v0.3.0 52147d7

screen_write.go RawHistoryFolder

1package vt
2
3import renderer "github.com/bnema/vev-vt/core"
4
5func (s *Screen) putRune(r rune) {
6	switch r {
7	case '\a':
8		if s.OnBell != nil {
9			s.OnBell()
10		}
11		return
12	case 0x00, 0x0e, 0x0f, 0x7f:
13		return
14	case '\r':
15		s.Col = 0
16	case '\n', '\v', '\f':
17		if s.Frame.Width > 0 && s.Col >= s.Frame.Width {
18			s.Col = s.Frame.Width - 1
19		}
20		s.buffer.hard(s.Row)
21		s.index()
22	case '\b':
23		if s.Col > 0 {
24			s.Col--
25		}
26	case '\t':
27		// HT moves to the next tab stop without modifying the frame. Clamp at
28		// the right edge rather than triggering deferred wrap or a scroll.
29		if s.Frame.Width > 0 {
30			s.Col = min(s.Col+8-s.Col%8, s.Frame.Width-1)
31		}
32	default:
33		// Drop C1 control characters (U+0080-U+009F).
34		if r >= 0x80 && r <= 0x9F {
35			return
36		}
37		if r >= 0x20 {
38			s.putPrintable(r)
39		}
40	}
41}
42
43// relinkWrap restores the soft link a deferred wrap just set when index()
44// scrolled the row out from under it. buffer.scrollUp severs the last moved
45// row on purpose — a linefeed there really does stop preceding anything — but
46// a wrap is the one case where that row flowed into the row below it, so the
47// link has to be put back after the rotation moved it to s.Row-1. movedUp is
48// false when nothing survived the scroll, and then there is no row to link.
49func (s *Screen) relinkWrap(movedUp bool) {
50	if movedUp {
51		s.buffer.continueRow(s.Row - 1)
52	}
53}
54
55func (s *Screen) putPrintable(r rune) {
56	w := renderer.RuneWidth(r)
57	// Skip combining marks and zero-width characters.
58	if w == 0 {
59		return
60	}
61	if s.Frame.Width == 0 || s.Frame.Height == 0 {
62		return
63	}
64	// Deferred wrap: cursor sits past the last column.
65	if s.Col >= s.Frame.Width {
66		s.buffer.soft(s.Row)
67		s.Col = 0
68		s.relinkWrap(s.index())
69	}
70	if s.Row >= s.Frame.Height {
71		s.Row = s.Frame.Height - 1
72	}
73
74	// A wide rune must never straddle the right edge. If it does not fit on the
75	// current line, clear the abandoned last cell and wrap to the next line.
76	if w == 2 && s.Col+1 >= s.Frame.Width {
77		if s.Frame.Width < 2 {
78			// The screen is too narrow to ever hold a wide rune; store a narrow
79			// replacement so the cell's renderer width matches its layout.
80			r = '\uFFFD'
81			w = renderer.RuneWidth(r)
82		} else {
83			// The abandoned cell may itself be the continuation of a pair whose
84			// left half sits one column back; report damage over the full span.
85			cx := s.Col
86			if s.Col > 0 && s.Frame.At(s.Col, s.Row).Continuation {
87				cx = s.Col - 1
88			}
89			s.clearWidePairAt(s.Col, s.Row)
90			s.Frame.Set(s.Col, s.Row, renderer.BlankCell())
91			s.buffer.truncate(s.Row, cx)
92			s.buffer.continueRow(s.Row)
93			s.record(renderer.Damage{Kind: renderer.DamageText, X: cx, Y: s.Row, Width: s.Col - cx + 1, Height: 1, Count: 1})
94			s.Col = 0
95			s.relinkWrap(s.index())
96			if s.Row >= s.Frame.Height {
97				s.Row = s.Frame.Height - 1
98			}
99		}
100	}
101
102	insertDamageX := s.Col
103	insertDamageWidth := 0
104	if s.insertMode {
105		row := s.Frame.Row(s.Row)
106		leftSplit := s.Col > 0 && row[s.Col].Continuation
107		for x := s.Frame.Width - 1; x >= s.Col+w; x-- {
108			row[x] = row[x-w]
109		}
110		for x := s.Col; x < s.Col+w; x++ {
111			row[x] = renderer.BlankCell()
112		}
113		s.repairRow(s.Row)
114		s.buffer.insert(s.Row, s.Col, w)
115		if leftSplit {
116			insertDamageX = s.Col - 1
117		}
118		insertDamageWidth = s.Frame.Width - insertDamageX
119	}
120
121	// Determine the range of cells actually modified, extending over any wide
122	// pair the write lands on so no orphaned half is left behind.
123	lo, hi := s.Col, s.Col+w-1
124	if s.Frame.At(s.Col, s.Row).Continuation {
125		lo = s.Col - 1
126	}
127	if right := s.Col + w; right < s.Frame.Width && s.Frame.At(right, s.Row).Continuation {
128		hi = right
129	}
130	for x := lo; x <= hi; x++ {
131		s.Frame.Set(x, s.Row, renderer.BlankCell())
132	}
133	s.Frame.Set(s.Col, s.Row, renderer.Cell{Rune: r, Style: s.Style})
134	s.buffer.content(s.Row, s.Col+w)
135	if w == 2 {
136		s.Frame.Set(s.Col+1, s.Row, renderer.Cell{Continuation: true, Style: s.Style})
137	}
138	if insertDamageWidth > 0 {
139		lo = min(lo, insertDamageX)
140		hi = max(hi, insertDamageX+insertDamageWidth-1)
141	}
142	s.record(renderer.Damage{Kind: renderer.DamageText, X: lo, Y: s.Row, Width: hi - lo + 1, Height: 1, Count: 1})
143	s.Col += w
144}
145
146// clearWidePairAt blanks both halves of a wide-character pair when the cell at
147// (x,y) is either the left (wide) half or the right (continuation) half. It is
148// O(1) and assumes the pair invariant (a continuation is preceded by its wide
149// left half) holds — which the writer maintains.
150
151func (s *Screen) clearWidePairAt(x, y int) {
152	if x < 0 || x >= s.Frame.Width || y < 0 || y >= s.Frame.Height {
153		return
154	}
155	if s.Frame.At(x, y).Continuation {
156		if x-1 >= 0 {
157			s.Frame.Set(x-1, y, renderer.BlankCell())
158		}
159		s.Frame.Set(x, y, renderer.BlankCell())
160		return
161	}
162	if x+1 < s.Frame.Width && s.Frame.At(x+1, y).Continuation {
163		s.Frame.Set(x, y, renderer.BlankCell())
164		s.Frame.Set(x+1, y, renderer.BlankCell())
165	}
166}
167
168func (s *Screen) eraseCell() renderer.Cell {
169	style := renderer.DefaultStyle()
170	if s.Style.HasBackgroundRGB {
171		style.HasBackgroundRGB = true
172		style.BackgroundRGB = s.Style.BackgroundRGB
173	} else {
174		style.Background = s.Style.Background
175	}
176	return renderer.Cell{Rune: ' ', Style: style}
177}
178
179// clearRow blanks cells [x0,x1) on row y, extending the range to swallow either
180// half of a wide pair that straddles a boundary so no orphan half is left. It
181// returns the actual modified span [start, start+width).
182
183func (s *Screen) clearRow(y, x0, x1 int) (start, width int) {
184	if y < 0 || y >= s.Frame.Height {
185		return x0, 0
186	}
187	if x0 < 0 {
188		x0 = 0
189	}
190	if x1 > s.Frame.Width {
191		x1 = s.Frame.Width
192	}
193	if x0 >= x1 {
194		return x0, 0
195	}
196	// Left boundary: a continuation at x0 means its wide left half sits at x0-1.
197	if x0 > 0 && s.Frame.At(x0, y).Continuation {
198		x0--
199	}
200	// Right boundary: a continuation at x1 means its wide left half (at x1-1) is
201	// inside the range and will be blanked, so swallow the continuation too.
202	if x1 < s.Frame.Width && s.Frame.At(x1, y).Continuation {
203		x1++
204	}
205	fullRow := x0 <= 0 && x1 >= s.Frame.Width
206	blank := s.eraseCell()
207	for x := x0; x < x1; x++ {
208		s.Frame.Set(x, y, blank)
209	}
210	s.buffer.clear(y, x0, x1)
211	if fullRow {
212		s.buffer.rowIDs[y] = s.nextRowIDValue()
213	}
214	return x0, x1 - x0
215}
216
217// repairRow blanks any orphaned wide-character halves on row y: a continuation
218// cell not preceded by its wide left half, or a wide rune not followed by its
219// continuation. Used after erase/insert/delete operations that may split a pair
220// at a boundary or by shifting cells.
221
222func (s *Screen) repairRow(y int) {
223	repairFrameRow(s.Frame, y)
224}
225
226func repairFrameRow(frame renderer.Frame, y int) {
227	if y < 0 || y >= frame.Height {
228		return
229	}
230	w := frame.Width
231	for x := range w {
232		c := frame.At(x, y)
233		if c.Continuation {
234			if x == 0 {
235				frame.Set(x, y, renderer.BlankCell())
236				continue
237			}
238			left := frame.At(x-1, y)
239			if left.Continuation || renderer.RuneWidth(left.Rune) != 2 {
240				frame.Set(x, y, renderer.BlankCell())
241			}
242			continue
243		}
244		if renderer.RuneWidth(c.Rune) == 2 {
245			if x+1 >= w || !frame.At(x+1, y).Continuation {
246				frame.Set(x, y, renderer.BlankCell())
247			}
248		}
249	}
250}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 2

Tags 13

↑↓ moveenter openesc close