Skip to content

Commit 595ae55

Browse files
feat: add XTVERSION response (CSI > q)
Register a sendXtVersion CSI handler that responds with DCS > | xterm-go(0.1.0) ST when queried with CSI > q. Fixes #2 Co-authored-by: Ona <no-reply@ona.com>
1 parent c6d9c01 commit 595ae55

3 files changed

Lines changed: 47 additions & 0 deletions

File tree

inputhandler.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ func NewInputHandler(
215215
p.RegisterCsiHandler(FunctionIdentifier{Final: 'b'}, h.repeatPrecedingCharacter)
216216
p.RegisterCsiHandler(FunctionIdentifier{Final: 'c'}, h.sendDeviceAttributesPrimary)
217217
p.RegisterCsiHandler(FunctionIdentifier{Prefix: '>', Final: 'c'}, h.sendDeviceAttributesSecondary)
218+
p.RegisterCsiHandler(FunctionIdentifier{Prefix: '>', Final: 'q'}, h.sendXtVersion)
218219
p.RegisterCsiHandler(FunctionIdentifier{Final: 'g'}, h.tabClear)
219220
p.RegisterCsiHandler(FunctionIdentifier{Final: 'm'}, h.charAttributes)
220221
p.RegisterCsiHandler(FunctionIdentifier{Final: 'n'}, h.deviceStatus)

inputhandler_csi.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,15 @@ func (h *InputHandler) sendDeviceAttributesSecondary(params *Params) bool {
458458
return true
459459
}
460460

461+
// sendXtVersion responds to XTVERSION (CSI > q) with a DCS response.
462+
func (h *InputHandler) sendXtVersion(params *Params) bool {
463+
if params.Params[0] > 0 {
464+
return true
465+
}
466+
h.coreService.TriggerDataEvent("\x1bP>|xterm-go(0.1.0)\x1b\\", false, false)
467+
return true
468+
}
469+
461470
func (h *InputHandler) deviceStatus(params *Params) bool {
462471
buf := h.activeBuffer()
463472
switch params.Params[0] {

inputhandler_csi_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,43 @@ func TestDeviceAttributes(t *testing.T) {
588588
}
589589
}
590590

591+
func TestXtVersion(t *testing.T) {
592+
t.Parallel()
593+
type Expectation struct {
594+
Response string
595+
}
596+
597+
t.Run("default param responds with DCS version", func(t *testing.T) {
598+
t.Parallel()
599+
h := newTestInputHandler(80, 24)
600+
var response string
601+
h.coreService.OnDataEmitter.Event(func(data string) {
602+
response = data
603+
})
604+
h.ParseString("\x1b[>q")
605+
got := Expectation{Response: response}
606+
expected := Expectation{Response: "\x1bP>|xterm-go(0.1.0)\x1b\\"}
607+
if diff := cmp.Diff(expected, got); diff != "" {
608+
t.Errorf("mismatch (-want +got):\n%s", diff)
609+
}
610+
})
611+
612+
t.Run("non-zero param produces no response", func(t *testing.T) {
613+
t.Parallel()
614+
h := newTestInputHandler(80, 24)
615+
var response string
616+
h.coreService.OnDataEmitter.Event(func(data string) {
617+
response = data
618+
})
619+
h.ParseString("\x1b[>1q")
620+
got := Expectation{Response: response}
621+
expected := Expectation{Response: ""}
622+
if diff := cmp.Diff(expected, got); diff != "" {
623+
t.Errorf("mismatch (-want +got):\n%s", diff)
624+
}
625+
})
626+
}
627+
591628
func TestEraseChars(t *testing.T) {
592629
t.Parallel()
593630
type Expectation struct {

0 commit comments

Comments
 (0)