From 0569ede1a50fe919fca4c60baaf385815fb10faa Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Tue, 13 Apr 2021 14:54:44 -0400 Subject: [PATCH] Comments and import fixes --- editor/document/document.go | 10 +++++----- editor/draw.go | 24 ++++++++++++------------ editor/editor.go | 14 +++++++------- editor/highlight/fn.go | 2 +- editor/input.go | 6 +++--- editor/search.go | 10 +++++----- internal/gilo/fn.go | 2 +- internal/gilo/point.go | 1 + key/key.go | 8 ++++---- 9 files changed, 39 insertions(+), 38 deletions(-) diff --git a/editor/document/document.go b/editor/document/document.go index 3cff7f0..94fd28d 100644 --- a/editor/document/document.go +++ b/editor/document/document.go @@ -4,7 +4,7 @@ import ( "bufio" "log" "os" - gilo2 "timshome.page/gilo/internal/gilo" + "timshome.page/gilo/internal/gilo" ) type Document struct { @@ -107,7 +107,7 @@ func (d *Document) InsertRow(at int, s string) { d.dirty = true } -func (d *Document) InsertNewline(at *gilo2.Point) { +func (d *Document) InsertNewline(at *gilo.Point) { if at.X == 0 { d.InsertRow(at.Y, "") } else { @@ -128,7 +128,7 @@ func (d *Document) MergeRows(to int, from int) { } func (d *Document) ToString() string { - buf := gilo2.NewBuffer() + buf := gilo.NewBuffer() for _, row := range d.rows { buf.Append(row.toString()) @@ -142,13 +142,13 @@ func (d *Document) RowCount() int { return len(d.rows) } -func (d *Document) InsertChar(at *gilo2.Point, ch rune) { +func (d *Document) InsertChar(at *gilo.Point, ch rune) { d.rows[at.Y].insertRune(ch, at.X) d.dirty = true } -func (d *Document) DelChar(at *gilo2.Point) { +func (d *Document) DelChar(at *gilo.Point) { d.rows[at.Y].deleteRune(at.X) d.dirty = true diff --git a/editor/draw.go b/editor/draw.go index 3f1758d..0749b1a 100644 --- a/editor/draw.go +++ b/editor/draw.go @@ -1,4 +1,4 @@ -// Editor methods involved in drawing to the console +// Package editor Editor methods involved in drawing to the console package editor import ( @@ -6,7 +6,7 @@ import ( "strings" "time" "timshome.page/gilo/editor/highlight" - gilo2 "timshome.page/gilo/internal/gilo" + "timshome.page/gilo/internal/gilo" "timshome.page/gilo/terminal" ) @@ -17,7 +17,7 @@ import ( func (e *editor) RefreshScreen() { e.scroll() - ab := gilo2.NewBuffer() + ab := gilo.NewBuffer() ab.Append(terminal.HideCursor) ab.Append(terminal.ResetCursor) @@ -57,7 +57,7 @@ func (e *editor) scroll() { } } -func (e *editor) drawRows(ab *gilo2.Buffer) { +func (e *editor) drawRows(ab *gilo.Buffer) { for y := 0; y < e.screen.Rows; y++ { fileRow := y + e.offset.Y @@ -81,7 +81,7 @@ func (e *editor) drawRows(ab *gilo2.Buffer) { } } -func (e *editor) drawFileRow(fileRow int, ab *gilo2.Buffer) { +func (e *editor) drawFileRow(fileRow int, ab *gilo.Buffer) { currentColor := terminal.DefaultFGColor row := e.doc.GetRow(fileRow) @@ -107,11 +107,11 @@ func (e *editor) drawFileRow(fileRow int, ab *gilo2.Buffer) { ab.Append(terminal.DefaultFGColor) } -func (e *editor) drawPlaceholderRow(y int, ab *gilo2.Buffer) { +func (e *editor) drawPlaceholderRow(y int, ab *gilo.Buffer) { if e.doc.RowCount() == 0 && y == e.screen.Rows/3 { - welcome := fmt.Sprintf("Gilo editor -- version %s", gilo2.Version) + welcome := fmt.Sprintf("Gilo editor -- version %s", gilo.Version) if len(welcome) > e.screen.Cols { - welcome = gilo2.Truncate(welcome, e.screen.Cols) + welcome = gilo.Truncate(welcome, e.screen.Cols) } padding := (e.screen.Cols - len(welcome)) / 2 @@ -131,7 +131,7 @@ func (e *editor) drawPlaceholderRow(y int, ab *gilo2.Buffer) { } } -func (e *editor) drawStatusBar(ab *gilo2.Buffer) { +func (e *editor) drawStatusBar(ab *gilo.Buffer) { cols := e.screen.Cols ab.Append(terminal.InvertColor) @@ -148,7 +148,7 @@ func (e *editor) drawStatusBar(ab *gilo2.Buffer) { leftStatus := fmt.Sprintf("%.20s - %d lines %s", fileName, e.doc.RowCount(), modified) length := len(leftStatus) if length > cols { - leftStatus = gilo2.Truncate(leftStatus, cols) + leftStatus = gilo.Truncate(leftStatus, cols) ab.Append(leftStatus) ab.Append(terminal.ResetColor) @@ -182,11 +182,11 @@ func (e *editor) drawStatusBar(ab *gilo2.Buffer) { ab.Append(terminal.ResetColor) } -func (e *editor) drawMessageBar(ab *gilo2.Buffer) { +func (e *editor) drawMessageBar(ab *gilo.Buffer) { ab.Append("\r\n") ab.Append(terminal.ClearLine) - msg := gilo2.Truncate(e.status.message, e.screen.Cols) + msg := gilo.Truncate(e.status.message, e.screen.Cols) if len(msg) > 0 && time.Since(e.status.created).Seconds() < 5.0 { ab.Append(msg) } diff --git a/editor/editor.go b/editor/editor.go index 51fb37f..8bf9952 100644 --- a/editor/editor.go +++ b/editor/editor.go @@ -5,7 +5,7 @@ import ( "fmt" "time" "timshome.page/gilo/editor/document" - gilo2 "timshome.page/gilo/internal/gilo" + "timshome.page/gilo/internal/gilo" "timshome.page/gilo/key" "timshome.page/gilo/terminal" ) @@ -21,8 +21,8 @@ type statusMsg struct { type editor struct { screen *terminal.Screen - cursor *gilo2.Point - offset *gilo2.Point + cursor *gilo.Point + offset *gilo.Point doc *document.Document status *statusMsg search *search @@ -42,12 +42,12 @@ func NewEditor() *editor { return &editor{ screen, - gilo2.DefaultPoint(), - gilo2.DefaultPoint(), + gilo.DefaultPoint(), + gilo.DefaultPoint(), document.NewDocument(), status, newSearch(), - gilo2.QuitTimes, + gilo.QuitTimes, 0, } } @@ -87,7 +87,7 @@ func (e *editor) save() { } func (e *editor) prompt(prompt string, callback func(string, string)) string { - buf := gilo2.NewBuffer() + buf := gilo.NewBuffer() // Show the prompt message e.SetStatusMessage(prompt, "") diff --git a/editor/highlight/fn.go b/editor/highlight/fn.go index 08eb7a7..0620c03 100644 --- a/editor/highlight/fn.go +++ b/editor/highlight/fn.go @@ -8,7 +8,7 @@ var syntaxColorMap = map[int]string{ Normal: terminal.DefaultFGColor, } -// Take a highlighting type and map it to +// SyntaxToColor Take a highlighting type and map it to // an ANSI color escape code for display func SyntaxToColor(hl int) string { color := syntaxColorMap[hl] diff --git a/editor/input.go b/editor/input.go index c869644..ce3b187 100644 --- a/editor/input.go +++ b/editor/input.go @@ -2,7 +2,7 @@ package editor import ( "timshome.page/gilo/editor/document" - gilo2 "timshome.page/gilo/internal/gilo" + "timshome.page/gilo/internal/gilo" "timshome.page/gilo/key" "timshome.page/gilo/terminal" ) @@ -74,8 +74,8 @@ func (e *editor) processKeypressChar(ch rune) bool { // Clear the quit message and restart the // confirmation count if confirmation is not // completed - if e.quitTimes != gilo2.QuitTimes { - e.quitTimes = gilo2.QuitTimes + if e.quitTimes != gilo.QuitTimes { + e.quitTimes = gilo.QuitTimes e.SetStatusMessage("") } diff --git a/editor/search.go b/editor/search.go index a1967d1..285a8ce 100644 --- a/editor/search.go +++ b/editor/search.go @@ -2,13 +2,13 @@ package editor import ( "timshome.page/gilo/editor/highlight" - gilo2 "timshome.page/gilo/internal/gilo" + "timshome.page/gilo/internal/gilo" "timshome.page/gilo/key" ) type search struct { - cursor *gilo2.Point - offset *gilo2.Point + cursor *gilo.Point + offset *gilo.Point hlLine int hl []int direction int @@ -17,8 +17,8 @@ type search struct { func newSearch() *search { return &search{ - cursor: gilo2.DefaultPoint(), - offset: gilo2.DefaultPoint(), + cursor: gilo.DefaultPoint(), + offset: gilo.DefaultPoint(), hlLine: -1, hl: []int{}, lastMatch: -1, diff --git a/internal/gilo/fn.go b/internal/gilo/fn.go index 20334c2..946f74f 100644 --- a/internal/gilo/fn.go +++ b/internal/gilo/fn.go @@ -1,4 +1,4 @@ -// Helper functions +// Package gilo Helper functions package gilo import "strings" diff --git a/internal/gilo/point.go b/internal/gilo/point.go index 1262dc7..3eafe38 100644 --- a/internal/gilo/point.go +++ b/internal/gilo/point.go @@ -1,3 +1,4 @@ +// Package gilo Point struct package gilo type Point struct { diff --git a/key/key.go b/key/key.go index e198ef6..2664fdd 100644 --- a/key/key.go +++ b/key/key.go @@ -12,12 +12,12 @@ const ( Enter = '\r' ) -// Is this an ASCII character? +// IsAscii Is this an ASCII character? func IsAscii(char rune) bool { return char <= unicode.MaxASCII } -// Is this an ASCII ctrl character? +// IsCtrl Is this an ASCII ctrl character? func IsCtrl(char rune) bool { if !IsAscii(char) { return false @@ -26,7 +26,7 @@ func IsCtrl(char rune) bool { return char == 0x7f || char < 0x20 } -// Return the input code of a Ctrl-key chord. +// Ctrl Return the input code of a Ctrl-key chord. func Ctrl(char rune) rune { if !IsAscii(char) { return 0 @@ -37,7 +37,7 @@ func Ctrl(char rune) rune { return ch } -// Is the character a general token separator type? +// IsSeparator Is the character a general token separator type? func IsSeparator(char rune) bool { return unicode.IsPunct(char) || unicode.IsSpace(char) } \ No newline at end of file