From 5ff459b6ad12bddd1009505c1f1c43cec27c621c Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Thu, 5 Oct 2023 15:29:37 -0400 Subject: [PATCH] Complete Chapter 7 Step 176 --- editor/draw.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/editor/draw.go b/editor/draw.go index 3b867be..c9e33d4 100644 --- a/editor/draw.go +++ b/editor/draw.go @@ -8,6 +8,7 @@ import ( "timshome.page/gilo/editor/highlight" "timshome.page/gilo/internal/gilo" "timshome.page/gilo/terminal" + "unicode" ) // ---------------------------------------------------------------------------- @@ -57,6 +58,7 @@ func (e *Editor) scroll() { } } +// drawRows is the equivalent to editorDrawRows in kilo func (e *Editor) drawRows(ab *gilo.Buffer) { for y := 0; y < e.screen.Rows; y++ { fileRow := y + e.offset.Y @@ -89,7 +91,19 @@ func (e *Editor) drawFileRow(fileRow int, ab *gilo.Buffer) { // this by runes so that multibyte-characters (like emoji) can // all be displayed for i, ch := range row.RenderRune(e.offset) { - if row.Hl[i] == highlight.Normal { + if unicode.IsControl(ch) { + sym := '?' + if ch <= 26 { + sym = '@' + ch + } + + ab.Append(terminal.InvertColor) + ab.AppendRune(sym) + ab.Append(terminal.ResetColor) + if currentColor != terminal.DefaultFGColor { + ab.Append(currentColor) + } + } else if row.Hl[i] == highlight.Normal { if currentColor != terminal.DefaultFGColor { ab.Append(terminal.DefaultFGColor) currentColor = terminal.DefaultFGColor @@ -189,6 +203,7 @@ func (e *Editor) drawStatusBar(ab *gilo.Buffer) { ab.Append(terminal.ResetColor) } +// drawMessageBar is the equivalent of editorDrawMessageBar in kilo func (e *Editor) drawMessageBar(ab *gilo.Buffer) { ab.Append("\r\n") ab.Append(terminal.ClearLine)