v0.1.0 d9218d6

state.go RawHistoryFolder

1package core
2
3import (
4	"cmp"
5	"reflect"
6	"slices"
7
8	"github.com/bnema/neferwl/internal/ports"
9)
10
11// publishState sends the script-facing snapshot when it changed.
12func (c *Core) publishState() {
13	if c.ch.State == nil {
14		return
15	}
16	st := c.state()
17	if reflect.DeepEqual(st, c.sentState) {
18		return
19	}
20	c.sentState = st
21	latest(c.ch.State, st)
22}
23
24// state builds the snapshot. The placeholder screen is not an output.
25func (c *Core) state() ports.State {
26	st := ports.State{Output: c.cur().name(), Outputs: []ports.OutputState{}, Windows: []ports.WindowState{}}
27	focus, _ := c.cur().mon.Focused()
28	for _, s := range c.screens {
29		if s.name() == "" {
30			continue
31		}
32		m := s.mon
33		cur := m.Current()
34		o := ports.OutputState{Name: s.name(), Count: numbered(m), Workspace: cur.Name}
35		if i := indexOf(m.Workspaces, cur); i >= 0 {
36			o.Active = i + 1
37		}
38		st.Outputs = append(st.Outputs, o)
39		for _, w := range m.all() {
40			n := indexOf(m.Workspaces, w) + 1
41			for _, id := range w.windows() {
42				info := c.clients[id]
43				st.Windows = append(st.Windows, ports.WindowState{ID: id, AppID: info.AppID, PID: info.PID, Output: s.name(), Workspace: n, Visible: w == cur, IdleInhibit: c.idle[id]})
44			}
45		}
46	}
47	slices.SortFunc(st.Windows, func(a, b ports.WindowState) int { return cmp.Compare(a.ID, b.ID) })
48	for i := range st.Windows {
49		if st.Windows[i].ID == focus && focus != 0 {
50			w := st.Windows[i]
51			st.Window = &w
52		}
53	}
54	return st
55}
56
57// numbered counts numbered workspaces, without the trailing spare one
58// unless it is on screen.
59func numbered(m *Monitor) int {
60	n := len(m.Workspaces)
61	if last := m.Workspaces[n-1]; n > 1 && last.empty() && last.Name == "" && m.Current() != last {
62		n--
63	}
64	return n
65}

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 26

Tags 10

↑↓ moveenter openesc close