preview.go RawHistoryFolder

1package protoconv
2
3// RemotePreviewRequest/RemotePreview converters (shared by sessionwire and
4// brokerwire).
5//
6// On failure these return either ErrOutOfRange (from a narrowing numeric or
7// identity conversion) or one of protocol's own RemotePreview* validation
8// sentinels, unwrapped. The two callers diverge on how they collapse these
9// into their own local sentinel errors, so this package never wraps or
10// renames them: sessionwire always folds every failure into a single fixed
11// request/preview sentinel, while brokerwire keeps range failures distinct
12// from semantic validation failures (and maps ErrRemotePreviewTooLarge to
13// its own bounded-size sentinel). See the callers' wrapper functions for the
14// exact mapping.
15
16import (
17	"github.com/bnema/vev/internal/domain"
18	"github.com/bnema/vev/internal/protocol"
19	"github.com/bnema/vev/internal/protocol/wire"
20)
21
22// RemotePreviewRequestToWire validates before encoding: an invalid request
23// is refused with protocol's own sentinel rather than emitted.
24func RemotePreviewRequestToWire(message protocol.RemotePreviewRequest) (*wire.RemotePreviewRequest, error) {
25	if err := protocol.ValidateRemotePreviewRequest(message); err != nil {
26		return nil, err
27	}
28	return &wire.RemotePreviewRequest{
29		Version: uint32(message.Version),
30		Target:  RemoteTargetToWire(message.Target),
31		Width:   uint32(message.Width),
32		Height:  uint32(message.Height),
33	}, nil
34}
35
36// RemotePreviewRequestFromWire requires a non-nil message and re-validates
37// the fully decoded request, so decode refuses exactly what encode refuses.
38func RemotePreviewRequestFromWire(message *wire.RemotePreviewRequest) (protocol.RemotePreviewRequest, error) {
39	var request protocol.RemotePreviewRequest
40	if message == nil {
41		return request, ErrOutOfRange
42	}
43	version, err := Uint16[uint16](message.GetVersion())
44	if err != nil {
45		return protocol.RemotePreviewRequest{}, err
46	}
47	request.Version = version
48	target, err := RemoteTargetFromWire(message.GetTarget())
49	if err != nil {
50		return protocol.RemotePreviewRequest{}, err
51	}
52	request.Target = target
53	width, err := Uint16[uint16](message.GetWidth())
54	if err != nil {
55		return protocol.RemotePreviewRequest{}, err
56	}
57	request.Width = width
58	height, err := Uint16[uint16](message.GetHeight())
59	if err != nil {
60		return protocol.RemotePreviewRequest{}, err
61	}
62	request.Height = height
63	if err := protocol.ValidateRemotePreviewRequest(request); err != nil {
64		return protocol.RemotePreviewRequest{}, err
65	}
66	return request, nil
67}
68
69// RemotePreviewToWire validates before encoding. A failure can be either
70// protocol.ErrInvalidRemotePreview or protocol.ErrRemotePreviewTooLarge;
71// callers distinguish the two.
72func RemotePreviewToWire(message protocol.RemotePreview) (*wire.RemotePreview, error) {
73	if err := protocol.ValidateRemotePreview(message); err != nil {
74		return nil, err
75	}
76	cells, err := PreviewCellsToWire(message.Cells)
77	if err != nil {
78		return nil, err
79	}
80	return &wire.RemotePreview{
81		Version:     uint32(message.Version),
82		Status:      uint32(message.Status),
83		LifecycleId: LifecycleToWire(message.LifecycleID),
84		TabId:       string(message.TabID),
85		Revision:    message.Revision,
86		Width:       uint32(message.Width),
87		Height:      uint32(message.Height),
88		Cells:       cells,
89	}, nil
90}
91
92// RemotePreviewFromWire requires a non-nil message and re-validates the
93// fully decoded preview.
94func RemotePreviewFromWire(message *wire.RemotePreview) (protocol.RemotePreview, error) {
95	var preview protocol.RemotePreview
96	if message == nil {
97		return preview, ErrOutOfRange
98	}
99	version, err := Uint16[uint16](message.GetVersion())
100	if err != nil {
101		return protocol.RemotePreview{}, err
102	}
103	preview.Version = version
104	status, err := Uint8[protocol.RemotePreviewStatus](message.GetStatus())
105	if err != nil {
106		return protocol.RemotePreview{}, err
107	}
108	preview.Status = status
109	lifecycle, err := LifecycleFromWire(message.GetLifecycleId())
110	if err != nil {
111		return protocol.RemotePreview{}, err
112	}
113	preview.LifecycleID = lifecycle
114	preview.TabID = domain.TabStableID(message.GetTabId())
115	preview.Revision = message.GetRevision()
116	width, err := Uint16[uint16](message.GetWidth())
117	if err != nil {
118		return protocol.RemotePreview{}, err
119	}
120	preview.Width = width
121	height, err := Uint16[uint16](message.GetHeight())
122	if err != nil {
123		return protocol.RemotePreview{}, err
124	}
125	preview.Height = height
126	cells, err := PreviewCellsFromWire(message.GetCells())
127	if err != nil {
128		return protocol.RemotePreview{}, err
129	}
130	preview.Cells = cells
131	if err := protocol.ValidateRemotePreview(preview); err != nil {
132		return protocol.RemotePreview{}, err
133	}
134	return preview, nil
135}

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