1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-05 00:59:19 +02: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

@ -5,7 +5,6 @@ import (
"io/ioutil" "io/ioutil"
"log" "log"
"os" "os"
"runtime"
"sync" "sync"
"os/exec" "os/exec"
@ -30,7 +29,6 @@ import (
"github.com/jesseduffield/lazygit/pkg/theme" "github.com/jesseduffield/lazygit/pkg/theme"
"github.com/jesseduffield/lazygit/pkg/updates" "github.com/jesseduffield/lazygit/pkg/updates"
"github.com/jesseduffield/lazygit/pkg/utils" "github.com/jesseduffield/lazygit/pkg/utils"
"github.com/mattn/go-runewidth"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
@ -51,10 +49,6 @@ const StartupPopupVersion = 5
// OverlappingEdges determines if panel edges overlap // OverlappingEdges determines if panel edges overlap
var OverlappingEdges = false var OverlappingEdges = false
func init() {
runewidth.DefaultCondition.EastAsianWidth = false
}
type ContextManager struct { type ContextManager struct {
ContextStack []Context ContextStack []Context
sync.RWMutex sync.RWMutex
@ -497,8 +491,6 @@ func (gui *Gui) Run() error {
g.NextSearchMatchKey = gui.getKey(userConfig.Keybinding.Universal.NextMatch) g.NextSearchMatchKey = gui.getKey(userConfig.Keybinding.Universal.NextMatch)
g.PrevSearchMatchKey = gui.getKey(userConfig.Keybinding.Universal.PrevMatch) g.PrevSearchMatchKey = gui.getKey(userConfig.Keybinding.Universal.PrevMatch)
g.ASCII = runtime.GOOS == "windows" && runewidth.IsEastAsian()
g.ShowListFooter = userConfig.Gui.ShowListFooter g.ShowListFooter = userConfig.Gui.ShowListFooter
if userConfig.Gui.MouseEvents { if userConfig.Gui.MouseEvents {

View File

@ -147,10 +147,6 @@ type Gui struct {
// match any known sequence, ESC means KeyEsc. // match any known sequence, ESC means KeyEsc.
InputEsc bool 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 // SupportOverlaps is true when we allow for view edges to overlap with other
// view edges // view edges
SupportOverlaps bool 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. // drawFrameEdges draws the horizontal and vertical edges of a view.
func (g *Gui) drawFrameEdges(v *View, fgColor, bgColor Attribute) error { func (g *Gui) drawFrameEdges(v *View, fgColor, bgColor Attribute) error {
runeH, runeV := '─', '│' runeH, runeV := '─', '│'
if g.ASCII { if len(v.FrameRunes) >= 2 {
runeH, runeV = '-', '|'
} else if len(v.FrameRunes) >= 2 {
runeH, runeV = v.FrameRunes[0], v.FrameRunes[1] 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) runeBL = corner(v, TOP|RIGHT)
runeBR = corner(v, TOP|LEFT) runeBR = corner(v, TOP|LEFT)
} }
if g.ASCII {
runeTL, runeTR, runeBL, runeBR = '+', '+', '+', '+'
}
corners := []struct { corners := []struct {
x, y int x, y int

View File

@ -8,6 +8,7 @@ import (
"time" "time"
"github.com/gdamore/tcell/v2" "github.com/gdamore/tcell/v2"
"github.com/mattn/go-runewidth"
) )
// We probably don't want this being a global variable for YOLO for now // We probably don't want this being a global variable for YOLO for now
@ -20,19 +21,50 @@ type oldStyle struct {
outputMode OutputMode 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. // tcellInit initializes tcell screen for use.
func (g *Gui) tcellInit() error { func (g *Gui) tcellInit() error {
runewidth.DefaultCondition.EastAsianWidth = false
tcell.SetEncodingFallback(tcell.EncodingFallbackASCII)
if s, e := tcell.NewScreen(); e != nil { if s, e := tcell.NewScreen(); e != nil {
return e return e
} else if e = s.Init(); e != nil { } else if e = s.Init(); e != nil {
return e return e
} else { } else {
registerRuneFallbacks(s)
g.screen = s g.screen = s
Screen = s Screen = s
return nil return nil
} }
} }
func registerRuneFallbacks(s tcell.Screen) {
for before, after := range runeReplacements {
s.RegisterRuneFallback(before, after)
}
}
// tcellInitSimulation initializes tcell screen for use. // tcellInitSimulation initializes tcell screen for use.
func (g *Gui) tcellInitSimulation() error { func (g *Gui) tcellInitSimulation() error {
s := tcell.NewSimulationScreen("") s := tcell.NewSimulationScreen("")