This commit is contained in:
2026-03-26 12:46:28 +09:00
parent 691f8d4175
commit b056ab059f
5 changed files with 29 additions and 4 deletions

View File

@@ -55,3 +55,11 @@ func Size() (int, int) {
}
return w, h
}
func EnableInvert() {
fmt.Print("\x1b[7m")
}
func DisableInvert() {
fmt.Print("\x1b[0m")
}

View File

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

View File

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

View File

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

View File

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