diff --git a/internal/console/console.go b/internal/console/console.go index 6bc4d14..371bbb8 100644 --- a/internal/console/console.go +++ b/internal/console/console.go @@ -55,3 +55,11 @@ func Size() (int, int) { } return w, h } + +func EnableInvert() { + fmt.Print("\x1b[7m") +} + +func DisableInvert() { + fmt.Print("\x1b[0m") +} diff --git a/internal/editor/command.go b/internal/editor/command.go index 47d47b2..3dcfc46 100644 --- a/internal/editor/command.go +++ b/internal/editor/command.go @@ -39,7 +39,8 @@ func (ed *Editor) moveUp(n int) { func (ed *Editor) deleteRune(n int) { if len(ed.lines[ed.row]) < 1 { - return // XXX ring + ed.ring() + return } rs := []rune(ed.lines[ed.row]) if ed.col < 1 { diff --git a/internal/editor/editor.go b/internal/editor/editor.go index 9786bee..e821b7d 100644 --- a/internal/editor/editor.go +++ b/internal/editor/editor.go @@ -25,6 +25,7 @@ type Editor struct { insert *strings.Builder mode mode path string + bell bool } func (ed *Editor) load() { @@ -67,6 +68,7 @@ func Init(args []string) *Editor { insert: new(strings.Builder), mode: modeCommand, path: path, + bell: false, } ed.load() @@ -103,3 +105,7 @@ func (ed *Editor) insertRune(r rune) { ed.insert.WriteRune(r) ed.col++ } + +func (ed *Editor) ring() { + ed.bell = true +} diff --git a/internal/editor/main.go b/internal/editor/main.go index 0b5078c..f15792d 100644 --- a/internal/editor/main.go +++ b/internal/editor/main.go @@ -38,7 +38,8 @@ func (ed *Editor) insertNewline() { func (ed *Editor) deleteBefore() { if ed.insert.Len() < 1 { - return // TODO ring + ed.ring() + return } insert := ed.insert.String() _, size := utf8.DecodeLastRuneInString(insert) @@ -74,6 +75,8 @@ func (ed *Editor) Main() { ed.moveUp(1) case 'x': ed.deleteRune(1) + default: + ed.ring() } case console.KeyUp: ed.moveUp(1) @@ -84,7 +87,7 @@ func (ed *Editor) Main() { case console.KeyLeft: ed.moveLeft(1) default: - // TODO ring + ed.ring() } case modeInsert: switch k { @@ -114,7 +117,7 @@ func (ed *Editor) Main() { ed.exitInsert() ed.moveLeft(1) default: - // TODO ring + ed.ring() } } } diff --git a/internal/editor/view.go b/internal/editor/view.go index f6f7e52..668be03 100644 --- a/internal/editor/view.go +++ b/internal/editor/view.go @@ -51,7 +51,14 @@ func (ed *Editor) drawStatus() { _, h := console.Size() console.MoveCursor(0, h-1) + if ed.bell { + console.EnableInvert() + } console.Printf("%s %d,%d %s", m, ed.row, ed.col, ed.path) + if ed.bell { + console.DisableInvert() + } + ed.bell = false } func (ed *Editor) updateCursor() {