Skip to content

Commit ea05ced

Browse files
fix: fire OnA11yChar during Print when screenReaderMode is enabled
Fixes #38 Co-authored-by: Ona <no-reply@ona.com>
1 parent f9a5d5a commit ea05ced

2 files changed

Lines changed: 50 additions & 3 deletions

File tree

inputhandler.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,10 @@ func (h *InputHandler) Print(data []uint32, start, end int) {
446446
precedingJoinState = currentInfo
447447
h.parser.SetPrecedingJoinState(precedingJoinState)
448448

449+
if h.optionsService.Options.ScreenReaderMode {
450+
h.OnA11yCharEmitter.Fire(string(rune(code)))
451+
}
452+
449453
if h.getCurrentLinkId() != 0 {
450454
h.oscLinkService.AddLineToLink(h.getCurrentLinkId(), buf.YBase+buf.Y)
451455
}

terminal_test.go

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,15 +1217,58 @@ func TestTerminalOnA11yTabDispose(t *testing.T) {
12171217

12181218
func TestTerminalOnA11yChar(t *testing.T) {
12191219
t.Parallel()
1220-
// OnA11yChar emitter exists and is subscribable, even if not yet fired
1221-
// by the current implementation. Verify the accessor returns a valid Disposable.
1222-
term := newTestTerminal(80, 24)
1220+
term := New(WithCols(80), WithRows(24), WithScrollback(1000), WithScreenReaderMode(true))
1221+
var chars []string
1222+
term.OnA11yChar(func(ch string) {
1223+
chars = append(chars, ch)
1224+
})
1225+
1226+
term.WriteString("ABC")
1227+
1228+
if len(chars) != 3 {
1229+
t.Fatalf("expected 3 OnA11yChar events, got %d", len(chars))
1230+
}
1231+
want := []string{"A", "B", "C"}
1232+
for i, w := range want {
1233+
if chars[i] != w {
1234+
t.Errorf("OnA11yChar[%d] = %q, want %q", i, chars[i], w)
1235+
}
1236+
}
1237+
}
1238+
1239+
func TestTerminalOnA11yCharDisabled(t *testing.T) {
1240+
t.Parallel()
1241+
// When ScreenReaderMode is off, OnA11yChar must not fire.
1242+
term := New(WithCols(80), WithRows(24), WithScrollback(1000))
1243+
count := 0
1244+
term.OnA11yChar(func(string) { count++ })
1245+
1246+
term.WriteString("ABC")
1247+
1248+
if count != 0 {
1249+
t.Errorf("OnA11yChar fired %d times with ScreenReaderMode disabled, want 0", count)
1250+
}
1251+
}
1252+
1253+
func TestTerminalOnA11yCharDispose(t *testing.T) {
1254+
t.Parallel()
1255+
term := New(WithCols(80), WithRows(24), WithScrollback(1000), WithScreenReaderMode(true))
12231256
count := 0
12241257
d := term.OnA11yChar(func(string) { count++ })
12251258
if d == nil {
12261259
t.Fatal("OnA11yChar returned nil Disposable")
12271260
}
1261+
1262+
term.WriteString("A")
1263+
if count != 1 {
1264+
t.Fatalf("expected 1 OnA11yChar event, got %d", count)
1265+
}
1266+
12281267
d.Dispose()
1268+
term.WriteString("B")
1269+
if count != 1 {
1270+
t.Errorf("OnA11yChar fired after Dispose: count = %d, want 1", count)
1271+
}
12291272
}
12301273

12311274
func TestTerminalOnRequestColorSchemeQuery(t *testing.T) {

0 commit comments

Comments
 (0)