diff --git a/editor/draw.go b/editor/draw.go index 2d1e926..2967bdc 100644 --- a/editor/draw.go +++ b/editor/draw.go @@ -4,7 +4,6 @@ package editor import ( "fmt" "strings" - "timshome.page/gilo/fn" "timshome.page/gilo/terminal" ) @@ -31,7 +30,7 @@ func (e *editor) drawRows(ab *buffer) { if y == e.screen.Rows / 3 { welcome := fmt.Sprintf("Gilo editor -- version %s", KiloVersion) if len(welcome) > e.screen.Cols { - welcome = fn.TruncateString(welcome, e.screen.Cols) + welcome = TruncateString(welcome, e.screen.Cols) } padding := (e.screen.Cols - len(welcome)) / 2 diff --git a/editor/editor.go b/editor/editor.go index a0f5d8c..42f0260 100644 --- a/editor/editor.go +++ b/editor/editor.go @@ -1,7 +1,6 @@ package editor import ( - "timshome.page/gilo/fn" "timshome.page/gilo/terminal" ) @@ -24,7 +23,6 @@ func New() *editor { screen := terminal.Size() cursor := &cursor { 0, 0 } var rows []*row - rows = append(rows, NewRow()) return &editor{screen, cursor, rows } } @@ -33,7 +31,7 @@ func (e *editor) ProcessKeypress() bool { var str string ch, _ := terminal.ReadKey() - if ch == fn.Ctrl('q') { + if ch == Ctrl('q') { // Clean up on exit terminal.Write(terminal.ClearScreen + terminal.ResetCursor) @@ -99,6 +97,7 @@ func parseEscapeSequence () string { runes = append(runes, ch) if i == 1 && runes[1] >= 'A' { + // \eOH \eOF if runes[0] == 'O' { switch runes[1] { case 'H': @@ -107,6 +106,7 @@ func parseEscapeSequence () string { return keyEnd } } + // \e[A if runes[0] == '[' { switch runes[1] { case 'A': @@ -125,6 +125,7 @@ func parseEscapeSequence () string { } } + // \e[1~ if i == 2 && runes[0] == '[' && runes[2] == '~' { switch runes[1] { case '1': diff --git a/fn/char.go b/editor/fn.go similarity index 57% rename from fn/char.go rename to editor/fn.go index 6bf25a5..59eb552 100644 --- a/fn/char.go +++ b/editor/fn.go @@ -1,4 +1,26 @@ -package fn +package editor + +import "strings" + +func TruncateString(s string, length int) string { + if length < 1 { + return "" + } + + var buf strings.Builder + count := 0 + + for _, char := range s { + if count == length { + break + } + + buf.WriteRune(char) + count++ + } + + return buf.String() +} func isAscii(char rune) bool { ord := int(char) @@ -26,4 +48,4 @@ func Ctrl(char rune) rune { } return rune(raw) -} +} \ No newline at end of file diff --git a/editor/keymap.go b/editor/keymap.go index 077223a..b7164df 100644 --- a/editor/keymap.go +++ b/editor/keymap.go @@ -14,7 +14,7 @@ const( ) // ---------------------------------------------------------------------------- -// !Map escape sequences to simpler constants +// !Constants representing input keys // ---------------------------------------------------------------------------- const ( diff --git a/fn/fn.go b/fn/fn.go deleted file mode 100644 index 43bef01..0000000 --- a/fn/fn.go +++ /dev/null @@ -1,23 +0,0 @@ -package fn - -import "strings" - -func TruncateString(s string, length int) string { - if length < 1 { - return "" - } - - var buf strings.Builder - count := 0 - - for _, char := range s { - if count == length { - break - } - - buf.WriteRune(char) - count++ - } - - return buf.String() -} \ No newline at end of file