Skip to content

Commit 194d81e

Browse files
committed
feat(emulator): Implement DECARM - auto-repeat mode
1 parent 720eeab commit 194d81e

2 files changed

Lines changed: 30 additions & 3 deletions

File tree

vt/emulate.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ func NewEmulator(be Backend) Emulator {
157157
localModes: map[PrivateMode]ModeStatus{
158158
PmAppCursor: ModeOff,
159159
PmAutoMargin: ModeOn,
160+
PmAutoRepeat: ModeOn,
160161
PmVT52: ModeOnLocked, // we never support VT52 mode (note ON means ANSI mode)
161162
PmLeftRightMargin: ModeOff,
162163
PmShowCursor: ModeOn,
@@ -1929,6 +1930,7 @@ func (em *emulator) softReset() {
19291930
}
19301931
// and set any that should reset on (auto-margin)
19311932
em.setPrivateMode(PmAutoMargin, ModeOn)
1933+
em.setPrivateMode(PmAutoRepeat, ModeOn)
19321934
em.setPrivateMode(PmShowCursor, ModeOn)
19331935
em.setPrivateMode(PmBlinkCursor, ModeOn)
19341936
// set default cursor - matches VT defaults
@@ -2165,10 +2167,16 @@ var legacyPadKeys = map[Key]struct {
21652167
}
21662168

21672169
// repeatRaw is called to provide key repeat. We limit key repeating to just 40,
2168-
// and we ensure that at least one is included.
2170+
// and we ensure that at least one is included. We only repeat if key repeat is enabled.
21692171
func (em *emulator) repeatRaw(ev KeyEvent, data []byte) {
2170-
for range min(max(1, ev.Repeat), 40) {
2171-
em.SendRaw(data)
2172+
if pm := em.getPrivateMode(PmAutoRepeat); pm == ModeOn || pm == ModeOnLocked {
2173+
for range min(max(1, ev.Repeat), 40) {
2174+
em.SendRaw(data)
2175+
}
2176+
} else {
2177+
if ev.Repeat == 0 {
2178+
em.SendRaw(data)
2179+
}
21722180
}
21732181
}
21742182

vt/tests/key_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,25 @@ func TestKeyRepeat(t *testing.T) {
256256
CheckRead(t, term, "xxxx") // 0 ms, 50 ms, 75 ms, 100 ms
257257
}
258258

259+
// TestKeyRepeatDisabled tests simple key repeat
260+
func TestKeyRepeatDisabled(t *testing.T) {
261+
term := vt.NewMockTerm()
262+
defer MustClose(t, term)
263+
264+
MustStart(t, term)
265+
266+
// these are unreasonable repeat rates, but its somewhere to start
267+
term.SetRepeat(time.Millisecond*50, time.Millisecond*25)
268+
WriteF(t, term, "\x1b[?8l")
269+
270+
term.KeyPress(vt.KeyX)
271+
time.Sleep(100 * time.Millisecond)
272+
term.KeyPress(vt.KeyX)
273+
term.KeyRelease(vt.KeyX)
274+
275+
CheckRead(t, term, "x") // 0 ms, 50 ms, 75 ms, 100 ms
276+
}
277+
259278
// TestKeyRepeatCapsLock ensures that caps lock does not repeat
260279
func TestKeyRepeatCapsLock(t *testing.T) {
261280
term := vt.NewMockTerm()

0 commit comments

Comments
 (0)