forked from charmbracelet/bubbletea
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxterm.go
45 lines (37 loc) · 1.18 KB
/
xterm.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package tea
import (
"github.com/charmbracelet/x/ansi"
)
func parseXTermModifyOtherKeys(csi *ansi.CsiSequence) Msg {
// XTerm modify other keys starts with ESC [ 27 ; <modifier> ; <code> ~
mod := KeyMod(csi.Param(1) - 1)
r := rune(csi.Param(2))
switch r {
case ansi.BS:
return KeyPressMsg{Mod: mod, Code: KeyBackspace}
case ansi.HT:
return KeyPressMsg{Mod: mod, Code: KeyTab}
case ansi.CR:
return KeyPressMsg{Mod: mod, Code: KeyEnter}
case ansi.ESC:
return KeyPressMsg{Mod: mod, Code: KeyEscape}
case ansi.DEL:
return KeyPressMsg{Mod: mod, Code: KeyBackspace}
}
// CSI 27 ; <modifier> ; <code> ~ keys defined in XTerm modifyOtherKeys
k := KeyPressMsg{Code: r, Mod: mod}
if k.Mod <= ModShift {
k.Text = string(r)
}
return k
}
// TerminalVersionMsg is a message that represents the terminal version.
type TerminalVersionMsg string
// terminalVersion is an internal message that queries the terminal for its
// version using XTVERSION.
type terminalVersion struct{}
// TerminalVersion is a command that queries the terminal for its version using
// XTVERSION. Note that some terminals may not support this command.
func TerminalVersion() Msg {
return terminalVersion{}
}