From a826601ada29c4190dfe1e4bcf2d0c8ceaf635f7 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Fri, 15 Apr 2022 10:02:11 +1000 Subject: [PATCH] better highlighting logic --- escape.go | 5 ----- gui.go | 5 ----- view.go | 26 +++++++++++++++++--------- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/escape.go b/escape.go index a9739f6..0085d0e 100644 --- a/escape.go +++ b/escape.go @@ -19,11 +19,6 @@ type escapeInterpreter struct { instruction instruction } -const ( - NONE = 1 << iota - ERASE_IN_LINE -) - type ( escapeState int fontEffect int diff --git a/gui.go b/gui.go index 880f9dc..ba8d93c 100644 --- a/gui.go +++ b/gui.go @@ -631,7 +631,6 @@ func (g *Gui) SetManagerFunc(manager func(*Gui) error) { // MainLoop runs the main loop until an error is returned. A successful // finish should return ErrQuit. func (g *Gui) MainLoop() error { - g.StartTime = time.Now() if g.PlayMode == REPLAYING { go g.replayRecording() @@ -916,9 +915,6 @@ func (g *Gui) drawTitle(v *View, fgColor, bgColor Attribute) error { if v != g.currentView { currentFgColor -= AttrBold } - if v.HighlightSelectedTabWithoutFocus || v == g.CurrentView() { - currentBgColor = v.SelBgColor - } } if err := g.SetRune(x, v.y0, ch, currentFgColor, currentBgColor); err != nil { return err @@ -982,7 +978,6 @@ func (g *Gui) drawListFooter(v *View, fgColor, bgColor Attribute) error { // flush updates the gui, re-drawing frames and buffers. func (g *Gui) flush() error { - // pretty sure we don't need this, but keeping it here in case we get weird visual artifacts // g.clear(g.FgColor, g.BgColor) diff --git a/view.go b/view.go index 372da55..cb735bd 100644 --- a/view.go +++ b/view.go @@ -25,11 +25,9 @@ const ( RIGHT = 8 // view is overlapping at right edge ) -var ( - // ErrInvalidPoint is returned when client passed invalid coordinates of a cell. - // Most likely client has passed negative coordinates of a cell. - ErrInvalidPoint = errors.New("invalid point") -) +// ErrInvalidPoint is returned when client passed invalid coordinates of a cell. +// Most likely client has passed negative coordinates of a cell. +var ErrInvalidPoint = errors.New("invalid point") // A View is a window. It maintains its own internal buffer and cursor // position. @@ -125,8 +123,7 @@ type View struct { Tabs []string TabIndex int - // HighlightTabWithoutFocus allows you to show which tab is selected without the view being focused - HighlightSelectedTabWithoutFocus bool + // TitleColor allow to configure the color of title and subtitle for the view. TitleColor Attribute @@ -838,7 +835,7 @@ func (v *View) updateSearchPositions() { v.searcher.searchPositions = []cellPos{} for y, line := range v.lines { lineLoop: - for x, _ := range line { + for x := range line { if normalizeRune(line[x].chr) == rune(normalizedSearchStr[0]) { for offset := 1; offset < len(normalizedSearchStr); offset++ { if len(line)-1 < x+offset { @@ -924,19 +921,29 @@ func (v *View) draw() error { } y := 0 + emptyCell := cell{chr: ' ', fgColor: ColorDefault, bgColor: ColorDefault} for _, vline := range v.viewLines[start:] { if y >= maxY { break } x := 0 - for j, c := range vline.line { + j := 0 + var c cell + for { if j < v.ox { + j++ continue } if x >= maxX { break } + if j > len(vline.line)-1 { + c = emptyCell + } else { + c = vline.line[j] + } + fgColor := c.fgColor if fgColor == ColorDefault { fgColor = v.FgColor @@ -960,6 +967,7 @@ func (v *View) draw() error { // Not sure why the previous code was here but it caused problems // when typing wide characters in an editor x += runewidth.RuneWidth(c.chr) + j++ } y++ }