1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-08-06 11:02:41 +03:00

fix some encodings

This commit is contained in:
Jesse Duffield
2021-09-25 12:37:37 +10:00
parent 652c97d239
commit ab0117c416
3 changed files with 33 additions and 18 deletions

View File

@@ -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("")