terminal_focus.go RawHistoryFolder

1package daemon
2
3import (
4	"github.com/bnema/vev/internal/domain"
5	"github.com/bnema/vev/internal/protocol"
6)
7
8// Terminal focus.
9//
10// Each attachment carries the focus its client's terminal window last
11// reported. It is a lock-free read, so any daemon feature can ask whether a
12// user may be looking at an attachment. An attachment that never reports keeps
13// unknown focus, which counts as possibly seen, so terminals without focus
14// reporting behave exactly as before.
15//
16// Attention uses it today: only an attachment that may be seen acknowledges a
17// bell, so a vev window left open on another workspace no longer clears it for
18// every other client. When that window gains focus again, the tab it shows is
19// acknowledged by its next paint.
20//
21// Geometry uses it too: a reported focus gain makes the attachment the latest
22// shared PTY geometry claimant, so session content follows the focused window.
23
24// terminalFocus returns the focus the client last reported.
25func (ac *attachedClient) terminalFocus() domain.TerminalFocus {
26	if ac == nil {
27		return domain.TerminalFocusUnknown
28	}
29	return domain.TerminalFocus(ac.focus.Load())
30}
31
32// setTerminalFocus records a reported focus and reports whether it changed.
33func (ac *attachedClient) setTerminalFocus(focus domain.TerminalFocus) bool {
34	return domain.TerminalFocus(ac.focus.Swap(uint32(focus))) != focus
35}
36
37// applyTerminalFocusForAttachment records a focus report. Gaining focus
38// claims shared session geometry and repaints the attachment, whose paint
39// acknowledges the visible tab's bell, and the bars of every client, whose
40// bells may clear with it.
41func (d *Daemon) applyTerminalFocusForAttachment(effect *attachmentEffect, message protocol.TerminalFocus) {
42	if message.Validate() != nil || effect == nil || effect.sess == nil || effect.ac == nil || effect.ac.terminalFocus() == message.Focus {
43		return
44	}
45	if !message.Focus.MaySee() {
46		effect.ac.setTerminalFocus(message.Focus)
47		return
48	}
49	// Like a bell rung on a seen tab, the bell a focused window finds on its
50	// tab is drawn for one pulse before a paint acknowledges it. Mark it before
51	// the focus lets any paint acknowledge.
52	effect.sess.markVisibleAttention(effect.ac)
53	effect.ac.setTerminalFocus(message.Focus)
54	// The caller admitted this effect, and only Focused reaches here.
55	effect.sess.geometry.reconcileAndInvalidate(d, effect.sess, effect.ac, "terminal_focus.go")
56	d.invalidateRender(effect.sess, effect.ac, false, "terminal_focus.go")
57}
58
59// markVisibleAttention asks for one visible bell pulse on the tab ac shows,
60// when that tab is ringing.
61func (s *session) markVisibleAttention(ac *attachedClient) {
62	view := ac.viewSnapshot()
63	s.mu.Lock()
64	defer s.mu.Unlock()
65	for _, tb := range s.tabs {
66		if tb != nil && tb.attention && domain.TabStableID(tb.stableID) == view.tabID {
67			tb.attentionVisiblePaint = true
68			return
69		}
70	}
71}

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 12

Tags 11

↑↓ moveenter openesc close