Complete Chapter 7 Step 176
All checks were successful
timw4mail/gilo/pipeline/head This commit looks good

This commit is contained in:
Timothy Warren 2023-10-05 15:29:37 -04:00
parent 74b59ed4fa
commit 5ff459b6ad

View File

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