better highlighting logic

This commit is contained in:
Jesse Duffield 2022-04-15 10:02:11 +10:00
parent 0c947ca079
commit a826601ada
3 changed files with 17 additions and 19 deletions

View File

@ -19,11 +19,6 @@ type escapeInterpreter struct {
instruction instruction
}
const (
NONE = 1 << iota
ERASE_IN_LINE
)
type (
escapeState int
fontEffect int

5
gui.go
View File

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

26
view.go
View File

@ -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++
}