web_control.go RawHistoryFolder

1package app
2
3import (
4	"context"
5	"encoding/base64"
6	"encoding/json"
7	"errors"
8	"io"
9	"net"
10	"time"
11
12	"github.com/bnema/vev/internal/adapters/webterm"
13)
14
15type webAccess struct {
16	Token    string           `json:"token"`
17	Settings webterm.Settings `json:"settings"`
18}
19
20func startWebControl(ctx context.Context, server *webterm.Server, settings webterm.Settings) (*net.UnixListener, error) {
21	listener, err := bindWebControl()
22	if err != nil {
23		return nil, err
24	}
25	go func() {
26		stop := context.AfterFunc(ctx, func() { _ = listener.Close() })
27		defer stop()
28		for {
29			conn, err := listener.AcceptUnix()
30			if err != nil {
31				return
32			}
33			// Serialize tiny bounded control requests. No unbounded per-peer workers.
34			func() {
35				defer conn.Close()
36				if !sameWebUID(conn) {
37					return
38				}
39				_ = conn.SetDeadline(time.Now().Add(time.Second))
40				var command [1]byte
41				if _, err := io.ReadFull(conn, command[:]); err != nil {
42					return
43				}
44				var token string
45				switch command[0] {
46				case 'G':
47					token = server.Token()
48				case 'R':
49					token, err = server.RenewToken()
50					if err != nil {
51						return
52					}
53				default:
54					return
55				}
56				_ = json.NewEncoder(conn).Encode(webAccess{Token: token, Settings: settings})
57			}()
58		}
59	}()
60	return listener, nil
61}
62
63func webControlRequest(ctx context.Context, renew bool) (webAccess, error) {
64	ctx, cancel := context.WithTimeout(ctx, time.Second)
65	defer cancel()
66	conn, err := (&net.Dialer{}).DialContext(ctx, "unix", webControlAddress())
67	if err != nil {
68		return webAccess{}, err
69	}
70	defer conn.Close()
71	unixConn, ok := conn.(*net.UnixConn)
72	if !ok {
73		return webAccess{}, errors.New("vev: unsafe web control peer")
74	}
75	if !sameWebUID(unixConn) {
76		return webAccess{}, errors.New("vev: unsafe web control peer")
77	}
78	deadline, _ := ctx.Deadline()
79	_ = conn.SetDeadline(deadline)
80	command := byte('G')
81	if renew {
82		command = 'R'
83	}
84	if _, err := conn.Write([]byte{command}); err != nil {
85		return webAccess{}, err
86	}
87	data, err := io.ReadAll(io.LimitReader(conn, 4097))
88	if err != nil {
89		return webAccess{}, err
90	}
91	var access webAccess
92	if len(data) > 4096 || json.Unmarshal(data, &access) != nil {
93		return webAccess{}, errors.New("vev: invalid web control response")
94	}
95	decoded, err := base64.RawURLEncoding.DecodeString(access.Token)
96	settings, settingsErr := webterm.ParseSettings(access.Settings.Listen, access.Settings.Origin)
97	if err != nil || len(decoded) != 32 || settingsErr != nil || settings != access.Settings {
98		return webAccess{}, errors.New("vev: invalid web control response")
99	}
100	return access, nil
101}

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