detached 1a6c6c9

protocol.go RawHistoryFolder

1package spec
2
3import (
4	"encoding/xml"
5	"fmt"
6)
7
8// Protocol is a parsed Wayland protocol XML document.
9type Protocol struct {
10	XMLName     xml.Name     `xml:"protocol"`
11	Name        string       `xml:"name,attr"`
12	Copyright   string       `xml:"copyright"`
13	Description *Description `xml:"description"`
14	Interfaces  []Interface  `xml:"interface"`
15}
16
17// Interface is a versioned Wayland interface.
18type Interface struct {
19	Name        string       `xml:"name,attr"`
20	Version     int          `xml:"version,attr"`
21	Description *Description `xml:"description"`
22	Requests    []Message    `xml:"request"`
23	Events      []Message    `xml:"event"`
24	Enums       []Enum       `xml:"enum"`
25}
26
27// Message is a request (client to server) or an event (server to client).
28type Message struct {
29	Name        string       `xml:"name,attr"`
30	Type        string       `xml:"type,attr"` // "destructor" or empty
31	Since       int          `xml:"since,attr"`
32	Description *Description `xml:"description"`
33	Args        []Arg        `xml:"arg"`
34}
35
36// Arg is a message argument.
37type Arg struct {
38	Name      string `xml:"name,attr"`
39	Type      string `xml:"type,attr"`
40	Summary   string `xml:"summary,attr"`
41	Interface string `xml:"interface,attr"`
42	AllowNull bool   `xml:"allow-null,attr"`
43	Enum      string `xml:"enum,attr"`
44}
45
46// Enum is an enumeration or bitfield.
47type Enum struct {
48	Name        string       `xml:"name,attr"`
49	Since       int          `xml:"since,attr"`
50	Bitfield    bool         `xml:"bitfield,attr"`
51	Description *Description `xml:"description"`
52	Entries     []Entry      `xml:"entry"`
53}
54
55// Entry is an enum value.
56type Entry struct {
57	Name    string `xml:"name,attr"`
58	Value   string `xml:"value,attr"`
59	Summary string `xml:"summary,attr"`
60	Since   int    `xml:"since,attr"`
61}
62
63// Description is protocol documentation.
64type Description struct {
65	Summary string `xml:"summary,attr"`
66	Text    string `xml:",chardata"`
67}
68
69// Parse decodes a protocol XML document.
70func Parse(data []byte) (*Protocol, error) {
71	var p Protocol
72	if err := xml.Unmarshal(data, &p); err != nil {
73		return nil, fmt.Errorf("parse protocol: %w", err)
74	}
75	if p.Name == "" {
76		return nil, fmt.Errorf("parse protocol: missing protocol name")
77	}
78	return &p, nil
79}
80
81// ReferencedInterfaces returns the interfaces named by arguments of p, in
82// first-seen order, without duplicates.
83func (p *Protocol) ReferencedInterfaces() []string {
84	seen := map[string]bool{}
85	var out []string
86	add := func(ms []Message) {
87		for _, m := range ms {
88			for _, a := range m.Args {
89				if a.Interface != "" && !seen[a.Interface] {
90					seen[a.Interface] = true
91					out = append(out, a.Interface)
92				}
93			}
94		}
95	}
96	for _, it := range p.Interfaces {
97		add(it.Requests)
98		add(it.Events)
99	}
100	return out
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 1

Tags 1

↑↓ moveenter openesc close