diff --git a/editor/document/document.go b/editor/document/document.go index 0c59d64..3cff7f0 100644 --- a/editor/document/document.go +++ b/editor/document/document.go @@ -4,7 +4,7 @@ import ( "bufio" "log" "os" - "timshome.page/gilo/gilo" + gilo2 "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 *gilo.Point) { +func (d *Document) InsertNewline(at *gilo2.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 := gilo.NewBuffer() + buf := gilo2.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 *gilo.Point, ch rune) { +func (d *Document) InsertChar(at *gilo2.Point, ch rune) { d.rows[at.Y].insertRune(ch, at.X) d.dirty = true } -func (d *Document) DelChar(at *gilo.Point) { +func (d *Document) DelChar(at *gilo2.Point) { d.rows[at.Y].deleteRune(at.X) d.dirty = true diff --git a/editor/document/row.go b/editor/document/row.go index 54873ca..71a1c74 100644 --- a/editor/document/row.go +++ b/editor/document/row.go @@ -3,7 +3,7 @@ package document import ( "strings" "timshome.page/gilo/editor/highlight" - "timshome.page/gilo/gilo" + gilo2 "timshome.page/gilo/internal/gilo" "unicode" ) @@ -33,7 +33,7 @@ func (r *Row) RenderSize() int { return len(r.render) } -func (r *Row) Render(at *gilo.Point) string { +func (r *Row) Render(at *gilo2.Point) string { return string(r.render[at.X:]) } @@ -95,7 +95,7 @@ func (r *Row) deleteRune(at int) { func (r *Row) update() { r.render = r.render[:0] - replacement := strings.Repeat(" ", gilo.TabSize) + replacement := strings.Repeat(" ", gilo2.TabSize) str := strings.ReplaceAll(string(r.chars), "\t", replacement) for _, ch := range str { @@ -131,7 +131,7 @@ func (r *Row) CursorXToRenderX(cursorX int) (renderX int) { for i := 0; i < cursorX; i++ { if r.chars[i] == '\t' { - renderX += (gilo.TabSize - 1) - (renderX % gilo.TabSize) + renderX += (gilo2.TabSize - 1) - (renderX % gilo2.TabSize) } renderX += 1 @@ -146,7 +146,7 @@ func (r *Row) RenderXtoCursorX(renderX int) (cursorX int) { for cursorX = 0; cursorX < r.Size(); cursorX++ { if r.chars[cursorX] == '\t' { - currentRenderX += (gilo.TabSize - 1) - (currentRenderX % gilo.TabSize) + currentRenderX += (gilo2.TabSize - 1) - (currentRenderX % gilo2.TabSize) } else { currentRenderX += 1 } diff --git a/editor/draw.go b/editor/draw.go index c996322..3f1758d 100644 --- a/editor/draw.go +++ b/editor/draw.go @@ -6,7 +6,7 @@ import ( "strings" "time" "timshome.page/gilo/editor/highlight" - "timshome.page/gilo/gilo" + gilo2 "timshome.page/gilo/internal/gilo" "timshome.page/gilo/terminal" ) @@ -17,7 +17,7 @@ import ( func (e *editor) RefreshScreen() { e.scroll() - ab := gilo.NewBuffer() + ab := gilo2.NewBuffer() ab.Append(terminal.HideCursor) ab.Append(terminal.ResetCursor) @@ -57,7 +57,7 @@ func (e *editor) scroll() { } } -func (e *editor) drawRows(ab *gilo.Buffer) { +func (e *editor) drawRows(ab *gilo2.Buffer) { for y := 0; y < e.screen.Rows; y++ { fileRow := y + e.offset.Y @@ -81,7 +81,7 @@ func (e *editor) drawRows(ab *gilo.Buffer) { } } -func (e *editor) drawFileRow(fileRow int, ab *gilo.Buffer) { +func (e *editor) drawFileRow(fileRow int, ab *gilo2.Buffer) { currentColor := terminal.DefaultFGColor row := e.doc.GetRow(fileRow) @@ -107,11 +107,11 @@ func (e *editor) drawFileRow(fileRow int, ab *gilo.Buffer) { ab.Append(terminal.DefaultFGColor) } -func (e *editor) drawPlaceholderRow(y int, ab *gilo.Buffer) { +func (e *editor) drawPlaceholderRow(y int, ab *gilo2.Buffer) { if e.doc.RowCount() == 0 && y == e.screen.Rows/3 { - welcome := fmt.Sprintf("Gilo editor -- version %s", gilo.Version) + welcome := fmt.Sprintf("Gilo editor -- version %s", gilo2.Version) if len(welcome) > e.screen.Cols { - welcome = gilo.Truncate(welcome, e.screen.Cols) + welcome = gilo2.Truncate(welcome, e.screen.Cols) } padding := (e.screen.Cols - len(welcome)) / 2 @@ -131,7 +131,7 @@ func (e *editor) drawPlaceholderRow(y int, ab *gilo.Buffer) { } } -func (e *editor) drawStatusBar(ab *gilo.Buffer) { +func (e *editor) drawStatusBar(ab *gilo2.Buffer) { cols := e.screen.Cols ab.Append(terminal.InvertColor) @@ -148,7 +148,7 @@ func (e *editor) drawStatusBar(ab *gilo.Buffer) { leftStatus := fmt.Sprintf("%.20s - %d lines %s", fileName, e.doc.RowCount(), modified) length := len(leftStatus) if length > cols { - leftStatus = gilo.Truncate(leftStatus, cols) + leftStatus = gilo2.Truncate(leftStatus, cols) ab.Append(leftStatus) ab.Append(terminal.ResetColor) @@ -182,11 +182,11 @@ func (e *editor) drawStatusBar(ab *gilo.Buffer) { ab.Append(terminal.ResetColor) } -func (e *editor) drawMessageBar(ab *gilo.Buffer) { +func (e *editor) drawMessageBar(ab *gilo2.Buffer) { ab.Append("\r\n") ab.Append(terminal.ClearLine) - msg := gilo.Truncate(e.status.message, e.screen.Cols) + msg := gilo2.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 4dbe1e5..e2ddac8 100644 --- a/editor/editor.go +++ b/editor/editor.go @@ -5,7 +5,7 @@ import ( "fmt" "time" "timshome.page/gilo/editor/document" - "timshome.page/gilo/gilo" + gilo2 "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 *gilo.Point - offset *gilo.Point + cursor *gilo2.Point + offset *gilo2.Point doc *document.Document status *statusMsg search *search @@ -42,12 +42,12 @@ func NewEditor() *editor { return &editor{ screen, - gilo.DefaultPoint(), - gilo.DefaultPoint(), + gilo2.DefaultPoint(), + gilo2.DefaultPoint(), document.NewDocument(), status, newSearch(), - gilo.QuitTimes, + gilo2.QuitTimes, 0, } } @@ -87,7 +87,7 @@ func (e *editor) save() { } func (e *editor) prompt(prompt string, callback func(string, string)) string { - buf := gilo.NewBuffer() + buf := gilo2.NewBuffer() // Show the prompt message e.SetStatusMessage(prompt, "") diff --git a/editor/input.go b/editor/input.go index 5b67cd8..c869644 100644 --- a/editor/input.go +++ b/editor/input.go @@ -2,7 +2,7 @@ package editor import ( "timshome.page/gilo/editor/document" - "timshome.page/gilo/gilo" + gilo2 "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 != gilo.QuitTimes { - e.quitTimes = gilo.QuitTimes + if e.quitTimes != gilo2.QuitTimes { + e.quitTimes = gilo2.QuitTimes e.SetStatusMessage("") } diff --git a/editor/input_test.go b/editor/input_test.go index f717fdf..04211ee 100644 --- a/editor/input_test.go +++ b/editor/input_test.go @@ -2,23 +2,23 @@ package editor import ( "testing" - "timshome.page/gilo/gilo" + gilo2 "timshome.page/gilo/internal/gilo" "timshome.page/gilo/key" ) type moveCursor struct { keys []string withFile bool - cursor *gilo.Point + cursor *gilo2.Point } var cursorTests = []moveCursor{ - {[]string{string(key.Esc)}, false, gilo.DefaultPoint()}, - {[]string{keyRight}, true, gilo.NewPoint(1, 0)}, - {[]string{keyDown, keyEnd}, true, gilo.NewPoint(14, 1)}, - {[]string{keyEnd, keyHome}, true, gilo.DefaultPoint()}, - {[]string{keyRight, keyLeft}, true, gilo.DefaultPoint()}, - {[]string{keyDown, keyUp}, true, gilo.DefaultPoint()}, + {[]string{string(key.Esc)}, false, gilo2.DefaultPoint()}, + {[]string{keyRight}, true, gilo2.NewPoint(1, 0)}, + {[]string{keyDown, keyEnd}, true, gilo2.NewPoint(14, 1)}, + {[]string{keyEnd, keyHome}, true, gilo2.DefaultPoint()}, + {[]string{keyRight, keyLeft}, true, gilo2.DefaultPoint()}, + {[]string{keyDown, keyUp}, true, gilo2.DefaultPoint()}, // {[]string{keyPageUp}, true, gilo.DefaultPoint()}, } diff --git a/editor/search.go b/editor/search.go index b4f8b45..a1967d1 100644 --- a/editor/search.go +++ b/editor/search.go @@ -2,13 +2,13 @@ package editor import ( "timshome.page/gilo/editor/highlight" - "timshome.page/gilo/gilo" + gilo2 "timshome.page/gilo/internal/gilo" "timshome.page/gilo/key" ) type search struct { - cursor *gilo.Point - offset *gilo.Point + cursor *gilo2.Point + offset *gilo2.Point hlLine int hl []int direction int @@ -17,8 +17,8 @@ type search struct { func newSearch() *search { return &search{ - cursor: gilo.DefaultPoint(), - offset: gilo.DefaultPoint(), + cursor: gilo2.DefaultPoint(), + offset: gilo2.DefaultPoint(), hlLine: -1, hl: []int{}, lastMatch: -1, diff --git a/gilo.go b/gilo.go index adc1ad8..1282465 100644 --- a/gilo.go +++ b/gilo.go @@ -2,6 +2,7 @@ package main import ( "golang.org/x/term" + "fmt" "os" "timshome.page/gilo/editor" "timshome.page/gilo/terminal" diff --git a/gilo/buffer.go b/internal/gilo/buffer.go similarity index 100% rename from gilo/buffer.go rename to internal/gilo/buffer.go diff --git a/gilo/buffer_test.go b/internal/gilo/buffer_test.go similarity index 100% rename from gilo/buffer_test.go rename to internal/gilo/buffer_test.go diff --git a/gilo/constants.go b/internal/gilo/constants.go similarity index 100% rename from gilo/constants.go rename to internal/gilo/constants.go diff --git a/gilo/fn.go b/internal/gilo/fn.go similarity index 100% rename from gilo/fn.go rename to internal/gilo/fn.go diff --git a/gilo/fn_test.go b/internal/gilo/fn_test.go similarity index 100% rename from gilo/fn_test.go rename to internal/gilo/fn_test.go diff --git a/gilo/point.go b/internal/gilo/point.go similarity index 100% rename from gilo/point.go rename to internal/gilo/point.go diff --git a/gilo/point_test.go b/internal/gilo/point_test.go similarity index 100% rename from gilo/point_test.go rename to internal/gilo/point_test.go