From c3b2900f4266061711049a4f71b8bcf437055e18 Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Wed, 7 Apr 2021 12:02:08 -0400 Subject: [PATCH] Highlight numbers --- internal/editor/document/row.go | 3 +-- internal/editor/draw.go | 18 +++++++++++++++--- internal/editor/editor.go | 5 ++--- internal/terminal/ansi.go | 2 ++ 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/internal/editor/document/row.go b/internal/editor/document/row.go index eaeee3f..3ffe87a 100644 --- a/internal/editor/document/row.go +++ b/internal/editor/document/row.go @@ -106,9 +106,8 @@ func (r *Row) toString() string { func (r *Row) CursorXToRenderX(cursorX int) (renderX int) { renderX = 0 - i := 0 - for ; i < cursorX; i++ { + for i := 0; i < cursorX; i++ { if r.chars[i] == '\t' { renderX += (gilo.TabSize - 1) - (renderX % gilo.TabSize) } diff --git a/internal/editor/draw.go b/internal/editor/draw.go index cbf7cd1..5531f5e 100644 --- a/internal/editor/draw.go +++ b/internal/editor/draw.go @@ -7,6 +7,7 @@ import ( "time" "timshome.page/gilo/internal/gilo" "timshome.page/gilo/internal/terminal" + "unicode" ) // ---------------------------------------------------------------------------- @@ -73,9 +74,20 @@ func (e *editor) drawRows(ab *gilo.Buffer) { continue } - rowLen := e.document.GetRow(fileRow).RenderSize() - e.offset.X - outputRow := gilo.Truncate(e.document.GetRow(fileRow).Render(e.offset), rowLen) - ab.Append(outputRow) + // rowLen := e.document.GetRow(fileRow).RenderSize() - e.offset.X + + for _, ch := range e.document.GetRow(fileRow).Render(e.offset) { + if unicode.IsDigit(ch) { + ab.Append(terminal.FGRed) + ab.AppendRune(ch) + ab.Append(terminal.DefaultFGColor) + } else { + ab.AppendRune(ch) + } + } + + // outputRow := gilo.Truncate(e.document.GetRow(fileRow).Render(e.offset), rowLen) + // ab.Append(outputRow) } ab.AppendLn(terminal.ClearLine) diff --git a/internal/editor/editor.go b/internal/editor/editor.go index 876da02..55b0e18 100644 --- a/internal/editor/editor.go +++ b/internal/editor/editor.go @@ -144,7 +144,6 @@ func (e *editor) find() { lastMatch := -1 direction := 1 - query := e.prompt("Search: %s (Use ESC/Arrows/Enter)", func(query string, ch string) { if ch == string(key.Enter) || ch == string(key.Esc) { lastMatch = -1 @@ -168,8 +167,8 @@ func (e *editor) find() { for i := 0; i < e.document.RowCount(); i++ { current += direction if current == -1 { - current = e.document.RowCount() - 1 - } else if current > e.document.RowCount() { + current = e.document.RowCount() + } else if current == e.document.RowCount() { current = 0 } diff --git a/internal/terminal/ansi.go b/internal/terminal/ansi.go index eb5cd59..1647149 100644 --- a/internal/terminal/ansi.go +++ b/internal/terminal/ansi.go @@ -31,6 +31,8 @@ const ( // Color sequences const ( + DefaultFGColor = EscPrefix + "39m" + FGRed = EscPrefix + "31m" InvertColor = EscPrefix + "7m" ResetColor = EscPrefix + "m" )