Codebergdnkl
foot
master
1#!/usr/bin/env python3
3import argparse
4import os
5import re
8class Capability:
9 def __init__(self, name: str, value: bool | int | str):
10 self._name = name
11 self._value = value
13 @property
14 def name(self) -> str:
15 return self._name
17 @property
18 def value(self) -> bool | int | str:
19 return self._value
21 def __lt__(self, other: object) -> bool:
22 if not isinstance(other, Capability):
23 return NotImplemented
24 return self._name < other._name
26 def __le__(self, other: object) -> bool:
27 if not isinstance(other, Capability):
28 return NotImplemented
29 return self._name <= other._name
31 def __eq__(self, other: object) -> bool:
32 if not isinstance(other, Capability):
33 return NotImplemented
34 return self._name == other._name
36 def __ne__(self, other: object) -> bool:
37 if not isinstance(other, Capability):
38 return NotImplemented
39 return bool(self._name != other._name)
41 def __gt__(self, other: object) -> bool:
42 if not isinstance(other, Capability):
43 return NotImplemented
44 return bool(self._name > other._name)
46 def __ge__(self, other: object) -> bool:
47 if not isinstance(other, Capability):
48 return NotImplemented
49 return self._name >= other._name
52class BoolCapability(Capability):
53 def __init__(self, name: str):
54 super().__init__(name, True)
57class IntCapability(Capability):
58 pass
61class StringCapability(Capability):
62 def __init__(self, name: str, value: str):
63 # see terminfo(5) for valid escape sequences
65 # Control characters
66 def translate_ctrl_chr(m: re.Match[str]) -> str:
67 ctrl = m.group(1)
68 if ctrl == '?':
69 return '\\x7f'
70 return f'\\x{ord(ctrl) - ord("@"):02x}'
71 value = re.sub(r'\^([@A-Z[\\\\\]^_?])', translate_ctrl_chr, value)
73 # Ensure e.g. \E7 (or \e7) doesn’t get translated to “\0337”,
74 # which would be interpreted as octal 337 by the C compiler
75 value = re.sub(r'(\\E|\\e)([0-7])', r'\\033" "\2', value)
77 # Replace \E and \e with ESC
78 value = re.sub(r'\\E|\\e', r'\\033', value)
80 # Unescape ,:^
81 value = re.sub(r'\\(,|:|\^)', r'\1', value)
83 # Replace \s with space
84 value = value.replace('\\s', ' ')
86 # Let \\, \n, \r, \t, \b and \f "fall through", to the C string literal
88 if re.search(r'\\l', value):
89 raise NotImplementedError('\\l escape sequence')
91 super().__init__(name, value)
94class Fragment:
95 def __init__(self, name: str, description: str):
96 self._name = name
97 self._description = description
98 self._caps = dict[str, Capability]()
100 @property
101 def name(self) -> str:
102 return self._name
104 @property
105 def description(self) -> str:
106 return self._description
108 @property
109 def caps(self) -> dict[str, Capability]:
110 return self._caps
112 def add_capability(self, cap: Capability) -> None:
113 assert cap.name not in self._caps
114 self._caps[cap.name] = cap
116 def del_capability(self, name: str) -> None:
117 del self._caps[name]
120def main() -> None:
121 parser = argparse.ArgumentParser()
122 parser.add_argument('source_entry_name')
123 parser.add_argument('source', type=argparse.FileType('r'))
124 parser.add_argument('target_entry_name')
125 parser.add_argument('target', type=argparse.FileType('w'))
127 opts = parser.parse_args()
128 source_entry_name = opts.source_entry_name
129 target_entry_name = opts.target_entry_name
130 source = opts.source
131 target = opts.target
133 lines = list[str]()
134 for line in source.readlines():
135 line = line.strip()
136 if line.startswith('#'):
137 continue
138 lines.append(line)
140 fragments = dict[str, Fragment]()
141 cur_fragment: Fragment | None = None
143 for m in re.finditer(
144 r'(?P<name>(?P<entry_name>[-+\w@]+)\|(?P<entry_desc>.+?),)|'
145 r'(?P<bool_cap>(?P<bool_name>\w+),)|'
146 r'(?P<int_cap>(?P<int_name>\w+)#(?P<int_val>(0x)?[0-9a-fA-F]+),)|'
147 r'(?P<str_cap>(?P<str_name>\w+)=(?P<str_val>(.+?)),)',
148 ''.join(lines)):
150 if m.group('name') is not None:
151 name = m.group('entry_name')
152 description = m.group('entry_desc')
154 assert name not in fragments
155 fragments[name] = Fragment(name, description)
156 cur_fragment = fragments[name]
158 elif m.group('bool_cap') is not None:
159 name = m.group('bool_name')
160 assert cur_fragment is not None
161 cur_fragment.add_capability(BoolCapability(name))
163 elif m.group('int_cap') is not None:
164 name = m.group('int_name')
165 int_value = int(m.group('int_val'), 0)
166 assert cur_fragment is not None
167 cur_fragment.add_capability(IntCapability(name, int_value))
169 elif m.group('str_cap') is not None:
170 name = m.group('str_name')
171 str_value = m.group('str_val')
172 assert cur_fragment is not None
173 cur_fragment.add_capability(StringCapability(name, str_value))
175 else:
176 assert False
178 # Expand ‘use’ capabilities
179 for frag in fragments.values():
180 for cap in frag.caps.values():
181 if cap.name == 'use':
182 assert isinstance(cap, StringCapability)
183 assert isinstance(cap.value, str)
185 use_frag = fragments[cap.value]
186 for use_cap in use_frag.caps.values():
187 frag.add_capability(use_cap)
190 frag.del_capability(cap.name)
191 break
193 entry = fragments[source_entry_name]
195 try:
196 entry.del_capability('RGB')
197 except KeyError:
198 pass
200 entry.add_capability(IntCapability('Co', 256))
201 entry.add_capability(StringCapability('TN', target_entry_name))
202 entry.add_capability(StringCapability('name', target_entry_name))
203 entry.add_capability(IntCapability('RGB', 8)) # 8 bits per channel
204 entry.add_capability(StringCapability('query-os-name', os.uname().sysname))
206 terminfo_parts = list[str]()
207 for cap in sorted(entry.caps.values()):
208 name = cap.name
209 value = str(cap.value)
211 # Escape ‘“‘
212 name = name.replace('"', '\"')
213 value = value.replace('"', '\"')
215 terminfo_parts.append(name)
216 if isinstance(cap, BoolCapability):
217 terminfo_parts.append('')
218 else:
219 terminfo_parts.append(value)
221 terminfo = '\\0" "'.join(terminfo_parts)
223 target.write('#pragma once\n')
224 target.write('\n')
225 target.write(f'static const char terminfo_capabilities[] = "{terminfo}";')
226 target.write('\n')
229if __name__ == '__main__':
230 main()
Diagnostics5 git calls · 491 ms
CallStatusSizeTime0491 ms
discover200178 B2 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=2 git.response.bytes=178 git.server.agent=git/2.56.1-Linux git.server.object_format=sha1 git.server.caps=agent ls-refs fetch server-option object-format git.server.fetch=shallow wait-for-done filter git.protocol.version=2 git.pkt.frames=9 git.pkt.data=7 git.pkt.flush=2 git.pkt.delim=0 git.pkt.bytes=178 git.pkt.payload.max=35
ls-refs20010 KiB463 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=381 git.response.bytes=10322 git.response.cache=EXPIRED git.response.duration_ms=463 git.protocol.version=2 git.pkt.frames=108 git.pkt.data=107 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=10322 git.pkt.payload.max=106 git.ls_refs.count=107 git.ls_refs.head=refs/heads/master
fetchtree:0 · deepen 102009.3 KiB · hit3 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=3 git.response.bytes=9489 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=tree:0 git.fetch.wants=c0d2c3e95d74cb60526ff28aec9f34ee3df545e0 git.fetch.haves.count=0 git.fetch.deepen=10 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=7 git.pkt.data=5 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=9489 git.pkt.payload.max=9389 git.sideband.band1.bytes=9389 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=10 git.pack.bytes=9389 git.pack.ofs_delta=0 git.pack.ref_delta=0 git.pack.chain.max=0 git.pack.trailer=de930681b6073ba5b599a0f956bfbd114762ad5a git.pack.full=10Open pack map
fetchcombine:blob:none+tree:2 · deepen 12008.6 KiB · hit3 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=3 git.response.bytes=8830 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=combine:blob:none+tree:2 git.fetch.wants=c0d2c3e95d74cb60526ff28aec9f34ee3df545e0 git.fetch.haves.count=0 git.fetch.deepen=1 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=7 git.pkt.data=5 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=8830 git.pkt.payload.max=8730 git.sideband.band1.bytes=8730 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=14 git.pack.bytes=8730 git.fetch.wide.objects=14 git.fetch.wide.extra_bytes=9909 git.fetch.wide.blobs=0
fetch2001.9 KiB · hit25 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=25 git.response.bytes=1927 git.response.cache=HIT git.response.duration_ms=25 git.fetch.wants=c10373d353aff1ac61b5f6438be0535e236c8cd2 git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=4 git.pkt.data=3 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=1927 git.pkt.payload.max=1900 git.sideband.band1.bytes=1900 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0
Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.
- Remote
- https://codeberg.org/dnkl/foot
- Ref
- refs/heads/master
- Commit
- c0d2c3e95d74cb60526ff28aec9f34ee3df545e0
- cf-ray
- a5e2bc4c4b80cfc3
- Request
- 5df9c7e0…
- Protocol
- v2 · sha1
- Agent
- git/2.56.1-Linux
- Filter
- advertised
- Fetch
- shallow wait-for-done filter
- Capabilities
- agent ls-refs fetch server-option object-format