diff --git a/gui.go b/gui.go index eccae45..7bd7643 100644 --- a/gui.go +++ b/gui.go @@ -147,10 +147,6 @@ type Gui struct { // match any known sequence, ESC means KeyEsc. InputEsc bool - // If ASCII is true then use ASCII instead of unicode to draw the - // interface. Using ASCII is more portable. - ASCII bool - // SupportOverlaps is true when we allow for view edges to overlap with other // view edges SupportOverlaps bool @@ -754,9 +750,7 @@ func (g *Gui) clear(fg, bg Attribute) (int, int) { // drawFrameEdges draws the horizontal and vertical edges of a view. func (g *Gui) drawFrameEdges(v *View, fgColor, bgColor Attribute) error { runeH, runeV := '─', '│' - if g.ASCII { - runeH, runeV = '-', '|' - } else if len(v.FrameRunes) >= 2 { + if len(v.FrameRunes) >= 2 { runeH, runeV = v.FrameRunes[0], v.FrameRunes[1] } @@ -882,9 +876,6 @@ func (g *Gui) drawFrameCorners(v *View, fgColor, bgColor Attribute) error { runeBL = corner(v, TOP|RIGHT) runeBR = corner(v, TOP|LEFT) } - if g.ASCII { - runeTL, runeTR, runeBL, runeBR = '+', '+', '+', '+' - } corners := []struct { x, y int diff --git a/tcell_driver.go b/tcell_driver.go index 8d5045b..2783103 100644 --- a/tcell_driver.go +++ b/tcell_driver.go @@ -8,6 +8,7 @@ import ( "time" "github.com/gdamore/tcell/v2" + "github.com/mattn/go-runewidth" ) // We probably don't want this being a global variable for YOLO for now @@ -20,19 +21,50 @@ type oldStyle struct { outputMode OutputMode } +var runeReplacements = map[rune]string{ + '┌': "+", + '┐': "+", + '└': "+", + '┘': "+", + '─': "-", + + // using a hyphen here actually looks weird. + // We see these characters when in portrait mode + '╶': " ", + '╴': " ", + + '├': "+", + '│': "|", + '▼': "v", + '►': ">", + '▲': "^", + '◄': "<", +} + // tcellInit initializes tcell screen for use. func (g *Gui) tcellInit() error { + runewidth.DefaultCondition.EastAsianWidth = false + tcell.SetEncodingFallback(tcell.EncodingFallbackASCII) + if s, e := tcell.NewScreen(); e != nil { return e } else if e = s.Init(); e != nil { return e } else { + registerRuneFallbacks(s) + g.screen = s Screen = s return nil } } +func registerRuneFallbacks(s tcell.Screen) { + for before, after := range runeReplacements { + s.RegisterRuneFallback(before, after) + } +} + // tcellInitSimulation initializes tcell screen for use. func (g *Gui) tcellInitSimulation() error { s := tcell.NewSimulationScreen("")