Projects : yrc : yrc_minor_command_reorder

yrc/codemap.txt

Dir - Raw

1Record types
2============
3
4conn
5- network: file-safe str
6- sock: socket
7- rdbuf: str
8- wrbuf: str
9- addrs: non-empty list of (host: str, port: int) (first entry is current)
10- nick: str
11- password: str | None
12- registered: bool
13- channels: dict of (channel: casemapped str) => (set of nick: casemapped str)
14- casemapper: function of (str -> casemapped str)
15- reconn_delay: int
16- count: int (number of times connected)
17- ping_ts: float (monotonic time of last sent ping)
18- pong_ts: float (monotonic time of last received pong)
19
20buf
21- name: str
22- parent: buf
23- title: str
24- vscroll: (origin: int, offset: int)
25- lines: list of str
26- num_read: int
27- at_end: bool
28
29buflist (singleton)
30- vscroll: int
31- width: int
32- selection: buf
33- cursor: buf
34- last: buf
35
36prompt (singleton)
37- chars: list of str
38- cursor: int
39- hscroll: int
40
41flags (singleton)
42- refresh
43- redraw
44- buflist_draw
45- buf_draw
46- prompt_draw
47- status_draw
48- quit
49- buflist
50- prompt
51- ping_draw
52
53Enumerations
54============
55
56kbd_state: ks_start ks_cx ks_esc ks_cseq ks_cs_intermed
57
58Variant types
59=============
60
61message: (args all str unless noted)
62- m_privmsg(sender, msg)
63- m_notice(sender, msg)
64- m_join(sender, chan)
65- m_part(sender, chan, msg)
66- m_quit(sender, msg)
67- m_nick(sender, nick)
68- m_kick(sender, chan, name, msg)
69- m_kicked(sender, chan, msg)
70- m_topic(sender, topic: str | None)
71- m_chantopic(sender, chan, topic: str | None)
72- m_mode(sender, modes)
73- m_chanmode(sender, chan, modes)
74- m_names(sender, chan, names)
75- m_endnames(sender, chan)
76- m_error(sender, msg)
77- m_client(msg)
78- m_server(sender, msg)
79
80Quasiconstants
81==============
82
83self_pipe_rd: int
84self_pipe_wr: int
85commands: (name: str) => function
86
87Global state
88============
89
90cur_buf: buf
91scr_height: int
92scr_width: int
93mono_last: float
94mono_offset: float
95out_buf: bytearray
96kbd_accum: bytearray
97kbd_state: function
98
99Collections
100===========
101
102buffers: non-empty list of buf
103buffer_index: (name: str, parent_name: str) => buf
104opening_conns: (fileno: int) => conn
105open_conns: (fileno: int) => conn
106network_conns: (network: str) => conn : all enabled networks, whether TCP alive or not
107schedule: min-heap of (time: float) => thunk
108
109Functions
110=========
111
112Excluding record constructors, accessors and basic mutators.
113
114Startup only:
115command(name: str, min_args=0: int, max_args=None: int | None, extended_arg=False: bool)(function) -> function
116check_command_dicts(keymap)
117make_casemapper(int) -> function of (str -> casemapped str)
118
119Boring:
120set_nonblock
121
122Pure functions:
123format_time(time_tuple) -> str
124is_ctrl(chr) -> bool
125ctrl(chr) -> chr
126is_meta(chr) -> bool
127meta(chr) -> chr
128variant_name(val) -> str
129variant_args(val) -> list
130matcher(vtype, cases: iterable of (constructor, receiver: function of (*args -> x))) -> function of (val: vtype -> x)
131sequence(*thunks) -> thunk
132char_range(pair) -> str
133partition(list, pred) -> (left: list, right: list)
134split_pair(str, sep=' ': str) -> [str, str]
135make_encoder(function of chr -> str) -> function of (str -> str)
136asciify(str) -> str
137fs_encode(str) -> str
138casemap_ascii(str) -> str
139clip(min: comparable, max: comparable, comparable) -> comparable
140clip_to(list, int) -> int
141get_clipped(list, int) -> element of list
142clip_str(str, width: int) -> str
143pad_or_clip_str(str, width: int, pad=' ': chr) -> str
144wrap(line, width, indent=0) -> list of str
145is_digit(chr) -> bool
146parse_address(addr) -> (host: str, port: int) / ValueError
147format_address((host: str, port: int)) -> str
148int_of_bytes(str) -> int
149bit_length(int) -> int
150heap_peek(heap: list) -> (key, value) / IndexError
151safe_filename(name) -> bool
152config_lines(text) -> non-empty list of non-empty str | None
153format_buf_msg(val: message) -> str
154buf_width() -> int
155buf_height() -> int
156render_line(str) -> list of str
157buf_max_vscroll(buf) -> (int, int)
158add_scroll_coords(lines: list of str, coords: (int, int), delta: int) -> (int, int)
159sub_scroll_coords(lines: list of str, coords: (int, int), delta: int) -> (int, int)
160render_lines(lines: list of str, vscroll: (int, int), row_limit: int) -> (list, int)
161build_msg(prefix, cmd, params) -> str
162max_param_len(cmd, prefix=None) -> int
163parse_msg(msg) -> (prefix: str | None, cmd: str, params: list of str) / ProtocolError
164is_chan(str) -> bool
165valid_chan(str) -> bool
166valid_nick(str) -> bool
167valid_password(str) -> bool
168conn_nick_lc(conn) -> casemapped str
169sender_nick(str) -> str
170arg2
171arg3
172empty2
173lterr / TypeError
174format_log_msg(val: message except (m_chantopic | m_mode | m_client)) -> str
175
176Pure I/O:
177write_all(blocking fd, str|bytearray) / EnvironmentError
178read_all(nonblocking fd) -> str / EOFError, EnvironmentError : may return empty
179
180Pure drawing:
181buf_draw(buf)
182prompt_draw
183draw_status(y: int)
184buflist_draw
185buflist_vline_draw
186place_cursor
187refresh_if_needed
188
189"Queries":
190find_buf(buf) -> int : find buf's index in buffers list
191#buf_network(buf) -> str
192buf_conn(buf) -> conn / CommandError
193buf_registered_conn(buf) -> conn / CommandError
194get_config(key, paths=(()), default=None) -> str | default
195
196Side effects on data:
197write_out(str) : stores for write to terminal
198flush_out : sends full terminal output buffer
199variant(vtype, name: str, nargs: int) -> constructor: function of (*args -> (tag, args))
200rand_int(int) -> int
201heap_insert(heap: list, key: comparable, value)
202heap_extract(heap: list) -> (key, value) / IndexError
203run_command(line: str) -> * / CommandError
204buf_log_msg(buf, m: message)
205buf_privmsg(buf, msg: str) : buf_parent ; buf_registered_conn ; conn_privmsg / CommandError
206check_buf_at_end : buf_set_at_end(cur_buf) | buf_clr_at_end(cur_buf)
207is_child_of(buf) -> function of (buf -> bool)
208sort_buffers : sorts buffers & generates buffer_index
209get_buf(name, parent_name) -> buf : buffer_index lookup but creates if not found
210close_buf(buf)
211prompt_insert(chr)
212prompt_submit
213prompt_backspace
214prompt_delete
215info(msg: str, buf=None) : buf_log_msg to buf or buffers[0]
216error(msg_or_exc: str | Exception, buf=None) : buf_log_msg to buf or buffers[0]
217kaccum(str)
218kaccept(str)
219ktrans(kbd_state)
220ks_start(chr)
221ks_cx(chr)
222ks_esc(chr)
223ks_cseq(chr)
224ks_cs_intermed(chr)
225conn_run_in(conn, seconds: float, method: function of (conn), run_if_down=False) : run_in
226conn_log_msg(conn, venue: casemapped str | None, m: message) : get_buf ; buf_log_msg ; file_log_msg
227conn_info(conn, str) : uses conn_log_msg
228conn_error(conn, str) : uses conn_log_msg
229conn_start(conn) : starts connecting; bumps count; rotates addrs; adds to opening_conns and network_conns
230conn_write(conn, str) : stores for nonblocking write by main loop
231conn_send(conn, cmd: str, params: list of str, prefix=None: str) : build_msg ;conn_write (TODO check msg well-formedness)
232conn_handle_connected(conn) : if successful, moves c from opening_conns to open_conns & sends login
233conn_close(conn) : shuts down and removes from open_conns
234conn_handle_data(conn, data: str) : does input buffering; extracts messages and calls...
235conn_handle_msg(conn, msg: str) : mega-function for handling IRC commands
236conn_join(conn, chan: str, key=None) : conn_info ; conn_send
237conn_privmsg(conn, target: str, msg: str) : conn_log_msg ; conn_send
238conn_ping(conn)
239conn_timeout(conn)
240conn_reg_timeout(conn)
241file_log_msg(network: file-safe str, venue: casemapped str | None, m: message)
242handle_resize
243mono_time -> float
244run_in(seconds, thunk)
245
246Slash commands:
247quit_cmd
248connect_cmd
249disconnect_cmd
250join_cmd
251kick_cmd
252mode_cmd
253nick_cmd
254part_cmd
255send_cmd
256
257Lifecycle:
258main
259crash_handler
260
261MVP:
262finish commands
263 close/close-net debug
264prefix case sensitivity in conn_handle_msg?
265
266TODO:
267nick fallback
268buflist vscroll
269modes
270date changes
271prompt history, kill ring
272tab completion (but how to focus buf/prompt?)
273username, realname
274logging
275bold nicks (generally: formatted wrap)
276search in scrollback
277channel key (config, persist across reconnect)
278buffer cleanup by category
279help
280scripting
281self-ping to find user@host to calc max privmsg length
282Proliferation of casemapping is bound to be buggy.
283Recognize WHOIS/WHOWAS/LIST responses
284bracketed paste
285
286Possible cleanups:
287more use of lambda/sequence for trivial functions
288rename buf* to wind* to match manual's terminology (nobody but emacs uses "buffer" to mean "window"...)
289move cur_buf global to a buflist attribute
290use the new scheduler for schedule_*; use delayed redraw to perform well under message floods