-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinputhandler_esc.go
More file actions
175 lines (155 loc) · 5.54 KB
/
inputhandler_esc.go
File metadata and controls
175 lines (155 loc) · 5.54 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
package xterm
// Ported from xterm.js src/common/InputHandler.ts — ESC sequence handlers.
// ESC handler wrappers (return bool for the parser chain).
func (h *InputHandler) escSaveCursor() bool { return h.SaveCursor() }
func (h *InputHandler) escRestoreCursor() bool { return h.RestoreCursor() }
func (h *InputHandler) escIndex() bool { return h.Index() }
func (h *InputHandler) escNextLine() bool { return h.NextLine() }
func (h *InputHandler) escTabSet() bool { return h.TabSet() }
func (h *InputHandler) escReverseIndex() bool { return h.ReverseIndex() }
func (h *InputHandler) escFullReset() bool { return h.FullReset() }
func (h *InputHandler) escKeypadApplicationMode() bool { return h.KeypadApplicationMode() }
func (h *InputHandler) escKeypadNumericMode() bool { return h.KeypadNumericMode() }
func (h *InputHandler) escSelectDefaultCharset() bool { return h.SelectDefaultCharset() }
func (h *InputHandler) escScreenAlignmentPattern() bool { return h.ScreenAlignmentPattern() }
// SaveCursor (ESC 7 / DECSC) — save cursor position, attributes, charset state.
func (h *InputHandler) SaveCursor() bool {
buf := h.activeBuffer()
buf.SavedState.X = buf.X
buf.SavedState.Y = buf.YBase + buf.Y
buf.SavedState.CurAttrData = h.curAttrData.Clone()
buf.SavedState.Charset = h.charsetService.Charset
charsets := h.charsetService.Charsets()
buf.SavedState.Charsets = make([]Charset, len(charsets))
copy(buf.SavedState.Charsets, charsets)
buf.SavedState.GLevel = h.charsetService.GLevel
buf.SavedState.OriginMode = h.coreService.DecPrivateModes.Origin
buf.SavedState.WraparoundMode = h.coreService.DecPrivateModes.Wraparound
return true
}
// RestoreCursor (ESC 8 / DECRC) — restore saved cursor state.
func (h *InputHandler) RestoreCursor() bool {
buf := h.activeBuffer()
buf.X = buf.SavedState.X
buf.Y = max(buf.SavedState.Y-buf.YBase, 0)
h.curAttrData.Fg = buf.SavedState.CurAttrData.Fg
h.curAttrData.Bg = buf.SavedState.CurAttrData.Bg
for i, cs := range buf.SavedState.Charsets {
h.charsetService.SetgCharset(i, cs)
}
h.charsetService.SetgLevel(buf.SavedState.GLevel)
h.coreService.DecPrivateModes.Origin = buf.SavedState.OriginMode
h.coreService.DecPrivateModes.Wraparound = buf.SavedState.WraparoundMode
h.restrictCursor()
return true
}
// Index (ESC D / IND) — move cursor down one line, scroll if at bottom of scroll region.
func (h *InputHandler) Index() bool {
buf := h.activeBuffer()
h.restrictCursor()
buf.Y++
if buf.Y == buf.ScrollBottom+1 {
buf.Y--
h.bufferService.Scroll(h.eraseAttrData(), false)
} else if buf.Y >= h.bufferService.Rows {
buf.Y = h.bufferService.Rows - 1
}
h.restrictCursor()
return true
}
// ReverseIndex (ESC M / RI) — move cursor up one line, scroll down if at top of scroll region.
func (h *InputHandler) ReverseIndex() bool {
buf := h.activeBuffer()
h.restrictCursor()
if buf.Y == buf.ScrollTop {
scrollRegionHeight := buf.ScrollBottom - buf.ScrollTop
buf.Lines.ShiftElements(buf.YBase+buf.Y, scrollRegionHeight, 1)
buf.Lines.Set(buf.YBase+buf.Y, buf.GetBlankLine(h.eraseAttrData(), false))
h.dirtyRowTracker.MarkRangeDirty(buf.ScrollTop, buf.ScrollBottom)
} else {
buf.Y--
h.restrictCursor()
}
return true
}
// NextLine (ESC E / NEL) — CR + LF.
func (h *InputHandler) NextLine() bool {
h.activeBuffer().X = 0
h.Index()
return true
}
// TabSet (ESC H / HTS) — set a tab stop at the current cursor column.
func (h *InputHandler) TabSet() bool {
buf := h.activeBuffer()
buf.Tabs[buf.X] = true
return true
}
// KeypadApplicationMode (ESC =) — enable application keypad mode.
func (h *InputHandler) KeypadApplicationMode() bool {
h.coreService.DecPrivateModes.ApplicationKeypad = true
h.OnRequestSyncScrollBarEmitter.Fire(struct{}{})
return true
}
// KeypadNumericMode (ESC >) — enable numeric keypad mode.
func (h *InputHandler) KeypadNumericMode() bool {
h.coreService.DecPrivateModes.ApplicationKeypad = false
h.OnRequestSyncScrollBarEmitter.Fire(struct{}{})
return true
}
// FullReset (ESC c / RIS) — complete terminal reset.
func (h *InputHandler) FullReset() bool {
h.parser.Reset()
h.OnRequestResetEmitter.Fire(struct{}{})
return true
}
// SetgLevel sets the active GL level (ESC n/o/|/}/~).
func (h *InputHandler) SetgLevel(level int) bool {
h.charsetService.SetgLevel(level)
return true
}
// SelectCharset designates a charset to a G-set (ESC ( ) * + - . / <flag>).
func (h *InputHandler) SelectCharset(collectAndFlag string) bool {
if len(collectAndFlag) != 2 {
h.SelectDefaultCharset()
return true
}
if collectAndFlag[0] == '/' {
return true // unsupported
}
g, ok := glevelMap[collectAndFlag[0]]
if !ok {
return true
}
cs, exists := CHARSETS[collectAndFlag[1]]
if !exists {
cs = nil // default US ASCII
}
h.charsetService.SetgCharset(g, cs)
return true
}
// SelectDefaultCharset (ESC % @ / ESC % G) — select default (US ASCII) charset.
func (h *InputHandler) SelectDefaultCharset() bool {
h.charsetService.SetgLevel(0)
h.charsetService.SetgCharset(0, nil) // nil = US ASCII default
return true
}
// ScreenAlignmentPattern (ESC # 8 / DECALN) — fill screen with 'E'.
func (h *InputHandler) ScreenAlignmentPattern() bool {
cell := &CellData{}
cell.Content = 1<<ContentWidthShift | uint32('E')
cell.Fg = h.curAttrData.Fg
cell.Bg = h.curAttrData.Bg
buf := h.activeBuffer()
h.setCursor(0, 0)
for yOffset := range h.bufferService.Rows {
row := buf.YBase + buf.Y + yOffset
line := buf.Lines.Get(row)
if line != nil {
line.Fill(cell, false)
line.IsWrapped = false
}
}
h.dirtyRowTracker.MarkAllDirty()
h.setCursor(0, 0)
return true
}