├── .flake8
├── .gitignore
├── LICENSE
├── Makefile
├── README.md
├── pyproject.toml
├── retronews.py
├── screenshot.png
├── tests.py
└── tests
├── test_hn_01.html
├── test_hn_01.out
├── test_hn_02.html
├── test_hn_02.out
├── test_hn_03.html
├── test_hn_03.out
├── test_hn_04.html
├── test_hn_04.out
├── test_hn_05.html
├── test_hn_05.out
├── test_hn_06.html
├── test_hn_06.out
├── test_lb_01.html
├── test_lb_01.out
├── test_lb_02.html
├── test_lb_02.out
├── test_lb_03.html
├── test_lb_03.out
├── test_lb_04.html
├── test_lb_04.out
├── test_lb_05.html
├── test_lb_05.out
├── test_lb_06.html
├── test_lb_06.out
├── test_lb_07.html
├── test_lb_07.out
├── test_lb_08.html
├── test_lb_08.out
├── test_lb_09.html
└── test_lb_09.out
/.flake8:
--------------------------------------------------------------------------------
1 | [flake8]
2 | max-line-length = 120
3 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /.mypy_cache
2 | /.venv
3 | /__pycache__
4 | /cache/*
5 | /tmp/*
6 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 2, June 1991
3 |
4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6 | Everyone is permitted to copy and distribute verbatim copies
7 | of this license document, but changing it is not allowed.
8 |
9 | Preamble
10 |
11 | The licenses for most software are designed to take away your
12 | freedom to share and change it. By contrast, the GNU General Public
13 | License is intended to guarantee your freedom to share and change free
14 | software--to make sure the software is free for all its users. This
15 | General Public License applies to most of the Free Software
16 | Foundation's software and to any other program whose authors commit to
17 | using it. (Some other Free Software Foundation software is covered by
18 | the GNU Lesser General Public License instead.) You can apply it to
19 | your programs, too.
20 |
21 | When we speak of free software, we are referring to freedom, not
22 | price. Our General Public Licenses are designed to make sure that you
23 | have the freedom to distribute copies of free software (and charge for
24 | this service if you wish), that you receive source code or can get it
25 | if you want it, that you can change the software or use pieces of it
26 | in new free programs; and that you know you can do these things.
27 |
28 | To protect your rights, we need to make restrictions that forbid
29 | anyone to deny you these rights or to ask you to surrender the rights.
30 | These restrictions translate to certain responsibilities for you if you
31 | distribute copies of the software, or if you modify it.
32 |
33 | For example, if you distribute copies of such a program, whether
34 | gratis or for a fee, you must give the recipients all the rights that
35 | you have. You must make sure that they, too, receive or can get the
36 | source code. And you must show them these terms so they know their
37 | rights.
38 |
39 | We protect your rights with two steps: (1) copyright the software, and
40 | (2) offer you this license which gives you legal permission to copy,
41 | distribute and/or modify the software.
42 |
43 | Also, for each author's protection and ours, we want to make certain
44 | that everyone understands that there is no warranty for this free
45 | software. If the software is modified by someone else and passed on, we
46 | want its recipients to know that what they have is not the original, so
47 | that any problems introduced by others will not reflect on the original
48 | authors' reputations.
49 |
50 | Finally, any free program is threatened constantly by software
51 | patents. We wish to avoid the danger that redistributors of a free
52 | program will individually obtain patent licenses, in effect making the
53 | program proprietary. To prevent this, we have made it clear that any
54 | patent must be licensed for everyone's free use or not licensed at all.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | GNU GENERAL PUBLIC LICENSE
60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61 |
62 | 0. This License applies to any program or other work which contains
63 | a notice placed by the copyright holder saying it may be distributed
64 | under the terms of this General Public License. The "Program", below,
65 | refers to any such program or work, and a "work based on the Program"
66 | means either the Program or any derivative work under copyright law:
67 | that is to say, a work containing the Program or a portion of it,
68 | either verbatim or with modifications and/or translated into another
69 | language. (Hereinafter, translation is included without limitation in
70 | the term "modification".) Each licensee is addressed as "you".
71 |
72 | Activities other than copying, distribution and modification are not
73 | covered by this License; they are outside its scope. The act of
74 | running the Program is not restricted, and the output from the Program
75 | is covered only if its contents constitute a work based on the
76 | Program (independent of having been made by running the Program).
77 | Whether that is true depends on what the Program does.
78 |
79 | 1. You may copy and distribute verbatim copies of the Program's
80 | source code as you receive it, in any medium, provided that you
81 | conspicuously and appropriately publish on each copy an appropriate
82 | copyright notice and disclaimer of warranty; keep intact all the
83 | notices that refer to this License and to the absence of any warranty;
84 | and give any other recipients of the Program a copy of this License
85 | along with the Program.
86 |
87 | You may charge a fee for the physical act of transferring a copy, and
88 | you may at your option offer warranty protection in exchange for a fee.
89 |
90 | 2. You may modify your copy or copies of the Program or any portion
91 | of it, thus forming a work based on the Program, and copy and
92 | distribute such modifications or work under the terms of Section 1
93 | above, provided that you also meet all of these conditions:
94 |
95 | a) You must cause the modified files to carry prominent notices
96 | stating that you changed the files and the date of any change.
97 |
98 | b) You must cause any work that you distribute or publish, that in
99 | whole or in part contains or is derived from the Program or any
100 | part thereof, to be licensed as a whole at no charge to all third
101 | parties under the terms of this License.
102 |
103 | c) If the modified program normally reads commands interactively
104 | when run, you must cause it, when started running for such
105 | interactive use in the most ordinary way, to print or display an
106 | announcement including an appropriate copyright notice and a
107 | notice that there is no warranty (or else, saying that you provide
108 | a warranty) and that users may redistribute the program under
109 | these conditions, and telling the user how to view a copy of this
110 | License. (Exception: if the Program itself is interactive but
111 | does not normally print such an announcement, your work based on
112 | the Program is not required to print an announcement.)
113 |
114 | These requirements apply to the modified work as a whole. If
115 | identifiable sections of that work are not derived from the Program,
116 | and can be reasonably considered independent and separate works in
117 | themselves, then this License, and its terms, do not apply to those
118 | sections when you distribute them as separate works. But when you
119 | distribute the same sections as part of a whole which is a work based
120 | on the Program, the distribution of the whole must be on the terms of
121 | this License, whose permissions for other licensees extend to the
122 | entire whole, and thus to each and every part regardless of who wrote it.
123 |
124 | Thus, it is not the intent of this section to claim rights or contest
125 | your rights to work written entirely by you; rather, the intent is to
126 | exercise the right to control the distribution of derivative or
127 | collective works based on the Program.
128 |
129 | In addition, mere aggregation of another work not based on the Program
130 | with the Program (or with a work based on the Program) on a volume of
131 | a storage or distribution medium does not bring the other work under
132 | the scope of this License.
133 |
134 | 3. You may copy and distribute the Program (or a work based on it,
135 | under Section 2) in object code or executable form under the terms of
136 | Sections 1 and 2 above provided that you also do one of the following:
137 |
138 | a) Accompany it with the complete corresponding machine-readable
139 | source code, which must be distributed under the terms of Sections
140 | 1 and 2 above on a medium customarily used for software interchange; or,
141 |
142 | b) Accompany it with a written offer, valid for at least three
143 | years, to give any third party, for a charge no more than your
144 | cost of physically performing source distribution, a complete
145 | machine-readable copy of the corresponding source code, to be
146 | distributed under the terms of Sections 1 and 2 above on a medium
147 | customarily used for software interchange; or,
148 |
149 | c) Accompany it with the information you received as to the offer
150 | to distribute corresponding source code. (This alternative is
151 | allowed only for noncommercial distribution and only if you
152 | received the program in object code or executable form with such
153 | an offer, in accord with Subsection b above.)
154 |
155 | The source code for a work means the preferred form of the work for
156 | making modifications to it. For an executable work, complete source
157 | code means all the source code for all modules it contains, plus any
158 | associated interface definition files, plus the scripts used to
159 | control compilation and installation of the executable. However, as a
160 | special exception, the source code distributed need not include
161 | anything that is normally distributed (in either source or binary
162 | form) with the major components (compiler, kernel, and so on) of the
163 | operating system on which the executable runs, unless that component
164 | itself accompanies the executable.
165 |
166 | If distribution of executable or object code is made by offering
167 | access to copy from a designated place, then offering equivalent
168 | access to copy the source code from the same place counts as
169 | distribution of the source code, even though third parties are not
170 | compelled to copy the source along with the object code.
171 |
172 | 4. You may not copy, modify, sublicense, or distribute the Program
173 | except as expressly provided under this License. Any attempt
174 | otherwise to copy, modify, sublicense or distribute the Program is
175 | void, and will automatically terminate your rights under this License.
176 | However, parties who have received copies, or rights, from you under
177 | this License will not have their licenses terminated so long as such
178 | parties remain in full compliance.
179 |
180 | 5. You are not required to accept this License, since you have not
181 | signed it. However, nothing else grants you permission to modify or
182 | distribute the Program or its derivative works. These actions are
183 | prohibited by law if you do not accept this License. Therefore, by
184 | modifying or distributing the Program (or any work based on the
185 | Program), you indicate your acceptance of this License to do so, and
186 | all its terms and conditions for copying, distributing or modifying
187 | the Program or works based on it.
188 |
189 | 6. Each time you redistribute the Program (or any work based on the
190 | Program), the recipient automatically receives a license from the
191 | original licensor to copy, distribute or modify the Program subject to
192 | these terms and conditions. You may not impose any further
193 | restrictions on the recipients' exercise of the rights granted herein.
194 | You are not responsible for enforcing compliance by third parties to
195 | this License.
196 |
197 | 7. If, as a consequence of a court judgment or allegation of patent
198 | infringement or for any other reason (not limited to patent issues),
199 | conditions are imposed on you (whether by court order, agreement or
200 | otherwise) that contradict the conditions of this License, they do not
201 | excuse you from the conditions of this License. If you cannot
202 | distribute so as to satisfy simultaneously your obligations under this
203 | License and any other pertinent obligations, then as a consequence you
204 | may not distribute the Program at all. For example, if a patent
205 | license would not permit royalty-free redistribution of the Program by
206 | all those who receive copies directly or indirectly through you, then
207 | the only way you could satisfy both it and this License would be to
208 | refrain entirely from distribution of the Program.
209 |
210 | If any portion of this section is held invalid or unenforceable under
211 | any particular circumstance, the balance of the section is intended to
212 | apply and the section as a whole is intended to apply in other
213 | circumstances.
214 |
215 | It is not the purpose of this section to induce you to infringe any
216 | patents or other property right claims or to contest validity of any
217 | such claims; this section has the sole purpose of protecting the
218 | integrity of the free software distribution system, which is
219 | implemented by public license practices. Many people have made
220 | generous contributions to the wide range of software distributed
221 | through that system in reliance on consistent application of that
222 | system; it is up to the author/donor to decide if he or she is willing
223 | to distribute software through any other system and a licensee cannot
224 | impose that choice.
225 |
226 | This section is intended to make thoroughly clear what is believed to
227 | be a consequence of the rest of this License.
228 |
229 | 8. If the distribution and/or use of the Program is restricted in
230 | certain countries either by patents or by copyrighted interfaces, the
231 | original copyright holder who places the Program under this License
232 | may add an explicit geographical distribution limitation excluding
233 | those countries, so that distribution is permitted only in or among
234 | countries not thus excluded. In such case, this License incorporates
235 | the limitation as if written in the body of this License.
236 |
237 | 9. The Free Software Foundation may publish revised and/or new versions
238 | of the General Public License from time to time. Such new versions will
239 | be similar in spirit to the present version, but may differ in detail to
240 | address new problems or concerns.
241 |
242 | Each version is given a distinguishing version number. If the Program
243 | specifies a version number of this License which applies to it and "any
244 | later version", you have the option of following the terms and conditions
245 | either of that version or of any later version published by the Free
246 | Software Foundation. If the Program does not specify a version number of
247 | this License, you may choose any version ever published by the Free Software
248 | Foundation.
249 |
250 | 10. If you wish to incorporate parts of the Program into other free
251 | programs whose distribution conditions are different, write to the author
252 | to ask for permission. For software which is copyrighted by the Free
253 | Software Foundation, write to the Free Software Foundation; we sometimes
254 | make exceptions for this. Our decision will be guided by the two goals
255 | of preserving the free status of all derivatives of our free software and
256 | of promoting the sharing and reuse of software generally.
257 |
258 | NO WARRANTY
259 |
260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268 | REPAIR OR CORRECTION.
269 |
270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278 | POSSIBILITY OF SUCH DAMAGES.
279 |
280 | END OF TERMS AND CONDITIONS
281 |
282 | How to Apply These Terms to Your New Programs
283 |
284 | If you develop a new program, and you want it to be of the greatest
285 | possible use to the public, the best way to achieve this is to make it
286 | free software which everyone can redistribute and change under these terms.
287 |
288 | To do so, attach the following notices to the program. It is safest
289 | to attach them to the start of each source file to most effectively
290 | convey the exclusion of warranty; and each file should have at least
291 | the "copyright" line and a pointer to where the full notice is found.
292 |
293 | {entry['url']} {thread['url']} Lorem ipsum dolor sit amet, pro eu soleat civibus. Mel quas sensibus te. Noster nominati recteque no has. Lorem ipsum dolor sit amet, pro eu soleat civibus. Mel quas sensibus te. Noster nominati recteque no has. >>Lorem ipsum dolor sit amet, pro eu soleat civibus. Mel quas sensibus te. Noster nominati recteque no has. > Lorem ipsum dolor sit amet, pro eu soleat civibus. Mel quas sensibus te. Noster nominati recteque no has. Lorem ipsum dolor sit amet, pro eu soleat civibus. Mel quas sensibus te. Noster nominati recteque no has. Lorem ipsum dolor sit amet, pro eu soleat civibus. Mel quas sensibus [0]: https://long.long.long.long.long.long.long.long.long.long.long.example.com [1] - https://long.long.long.long.long.long.long.long.long.long.long.example.com [2] https://long.long.long.long.long.long.long.long.long.long.long.example.com Lorem ipsum dolor sit amet, pro eu soleat civibus. Mel quas sensibus te. Noster nominati recteque no has.
24 |
25 | ## Customization
26 |
27 | To customize retronews without directly editing the script, you can put any valid
28 | Python code in `~/.retronewsrc.py` (or other location specified with `--rcfile`) to
29 | be executed on startup. For example:
30 |
31 | ```python
32 | # Ignore type warnings
33 | from typing import Any
34 | retronews: Any
35 |
36 | # Example: Custom key bindings
37 | retronews.KEY_BINDINGS[ord('a')] = lambda app: retronews.cmd_prev(app)
38 | retronews.KEY_BINDINGS[ord('z')] = lambda app: retronews.cmd_next(app)
39 |
40 | # Example: Custom colors
41 | retronews.COLORS['author'] = (retronews.curses.COLOR_RED, -1)
42 | ```
43 |
44 | ## Known issues and limitations
45 |
46 | - The reader is read-only, there are no plans to support voting and posting
47 | - Message formatting is not perfect, but works well enough most of the time
48 | - Detecting if threads contain unread responses works by only checking their
49 | count, it's not reliable if any responses were deleted
50 |
51 | ## Why not an NNTP gateway?
52 |
53 | NNTP doesn't support browsing threads by title (let alone paginated) and requesting
54 | their messages on demand. Clients need to fetch metadata of all available messages
55 | in all available threads in advance. Given the volume of messages on HN, synchronizing
56 | them to the gateway is not practical. Even when attempted, some clients struggle
57 | with the sheer number of messages in a single group.
58 |
59 | ## Related projects
60 |
61 | - [HN Search @ Algolia](https://hn.algolia.com/about) - The underlying API used to retrieve messages
62 | - [nntpit](https://github.com/taviso/nntpit) - An NNTP gateway to reddit.com
63 | - [circumflex](https://github.com/bensadeh/circumflex) - Another, more advanced TUI for HN
64 |
--------------------------------------------------------------------------------
/pyproject.toml:
--------------------------------------------------------------------------------
1 | [tool.isort]
2 | profile = "black"
3 |
4 | [tool.black]
5 | line-length = 120
6 |
--------------------------------------------------------------------------------
/retronews.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | #
3 | # Copyright (c) luke8086
4 | #
5 | # This program is free software: you can redistribute it and/or modify
6 | # it under the terms of the GNU General Public License version 2 as published by
7 | # the Free Software Foundation.
8 | #
9 |
10 | import sys
11 |
12 | if sys.version_info < (3, 9):
13 | sys.stderr.write("Python 3.9 or newer is required.\n")
14 | sys.exit(1)
15 |
16 | import argparse
17 | import curses
18 | import curses.textpad
19 | import dataclasses
20 | import html.parser
21 | import json
22 | import logging
23 | import os
24 | import re
25 | import sqlite3
26 | import traceback
27 | import unicodedata
28 | import urllib.request
29 | import webbrowser
30 | from collections import defaultdict
31 | from datetime import datetime
32 | from functools import partial, reduce
33 | from textwrap import wrap
34 | from typing import (
35 | TYPE_CHECKING,
36 | Any,
37 | Callable,
38 | Generator,
39 | Literal,
40 | NewType,
41 | Optional,
42 | TypedDict,
43 | TypeVar,
44 | Union,
45 | cast,
46 | overload,
47 | )
48 |
49 | KEY_BINDINGS: dict[int, Callable[["AppState"], None]] = {
50 | ord("q"): lambda app: cmd_quit(app),
51 | ord("?"): lambda app: cmd_help(app),
52 | ord("\n"): lambda app: cmd_open(app),
53 | ord(" "): lambda app: cmd_open(app),
54 | ord("o"): lambda app: cmd_show_links(app),
55 | ord("x"): lambda app: cmd_close(app),
56 | ord("s"): lambda app: cmd_star(app),
57 | ord("S"): lambda app: cmd_star_thread(app),
58 | ord("u"): lambda app: cmd_set_unread(app),
59 | ord("D"): lambda app: cmd_dump(app),
60 | ord("r"): lambda app: cmd_toggle_raw_mode(app),
61 | ord("k"): lambda app: cmd_up(app),
62 | ord("j"): lambda app: cmd_down(app),
63 | ord("p"): lambda app: cmd_prev(app),
64 | ord("n"): lambda app: cmd_next(app),
65 | ord("N"): lambda app: cmd_next_unread(app),
66 | ord("P"): lambda app: cmd_parent(app),
67 | ord(";"): lambda app: cmd_mark_set(app),
68 | ord(","): lambda app: cmd_mark_jump(app),
69 | ord("R"): lambda app: cmd_reload_page(app),
70 | ord("<"): lambda app: cmd_load_prev_page(app),
71 | ord(">"): lambda app: cmd_load_next_page(app),
72 | ord("g"): lambda app: cmd_load_page(app),
73 | curses.KEY_UP: lambda app: cmd_prev(app),
74 | curses.KEY_DOWN: lambda app: cmd_next(app),
75 | curses.KEY_PPAGE: lambda app: cmd_page_up(app),
76 | curses.KEY_NPAGE: lambda app: cmd_page_down(app),
77 | curses.KEY_RESIZE: lambda app: cmd_resize(app),
78 | } | {ord(str(i)): lambda app, i=i: cmd_load_tab(app, i) for i in range(1, 10)}
79 |
80 | HELP_MENU = "q:Quit ?:Help p:Prev n:Next N:Next-Unread j:Down k:Up x:Close s:Star"
81 |
82 | HELP_SCREEN = """\
83 | q Quit retronews
84 | UP, DOWN Go up / down by one message / pager line
85 | PG UP, PG DOWN Gp up / down by one page of messages / pager lines
86 | p, n Go to previous / next message
87 | N Go to next unread message
88 | P Go to parent message
89 | ; , Set mark, jump to mark & swap (valid within thread)
90 | RETURN, SPACE Open selected message
91 | x Close current message / thread
92 | o Select link and open in browser
93 | 1 - 9 Change group
94 | R Refresh current page
95 | < > Go to previous / next page
96 | g Go to specific page
97 | k j Scroll pager up / down by one line
98 | s Star / unstar current message
99 | S Star / unstar current thread
100 | u Mark current message as unread
101 | r Toggle raw HTML mode
102 |
103 | See https://github.com/luke8086/retronews for more information."""
104 |
105 | Color = Literal[
106 | "author",
107 | "code",
108 | "cursor",
109 | "date",
110 | "default",
111 | "empty_pager_line",
112 | "deleted_message_pager_line",
113 | "menu",
114 | "menu_active",
115 | "nested_quote",
116 | "quote",
117 | "starred_subject",
118 | "header_subject",
119 | "tree",
120 | "unread_comments",
121 | "url",
122 | ]
123 |
124 | COLORS: dict[Color, tuple[int, int]] = {
125 | "author": (curses.COLOR_YELLOW, -1),
126 | "code": (curses.COLOR_GREEN, -1),
127 | "cursor": (curses.COLOR_BLACK, curses.COLOR_CYAN),
128 | "date": (curses.COLOR_CYAN, -1),
129 | "default": (curses.COLOR_WHITE, -1),
130 | "empty_pager_line": (curses.COLOR_GREEN, -1),
131 | "deleted_message_pager_line": (curses.COLOR_RED, -1),
132 | "menu": (curses.COLOR_GREEN, curses.COLOR_BLUE),
133 | "menu_active": (curses.COLOR_YELLOW, curses.COLOR_BLUE),
134 | "nested_quote": (curses.COLOR_CYAN, -1),
135 | "quote": (curses.COLOR_YELLOW, -1),
136 | "starred_subject": (curses.COLOR_CYAN, -1),
137 | "header_subject": (curses.COLOR_GREEN, -1),
138 | "tree": (curses.COLOR_RED, -1),
139 | "unread_comments": (curses.COLOR_GREEN, -1),
140 | "url": (curses.COLOR_MAGENTA, -1),
141 | }
142 |
143 | REQUEST_TIMEOUT = 10
144 |
145 | # Recognize ">text", "> text", ">>text", ">> text", etc.
146 | QUOTE_REX = re.compile(r"^(> ?)+")
147 |
148 | # Recognize "[n] link", "[n]: link", "[n] - link", etc.
149 | REFERENCE_REX = re.compile(r"^\[\d+\][ :-]*https?://[^ ]*$")
150 |
151 | # Recognize http/https URLs
152 | URL_REX = re.compile(r"(https?://[^\s\)\"<,]+[^\s\)\"<,\.])")
153 |
154 | # Recognize HN message URLs
155 | HN_URL_REX = re.compile(r"^https://news\.ycombinator\.com/item\?id=(\d+)$")
156 |
157 | # FIXME: Use TypeAlias after migrating to Python 3.10
158 | DB = NewType("DB", "sqlite3.Connection")
159 |
160 | if TYPE_CHECKING:
161 | from _curses import _CursesWindow
162 |
163 | Window = _CursesWindow
164 | else:
165 | Window = Any
166 |
167 | T = TypeVar("T")
168 |
169 |
170 | class ExitException(Exception):
171 | code: int
172 | message: str
173 |
174 | def __init__(self, code: int = 0, message: str = ""):
175 | self.code = code
176 | self.message = message
177 |
178 | super().__init__(message)
179 |
180 |
181 | @dataclasses.dataclass(frozen=True)
182 | class Provider:
183 | fetch_thread: Callable[[str], "Message"]
184 | fetch_threads_by_id: Callable[[list[str]], list["Message"]]
185 |
186 |
187 | PROVIDERS: dict[str, Provider] = {
188 | "hn": Provider(
189 | fetch_thread=lambda msg_id: hn_fetch_thread(msg_id),
190 | fetch_threads_by_id=lambda msg_ids: hn_fetch_threads_by_id(msg_ids),
191 | ),
192 | "lb": Provider(
193 | fetch_thread=lambda msg_id: lb_fetch_thread(msg_id),
194 | fetch_threads_by_id=lambda msg_ids: [lb_fetch_thread(x) for x in msg_ids],
195 | ),
196 | }
197 |
198 |
199 | @dataclasses.dataclass(frozen=True)
200 | class Group:
201 | label: str
202 | fetch: Callable[[DB, int], list["Message"]]
203 | page: int = 1
204 |
205 |
206 | GROUP_TABS: list[Group] = [
207 | Group(label="Front HN", fetch=lambda db, page: hn_fetch_threads("news", page)),
208 | Group(label="New HN", fetch=lambda db, page: hn_fetch_new_threads(page)),
209 | Group(label="Ask HN", fetch=lambda db, page: hn_fetch_threads("ask", page)),
210 | Group(label="Show HN", fetch=lambda db, page: hn_fetch_threads("show", page)),
211 | Group(label="Front LB", fetch=lambda db, page: lb_fetch_threads("", page)),
212 | Group(label="New LB", fetch=lambda db, page: lb_fetch_threads("newest", page)),
213 | Group(label="Starred", fetch=lambda db, page: group_fetch_starred_threads(db, page)),
214 | ]
215 |
216 |
217 | @dataclasses.dataclass
218 | class MessageFlags:
219 | read: bool = False
220 | starred: bool = False
221 |
222 |
223 | @dataclasses.dataclass
224 | class Message:
225 | msg_id: str
226 | thread_id: str
227 | content_location: str
228 | date: datetime
229 | author: Optional[str]
230 | title: str
231 | body: Optional[str] = None
232 | lines: list[str] = dataclasses.field(default_factory=list)
233 | parent: Optional["Message"] = None
234 | children: Optional[list["Message"]] = None
235 | flags: MessageFlags = dataclasses.field(default_factory=MessageFlags)
236 | read_comments: int = 0
237 | total_comments: int = 0
238 | index_position: int = 0
239 | index_tree: str = ""
240 |
241 | @property
242 | def is_read(self) -> bool:
243 | return self.flags.read
244 |
245 | @property
246 | def is_shown_as_read(self) -> bool:
247 | # If the message is an unloaded thread, check if all comments are read
248 | return self.read_comments >= self.total_comments if self.is_thread and self.children is None else self.is_read
249 |
250 | @property
251 | def is_thread(self) -> bool:
252 | return self.msg_id == self.thread_id
253 |
254 | @property
255 | def is_deleted(self) -> bool:
256 | return self.author is None
257 |
258 |
259 | @dataclasses.dataclass
260 | class Layout:
261 | lines: int = 0
262 | cols: int = 0
263 | top_menu_row: int = 0
264 | index_start: int = 1
265 | index_height: int = 0
266 | middle_menu_row: Optional[int] = None
267 | pager_start: Optional[int] = None
268 | pager_height: Optional[int] = None
269 | bottom_menu_row: int = 0
270 | flash_menu_row: int = 0
271 |
272 |
273 | @dataclasses.dataclass
274 | class AppState:
275 | screen: Window
276 | db: DB
277 | group: Group
278 | ascii: bool = False
279 | monochrome: bool = False
280 | colors: dict[Color, int] = dataclasses.field(default_factory=dict)
281 | messages: list[Message] = dataclasses.field(default_factory=list)
282 | messages_by_id: dict[str, Message] = dataclasses.field(default_factory=dict)
283 | selected_message: Optional[Message] = None
284 | marked_message_id: Optional[str] = None
285 | layout: Layout = dataclasses.field(default_factory=Layout)
286 | pager_visible: bool = False
287 | pager_offset: int = 0
288 | raw_mode: bool = False
289 | flash: Optional[str] = None
290 |
291 |
292 | class HNSearchHit(TypedDict):
293 | objectID: int
294 | author: Optional[str]
295 | title: str
296 | created_at_i: int
297 | story_text: Optional[str]
298 | url: Optional[str]
299 | num_comments: int
300 |
301 |
302 | class HNEntry(TypedDict):
303 | author: Optional[str]
304 | # FIXME: Recursive declarations are not yet supported in TypedDicts
305 | children: list[Any]
306 | created_at_i: int
307 | id: int
308 | parent_id: Optional[int]
309 | text: Optional[str]
310 | title: Optional[str]
311 | url: Optional[str]
312 |
313 |
314 | class LBThread(TypedDict):
315 | short_id: str
316 | short_id_url: str
317 | created_at: str
318 | title: str
319 | url: str
320 | description: str
321 | submitter_user: str
322 | comment_count: int
323 | comments: Optional[list[Any]]
324 |
325 |
326 | class LBComment(TypedDict):
327 | short_id: str
328 | created_at: str
329 | url: str
330 | commenting_user: str
331 | parent_comment: Optional[str]
332 |
333 |
334 | HTML_BLOCK_TAGS = set(("root", "p", "pre", "blockquote", "ul", "ol", "li", "hr"))
335 | HTML_INLINE_TAGS = set(("code", "a", "em", "strong", "b", "br"))
336 | HTML_KNOWN_TAGS = HTML_BLOCK_TAGS.union(HTML_INLINE_TAGS)
337 | HTML_AUTOCLOSE_TAGS = set(("hr", "br"))
338 |
339 |
340 | @dataclasses.dataclass
341 | class HTMLNode:
342 | tag: str
343 |
344 | parent: Optional["HTMLNode"] = None
345 |
346 | prev_sibling: Optional["HTMLNode"] = None
347 | next_sibling: Optional["HTMLNode"] = None
348 |
349 | first_child: Optional["HTMLNode"] = None
350 | last_child: Optional["HTMLNode"] = None
351 |
352 | attrs: dict[str, Optional[str]] = dataclasses.field(default_factory=dict)
353 | text: str = ""
354 | pre: bool = False
355 |
356 |
357 | class HTMLParser(html.parser.HTMLParser):
358 | root_node: HTMLNode
359 | current_node: HTMLNode
360 | pre_level = 0
361 |
362 | def __init__(self):
363 | super().__init__()
364 |
365 | self.root_node = self.current_node = HTMLNode(tag="root")
366 |
367 | def handle_data(self, data: str) -> None:
368 | if self.current_node.tag in HTML_AUTOCLOSE_TAGS:
369 | self.handle_endtag(self.current_node.tag)
370 |
371 | node = HTMLNode(tag="text", text=data, pre=self.pre_level > 0)
372 | html_node_append(self.current_node, node)
373 |
374 | def handle_starttag(self, tag: str, attrs: list[tuple[str, Optional[str]]]) -> None:
375 | if self.current_node.tag in HTML_AUTOCLOSE_TAGS:
376 | self.handle_endtag(self.current_node.tag)
377 |
378 | if tag not in HTML_KNOWN_TAGS:
379 | return
380 |
381 | if tag == "pre":
382 | self.pre_level += 1
383 |
384 | node = HTMLNode(tag=tag, attrs=dict(attrs), pre=self.pre_level > 0)
385 | html_node_append(self.current_node, node)
386 | self.current_node = node
387 |
388 | def handle_endtag(self, tag: str) -> None:
389 | if tag not in HTML_KNOWN_TAGS:
390 | return
391 |
392 | if tag == "pre":
393 | self.pre_level = max(0, self.pre_level - 1)
394 |
395 | while True:
396 | node = self.current_node
397 |
398 | if node.parent is None:
399 | break
400 |
401 | self.current_node = node.parent
402 |
403 | if node.tag == tag:
404 | break
405 |
406 |
407 | def text_wrap(text: str, width=70) -> str:
408 | if len(text) == 0:
409 | # Preserve empty lines
410 | return ""
411 |
412 | if text.startswith(" "):
413 | # Preserve code indentation
414 | return text
415 |
416 | if REFERENCE_REX.match(text):
417 | # Keep reference numbers with long links in the same line
418 | return text
419 |
420 | indent = ""
421 |
422 | if (match := QUOTE_REX.match(text)) is not None:
423 | # Preserve quotation symbols in subsequent lines
424 | indent = match[0]
425 |
426 | lines = wrap(text, width, subsequent_indent=indent, break_on_hyphens=False, break_long_words=False)
427 | lines = [line.rstrip() for line in lines]
428 |
429 | return "\n".join(lines)
430 |
431 |
432 | def text_clean(text: str, ascii: bool = False) -> str:
433 | """Cleanup text for rendering, currently only removes non-ascii characters in ascii mode"""
434 |
435 | if ascii:
436 | text = text.encode("ascii", "replace").decode("ascii")
437 |
438 | return text
439 |
440 |
441 | def text_unindent(text: str) -> str:
442 | lines = text.split("\n")
443 |
444 | while all(line.startswith(" ") or line == "" for line in lines):
445 | lines = [line[1:] for line in lines]
446 |
447 | return "\n".join(lines)
448 |
449 |
450 | def text_sanitize(text: Optional[str]) -> str:
451 | # For safety, remove any control characters except for \n and \t
452 | # At least on HN some messages contain \x00 characters
453 |
454 | text = text or ""
455 | allowed_cc = set(("\n", "\t"))
456 | chars = (c for c in text if c in allowed_cc or unicodedata.category(c) != "Cc")
457 | text = "".join(chars)
458 |
459 | return text
460 |
461 |
462 | def text_split_urls(text: str) -> list[str]:
463 | return [p for p in URL_REX.split(text) if p != ""]
464 |
465 |
466 | def html_node_children(parent: HTMLNode) -> list[HTMLNode]:
467 | ret: list[HTMLNode] = []
468 | node = parent.first_child
469 |
470 | while node is not None:
471 | ret.append(node)
472 | node = node.next_sibling
473 |
474 | return ret
475 |
476 |
477 | def html_node_append(parent: HTMLNode, child: HTMLNode) -> None:
478 | if parent.first_child is None:
479 | parent.first_child = child
480 |
481 | if parent.last_child is not None:
482 | parent.last_child.next_sibling = child
483 | child.prev_sibling = parent.last_child
484 |
485 | parent.last_child = child
486 | child.parent = parent
487 |
488 |
489 | def html_node_unlink(node: HTMLNode) -> None:
490 | if node.prev_sibling:
491 | node.prev_sibling.next_sibling = node.next_sibling
492 |
493 | if node.next_sibling:
494 | node.next_sibling.prev_sibling = node.prev_sibling
495 |
496 | if node.parent and node.parent.first_child is node:
497 | node.parent.first_child = node.next_sibling
498 |
499 | if node.parent and node.parent.last_child is node:
500 | node.parent.last_child = node.prev_sibling
501 |
502 | node.parent = node.prev_sibling = node.next_sibling = None
503 |
504 |
505 | def html_node_dump(node: HTMLNode) -> str:
506 | lines = []
507 | lines.append(f"{node.tag} {repr(node.attrs)}")
508 |
509 | for child in html_node_children(node):
510 | if child.tag == "text":
511 | lines.append(" text " + repr(child.text))
512 | else:
513 | lines += [" " + line for line in html_node_dump(child).split("\n")]
514 |
515 | return "\n".join(lines)
516 |
517 |
518 | def html_node_trim_whitespace(node: HTMLNode) -> None:
519 | if node.pre:
520 | node.text = node.text.rstrip("\r\n\t ")
521 | return
522 |
523 | text = node.text.strip("\r\n\t ")
524 | text = re.sub(r"[\r\n\t ]+", " ", text)
525 | text = text.replace("\x00", "\n")
526 | text = re.sub(r" *\n *", "\n", text)
527 |
528 | node.text = text
529 |
530 |
531 | def html_node_process_inline(node: HTMLNode, inline=False) -> str:
532 | """Traverse tree flattening all inline nodes into text nodes"""
533 |
534 | if node.tag not in HTML_BLOCK_TAGS:
535 | # Never disable inline if already enabled
536 | inline = True
537 |
538 | text = "".join(html_node_process_inline(c, inline) for c in html_node_children(node))
539 |
540 | if not inline:
541 | return ""
542 |
543 | if node.tag == "text":
544 | text = node.text
545 | elif node.tag == "br":
546 | text = "\x00"
547 | elif node.tag == "em" or node.tag == "i":
548 | text = f"/{text}/"
549 | elif node.tag == "strong" or node.tag == "b":
550 | text = f"*{text}*"
551 | elif node.tag == "code" and not node.pre:
552 | text = f"`{text}`"
553 | elif node.tag == "a":
554 | href = node.attrs.get("href", "") or ""
555 | if text.endswith("...") and href.startswith(text[:-3]):
556 | # Workaround for link formatting on HN
557 | text = href
558 | elif text != href:
559 | text = f"{text} {href}"
560 |
561 | node.tag = "text"
562 | node.text = text
563 | node.first_child = node.last_child = None
564 |
565 | return text
566 |
567 |
568 | def html_node_process_text(node: HTMLNode):
569 | """Traverse tree merging, trimming and pruning text nodes"""
570 |
571 | for child in html_node_children(node):
572 | html_node_process_text(child)
573 |
574 | # Merge adjacent text nodes
575 | for child in html_node_children(node):
576 | prev = child.prev_sibling
577 | if child.tag == "text" and prev is not None and prev.tag == "text" and child.pre == prev.pre:
578 | child.text = prev.text + child.text
579 | html_node_unlink(prev)
580 |
581 | # Trim whitespace from text nodes
582 | for child in html_node_children(node):
583 | if child.tag == "text":
584 | html_node_trim_whitespace(child)
585 |
586 | # Remove empty text nodes
587 | for child in html_node_children(node):
588 | if child.tag == "text" and child.text == "":
589 | html_node_unlink(child)
590 |
591 |
592 | def html_node_render_block(node: HTMLNode, width=70) -> str:
593 | if node.tag == "blockquote" or node.tag == "li" or node.tag == "pre":
594 | width -= 2
595 |
596 | parts = []
597 |
598 | if node.tag == "hr":
599 | parts.append("-" * width)
600 |
601 | for child in html_node_children(node):
602 | if child.tag == "text" and child.pre:
603 | parts.append(child.text)
604 |
605 | elif child.tag == "text" and not child.pre:
606 | subparts = [text_wrap(p, width) for p in child.text.split("\n")]
607 | parts.append("\n".join(subparts))
608 |
609 | else:
610 | parts.append(html_node_render_block(child, width))
611 |
612 | if child.next_sibling is not None and child.tag != "li":
613 | parts.append("")
614 |
615 | text = "\n".join(parts)
616 |
617 | if node.tag == "blockquote":
618 | text = "\n".join((">" if line.startswith("> ") else "> ") + line for line in text.split("\n"))
619 | elif node.tag == "pre":
620 | text = text_unindent(text)
621 | text = "\n".join("| " + line for line in text.split("\n"))
622 | elif node.tag == "li":
623 | lines = text.split("\n")
624 | lines = [("- " + lines[0]).rstrip()] + [(" " + line).rstrip() for line in lines[1:]]
625 | text = "\n".join(lines)
626 |
627 | return text
628 |
629 |
630 | def html_render(html: str) -> str:
631 | # This renderer works well for HN messages because their markup is simple, and it can do
632 | # some custom optimizations, like expanding ellipsis-shortened links, preserving quote
633 | # symbols in wrapped lines, and preventing references with long urls from being broken
634 | # into separate lines. For other backends it may make more sense to use an external app
635 | # (links, w3m, etc)
636 |
637 | html = text_sanitize(html)
638 |
639 | parser = HTMLParser()
640 | parser.feed(html)
641 | parser.close()
642 |
643 | node = parser.root_node
644 |
645 | log_sep = "\n" + "-" * 80 + "\n"
646 | logging.debug(f"Initial HTML tree{log_sep}{html_node_dump(node)}{log_sep}")
647 |
648 | html_node_process_inline(node)
649 | html_node_process_text(node)
650 |
651 | logging.debug(f"Processed HTML tree{log_sep}{html_node_dump(node)}{log_sep}")
652 |
653 | return html_node_render_block(node)
654 |
655 |
656 | def fetch(url: str) -> str:
657 | logging.debug(f"Fetching '{url}'...")
658 |
659 | headers = {"User-Agent": "retronews"}
660 | req = urllib.request.Request(url, headers=headers)
661 | resp = urllib.request.urlopen(req, timeout=REQUEST_TIMEOUT).read().decode()
662 |
663 | return resp
664 |
665 |
666 | @overload
667 | def list_get(lst: list[T], index: int, default: T) -> T: ...
668 |
669 |
670 | @overload
671 | def list_get(lst: list[T], index: int, default: Optional[T] = None) -> Optional[T]: ...
672 |
673 |
674 | def list_get(lst, index, default=None):
675 | return lst[index] if 0 <= index < len(lst) else default
676 |
677 |
678 | def list_chunk(lst: list[T], size: int) -> list[list[T]]:
679 | # Flake8 conflicts with Black here - https://github.com/PyCQA/pycodestyle/issues/373
680 | return [lst[i : i + size] for i in range(0, len(lst), size)] # noqa: E203
681 |
682 |
683 | def cmd_quit(_: AppState):
684 | raise ExitException()
685 |
686 |
687 | def cmd_help(app: AppState):
688 | app_show_help_screen(app)
689 |
690 |
691 | def cmd_show_links(app: AppState):
692 | app_show_links_screen(app)
693 |
694 |
695 | def cmd_up(app: AppState) -> None:
696 | cmd_pager_up(app) if app.pager_visible else cmd_prev(app)
697 |
698 |
699 | def cmd_down(app: AppState) -> None:
700 | cmd_pager_down(app) if app.pager_visible else cmd_next(app)
701 |
702 |
703 | def cmd_prev(app: AppState) -> None:
704 | pos = app.selected_message.index_position - 1 if app.selected_message else 0
705 | app_select_message(app, list_get(app.messages, pos, app.selected_message))
706 |
707 |
708 | def cmd_next(app: AppState) -> None:
709 | pos = app.selected_message.index_position + 1 if app.selected_message else 0
710 | app_select_message(app, list_get(app.messages, pos, app.selected_message))
711 |
712 |
713 | def cmd_next_unread(app: AppState) -> None:
714 | pos = app.selected_message.index_position + 1 if app.selected_message else 0
715 | message = next((msg for msg in app.messages[pos:] if not msg.is_shown_as_read), None)
716 | if message is not None:
717 | app_select_message(app, message)
718 |
719 |
720 | def cmd_next_sibling(app: AppState) -> None:
721 | if (msg := app.selected_message) and (parent_msg := msg.parent) and parent_msg.children:
722 | # find the next sibling
723 | try:
724 | idx = parent_msg.children.index(msg)
725 | if idx < len(parent_msg.children):
726 | app_select_message(app, parent_msg.children[idx + 1])
727 | except IndexError:
728 | pass
729 |
730 |
731 | def cmd_prev_sibling(app: AppState) -> None:
732 | if (msg := app.selected_message) and (parent_msg := msg.parent) and parent_msg.children:
733 | # find the previous sibling
734 | try:
735 | idx = parent_msg.children.index(msg)
736 | if idx > 0:
737 | app_select_message(app, parent_msg.children[idx - 1])
738 | except IndexError:
739 | pass
740 |
741 |
742 | def cmd_mark_thread_as_read(app: AppState) -> None:
743 | # recursively mark us and all children as read
744 | # then jump to the next sibling
745 | def iterate(message: Message):
746 | if message.children:
747 | for child in message.children:
748 | child.flags.read = True
749 | db_save_message(app.db, child)
750 | iterate(child)
751 |
752 | if (msg := app.selected_message) is not None:
753 | iterate(msg)
754 | # jump to the next sibling
755 | cmd_next_sibling(app)
756 |
757 |
758 | def cmd_parent(app: AppState) -> None:
759 | if (msg := app.selected_message) is not None and (parent_msg := msg.parent) is not None:
760 | app_select_message(app, parent_msg)
761 |
762 |
763 | def cmd_mark_set(app: AppState) -> None:
764 | if (msg := app.selected_message) is not None:
765 | app.marked_message_id = msg.msg_id
766 | app_show_flash(app, "Mark set")
767 |
768 |
769 | def cmd_mark_jump(app: AppState) -> None:
770 | marked_msg = app.messages_by_id.get(app.marked_message_id) if app.marked_message_id else None
771 | cmd_mark_set(app)
772 | if marked_msg is not None:
773 | app_select_message(app, marked_msg)
774 | app_show_flash(app, "Mark swapped")
775 |
776 |
777 | def cmd_pager_up(app: AppState) -> None:
778 | app.pager_offset = max(0, app.pager_offset - 1)
779 |
780 |
781 | def cmd_pager_down(app: AppState) -> None:
782 | if app.selected_message is not None and app.layout.pager_height is not None:
783 | app.pager_offset = min(app.pager_offset + 1, max(0, len(app.selected_message.lines) - app.layout.pager_height))
784 |
785 |
786 | def cmd_page_up(app: AppState) -> None:
787 | cmd_pager_page_up(app) if app.pager_visible else cmd_index_page_up(app)
788 |
789 |
790 | def cmd_page_down(app: AppState) -> None:
791 | cmd_pager_page_down(app) if app.pager_visible else cmd_index_page_down(app)
792 |
793 |
794 | def cmd_index_page_up(app: AppState) -> None:
795 | pos = app.selected_message.index_position - app.layout.index_height if app.selected_message else 0
796 | pos = max(pos, 0)
797 | app_select_message(app, list_get(app.messages, pos, app.selected_message))
798 |
799 |
800 | def cmd_index_page_down(app: AppState) -> None:
801 | pos = app.selected_message.index_position + app.layout.index_height if app.selected_message else 0
802 | pos = min(pos, len(app.messages) - 1)
803 | app_select_message(app, list_get(app.messages, pos, app.selected_message))
804 |
805 |
806 | def cmd_pager_page_up(app: AppState) -> None:
807 | if app.layout.pager_height is not None:
808 | app.pager_offset = max(0, app.pager_offset - app.layout.pager_height)
809 |
810 |
811 | def cmd_pager_page_down(app: AppState) -> None:
812 | if (message := app.selected_message) is not None and (pager_height := app.layout.pager_height) is not None:
813 | app.pager_offset = min(app.pager_offset + pager_height, max(0, len(message.lines) - pager_height))
814 |
815 |
816 | def cmd_load_tab(app: AppState, tab: int) -> None:
817 | if group := list_get(GROUP_TABS, tab - 1):
818 | app_load_group(app, group)
819 |
820 |
821 | def cmd_reload_page(app: AppState) -> None:
822 | app_load_group(app, app.group)
823 |
824 |
825 | def cmd_load_prev_page(app: AppState) -> None:
826 | app_load_group(app, group_advance_page(app.group, -1))
827 |
828 |
829 | def cmd_load_next_page(app: AppState) -> None:
830 | app_load_group(app, group_advance_page(app.group, 1))
831 |
832 |
833 | def cmd_load_page(app: AppState) -> None:
834 | user_input = app_prompt(app, "Go to page (empty to cancel): ")
835 |
836 | if user_input.isnumeric() and (page := int(user_input)) >= 1:
837 | app_load_group(app, group_set_page(app.group, page))
838 | elif len(user_input) > 0:
839 | app_show_flash(app, "Invalid page number")
840 |
841 |
842 | def cmd_open(app: AppState) -> None:
843 | if (msg := app.selected_message) is None:
844 | return
845 |
846 | if msg.is_thread:
847 | app_open_thread(app, msg)
848 | else:
849 | app_select_message(app, msg, show_pager=True)
850 |
851 |
852 | def cmd_close(app: AppState) -> None:
853 | if app.pager_visible:
854 | app.pager_visible = False
855 | else:
856 | app_close_thread(app)
857 |
858 |
859 | def cmd_star(app: AppState) -> None:
860 | if (msg := app.selected_message) is not None:
861 | msg.flags.starred = not msg.flags.starred
862 | db_save_message(app.db, msg)
863 | cmd_next(app)
864 |
865 |
866 | def cmd_star_thread(app: AppState) -> None:
867 | if (msg := app.selected_message) is None:
868 | return
869 |
870 | if (thread_msg := app.messages_by_id.get(msg.thread_id)) is None:
871 | return
872 |
873 | thread_msg.flags.starred = not thread_msg.flags.starred
874 | db_save_message(app.db, thread_msg)
875 | cmd_next(app)
876 |
877 |
878 | def cmd_set_unread(app: AppState) -> None:
879 | if (msg := app.selected_message) is not None:
880 | msg.flags.read = False
881 | db_save_message(app.db, msg)
882 | cmd_next(app)
883 |
884 |
885 | def cmd_dump(app: AppState) -> None:
886 | if (msg := app.selected_message) is None:
887 | return
888 |
889 | filename = f"{msg.msg_id}.html"
890 |
891 | with open(filename, "w") as fp:
892 | fp.write(msg.body or "")
893 |
894 | app_show_flash(app, f"Message body dumped to {filename}")
895 |
896 |
897 | def cmd_toggle_raw_mode(app: AppState) -> None:
898 | app.raw_mode = not app.raw_mode
899 | app_select_message(app, app.selected_message)
900 |
901 |
902 | def cmd_resize(app: AppState) -> None:
903 | app_refresh_message(app)
904 |
905 |
906 | def cmd_unknown(app: AppState) -> None:
907 | app.flash = "Unknown key"
908 |
909 |
910 | def db_init(path: str) -> DB:
911 | path = os.path.expanduser(path)
912 | create_table_sql = """
913 | CREATE TABLE IF NOT EXISTS messages (
914 | msg_id TEXT NOT NULL PRIMARY KEY,
915 | thread_id TEXT NOT NULL,
916 | date INTEGER NOT NULL,
917 | flags JSON NOT NULL
918 | );
919 |
920 | CREATE INDEX IF NOT EXISTS messages_starred_date ON messages (
921 | JSON_EXTRACT(flags, '$.starred'),
922 | date
923 | );
924 | """
925 |
926 | db = sqlite3.connect(path)
927 | db.row_factory = sqlite3.Row
928 | db.executescript(create_table_sql)
929 | db.commit()
930 |
931 | return cast(DB, db)
932 |
933 |
934 | def db_save_message(db: DB, message: Message) -> None:
935 | sql = """INSERT OR REPLACE INTO messages (msg_id, thread_id, date, flags) VALUES (?, ?, ?, ?)"""
936 | date = int(message.date.timestamp())
937 | flags_json = json.dumps(dataclasses.asdict(message.flags))
938 | db.execute(sql, (message.msg_id, message.thread_id, date, flags_json))
939 | db.commit()
940 |
941 |
942 | def db_load_message_flags(db: DB, messages_by_id: dict[str, Message]) -> None:
943 | message_ids = list(messages_by_id.keys())
944 | sql = f"SELECT * FROM messages WHERE msg_id IN ({','.join('?' for _ in message_ids)})"
945 |
946 | for row in db.execute(sql, message_ids):
947 | flags = json.loads(row["flags"])
948 | messages_by_id[row["msg_id"]].flags = MessageFlags(**flags)
949 |
950 |
951 | def db_load_read_comments(db: DB, messages_by_id: dict[str, Message]) -> None:
952 | threads_by_id = {msg.msg_id: msg for msg in messages_by_id.values() if msg.is_thread}
953 | thread_ids = list(threads_by_id.keys())
954 |
955 | sql = f"""
956 | SELECT thread_id, COUNT(*) AS count
957 | FROM messages
958 | WHERE thread_id IN ({','.join('?' for _ in thread_ids)}) AND JSON_EXTRACT(flags, '$.read')
959 | GROUP BY thread_id
960 | """
961 |
962 | for row in db.execute(sql, thread_ids):
963 | threads_by_id[row["thread_id"]].read_comments = row["count"]
964 |
965 |
966 | def db_load_starred_thread_ids(db: DB, page: int = 1) -> list[str]:
967 | page_size = 30
968 | offset = (page - 1) * page_size
969 | sql = """
970 | SELECT thread_id
971 | FROM messages
972 | WHERE JSON_EXTRACT(flags, '$.starred')
973 | GROUP BY thread_id
974 | ORDER BY date DESC
975 | LIMIT ?
976 | OFFSET ?
977 | """
978 |
979 | return [row["thread_id"] for row in db.execute(sql, (page_size, offset))]
980 |
981 |
982 | def msg_flatten_thread(
983 | msg: Message, prefix: str = "", is_last_child: bool = False, ascii: bool = False
984 | ) -> Generator[Message, None, None]:
985 | blcorner = "'-" if ascii else "└─"
986 | ltee = "|-" if ascii else "├─"
987 | vline = "| " if ascii else "│ "
988 |
989 | msg.index_tree = "" if msg.is_thread else f"{prefix}{blcorner if is_last_child else ltee}> "
990 | yield msg
991 |
992 | children = msg.children or []
993 |
994 | child_count = len(children)
995 | child_prefix = "" if msg.is_thread else f"{prefix}{' ' if is_last_child else vline}"
996 |
997 | for i, child_node in enumerate(children):
998 | child_is_last = i == child_count - 1
999 | for child in msg_flatten_thread(child_node, prefix=child_prefix, is_last_child=child_is_last, ascii=ascii):
1000 | yield child
1001 |
1002 |
1003 | def msg_build_raw_lines(msg: Message) -> list[str]:
1004 | text = text_sanitize(msg.body)
1005 |
1006 | # Unescape selected entities for better readability
1007 | repl = {"/": "/", "'": "'", """: '"'}
1008 | for k, v in repl.items():
1009 | text = text.replace(k, v)
1010 |
1011 | return reduce(lambda acc, line: acc + wrap(line, width=120, replace_whitespace=False), text.split("\n"), [])
1012 |
1013 |
1014 | def msg_build_lines(msg: Message) -> list[str]:
1015 | lines = [
1016 | f"Content-Location: {msg.content_location}",
1017 | f"Date: {msg.date.strftime('%Y-%m-%d %H:%M')}",
1018 | f"From: {msg.author or '
5 | Lorem ipsum dolor sit amet, pro eu soleat civibus. Mel quas sensibus te. Noster nominati recteque no has. def hello():
2 | print('Hello World')
3 | return None
4 |
def hello():
6 | print('Hello World')
7 | return None
8 |
9 | Lorem ipsum dolor sit amet, pro eu soleat civibus. Mel quas sensibus te. Noster nominati recteque no has.
10 |
--------------------------------------------------------------------------------
/tests/test_hn_05.out:
--------------------------------------------------------------------------------
1 | Lorem ipsum dolor sit amet, pro eu soleat civibus. Mel quas sensibus
2 | te. Noster nominati recteque no has.
3 |
4 | | def hello():
5 | | print('Hello World')
6 | | return None
7 |
8 | Lorem ipsum dolor sit amet, pro eu soleat civibus. Mel quas sensibus
9 | te. Noster nominati recteque no has.
10 |
11 | | def hello():
12 | | print('Hello World')
13 | | return None
14 |
15 | Lorem ipsum dolor sit amet, pro eu soleat civibus. Mel quas sensibus
16 | te. Noster nominati recteque no has.
--------------------------------------------------------------------------------
/tests/test_hn_06.html:
--------------------------------------------------------------------------------
1 | Lorem ipsum dolor sit amet, pro eu soleat civibus.
lambda L: [] if L==[] else qsort([x for x in L[1:] if x< L[0]]) + L[0:1] + qsort([x for x in L[1:] if x>=L[0]])
2 |
Mel quas sensibus te. Noster nominati recteque no has.
3 |
--------------------------------------------------------------------------------
/tests/test_hn_06.out:
--------------------------------------------------------------------------------
1 | Lorem ipsum dolor sit amet, pro eu soleat civibus.
2 |
3 | | lambda L: [] if L==[] else qsort([x for x in L[1:] if x< L[0]]) + L[0:1] + qsort([x for x in L[1:] if x>=L[0]])
4 |
5 | Mel quas sensibus te. Noster nominati recteque no has.
--------------------------------------------------------------------------------
/tests/test_lb_01.html:
--------------------------------------------------------------------------------
1 | 2 |4 |Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
3 |
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
5 |Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
6 |7 |9 |Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
8 |
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
10 | -------------------------------------------------------------------------------- /tests/test_lb_01.out: -------------------------------------------------------------------------------- 1 | > Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do 2 | > eiusmod tempor 3 | 4 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do 5 | eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing 6 | elit, sed do eiusmod tempor. Lorem ipsum dolor sit amet, consectetur 7 | adipiscing elit, sed do eiusmod tempor 8 | 9 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do 10 | eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing 11 | elit, sed do eiusmod tempor. Lorem ipsum dolor sit amet, consectetur 12 | adipiscing elit, sed do eiusmod tempor 13 | 14 | > Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do 15 | > eiusmod tempor 16 | 17 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do 18 | eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing 19 | elit, sed do eiusmod tempor. Lorem ipsum dolor sit amet, consectetur 20 | adipiscing elit, sed do eiusmod tempor -------------------------------------------------------------------------------- /tests/test_lb_02.html: -------------------------------------------------------------------------------- 1 |2 |4 |Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
3 |
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor. Lorem ipsum
dolor sit amet, consectetur adipiscing
elit, sed do eiusmod tempor
def hello_world():
6 | print('hello')
7 | if True:
8 | print('world')
9 | print('!!!')
10 |
11 | hello_world()
12 |
13 |
--------------------------------------------------------------------------------
/tests/test_lb_02.out:
--------------------------------------------------------------------------------
1 | > Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
2 | > eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing
3 | > elit, sed do eiusmod tempor. Lorem ipsum dolor sit amet, consectetur
4 | > adipiscing elit, sed do eiusmod tempor
5 |
6 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
7 | eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing
8 | elit, sed do eiusmod tempor. Lorem `ipsum` dolor sit amet,
9 | `consectetur adipiscing` elit, sed do eiusmod tempor
10 |
11 | | def hello_world():
12 | | print('hello')
13 | | if True:
14 | | print('world')
15 | | print('!!!')
16 | |
17 | | hello_world()
--------------------------------------------------------------------------------
/tests/test_lb_03.html:
--------------------------------------------------------------------------------
1 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
2 |Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
13 | -------------------------------------------------------------------------------- /tests/test_lb_03.out: -------------------------------------------------------------------------------- 1 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do 2 | eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing 3 | elit, sed do eiusmod tempor. Lorem ipsum dolor sit amet, consectetur 4 | adipiscing elit, sed do eiusmod tempor 5 | 6 | - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do 7 | eiusmod tempor. 8 | - Lorem: 9 | 10 | - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do 11 | eiusmod tempor. 12 | - Lorem ipsum dolor sit amet, consectetur. 13 | - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do 14 | eiusmod tempor. 15 | 16 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do 17 | eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing 18 | elit, sed do eiusmod tempor. Lorem ipsum dolor sit amet, consectetur 19 | adipiscing elit, sed do eiusmod tempor -------------------------------------------------------------------------------- /tests/test_lb_04.html: -------------------------------------------------------------------------------- 1 |Lorem ipsum dolor sit amet, consectetur adipiscing elit
2 |3 |18 |Lorem ipsum dolor sit amet, consectetur adipiscing elit, example sed do eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor. Lorem ipsum dolor sit amet, consectetur
4 |adipiscing elit
, sed do eiusmod tempor5 |16 |6 | Lorem ipsum dolor sit
13 |
dolor amet, consectetur 7 | 8 | adipiscing 9 | 10 | 11 | elit 12 |
14 |Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
15 |Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
17 |
Lorem ipsum dolor sit amet, consectetur adipiscing elit
-------------------------------------------------------------------------------- /tests/test_lb_04.out: -------------------------------------------------------------------------------- 1 | Lorem ipsum dolor sit amet, consectetur adipiscing elit 2 | 3 | > Lorem ipsum dolor sit amet, consectetur adipiscing elit, example 4 | > https://example.com/ sed do eiusmod tempor. Lorem ipsum dolor sit 5 | > amet, consectetur adipiscing elit, sed do eiusmod tempor. Lorem 6 | > ipsum dolor sit amet, consectetur `adipiscing elit`, sed do eiusmod 7 | > tempor 8 | > 9 | >> Lorem ipsum /dolor/ *sit 10 | >> dolor* amet, consectetur adipiscing elit 11 | >> 12 | >> ------------------------------------------------------------------ 13 | >> 14 | >> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do 15 | >> eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing 16 | >> elit, sed do eiusmod tempor. Lorem ipsum dolor sit amet, 17 | >> consectetur adipiscing elit, sed do eiusmod tempor 18 | > 19 | > Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do 20 | > eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing 21 | > elit, sed do eiusmod tempor. Lorem ipsum dolor sit amet, consectetur 22 | > adipiscing elit, sed do eiusmod tempor 23 | 24 | Lorem ipsum dolor sit amet, consectetur adipiscing elit -------------------------------------------------------------------------------- /tests/test_lb_05.html: -------------------------------------------------------------------------------- 1 |Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
2 |Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
4 |Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
5 |Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
7 | -------------------------------------------------------------------------------- /tests/test_lb_05.out: -------------------------------------------------------------------------------- 1 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do 2 | eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing 3 | elit, sed do eiusmod tempor. Lorem ipsum dolor sit amet, consectetur 4 | adipiscing elit, sed do eiusmod tempor 5 | 6 | ---------------------------------------------------------------------- 7 | 8 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do 9 | eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing 10 | elit, sed do eiusmod tempor. Lorem ipsum dolor sit amet, consectetur 11 | adipiscing elit, sed do eiusmod tempor 12 | 13 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do 14 | eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing 15 | elit, sed do eiusmod tempor. Lorem ipsum dolor sit amet, consectetur 16 | adipiscing elit, sed do eiusmod tempor 17 | 18 | ---------------------------------------------------------------------- 19 | 20 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do 21 | eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing 22 | elit, sed do eiusmod tempor. Lorem ipsum dolor sit amet, consectetur 23 | adipiscing elit, sed do eiusmod tempor -------------------------------------------------------------------------------- /tests/test_lb_06.html: -------------------------------------------------------------------------------- 1 |2 |4 |Lorem ipsum dolor sit amet, consectetur adipiscing elit
3 |
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
5 |6 |8 |Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
7 |
Lorem ipsum dolor sit amet, consectetur adipiscing elit
9 |10 |16 |11 |
15 |- Lorem ipsum dolor sit amet, consectetur adipiscing elit
12 |- Lorem ipsum dolor sit amet, consectetur adipiscing elit
13 |- Lorem ipsum dolor sit amet, consectetur adipiscing elit
14 |
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
17 | -------------------------------------------------------------------------------- /tests/test_lb_06.out: -------------------------------------------------------------------------------- 1 | > Lorem ipsum dolor sit amet, consectetur adipiscing elit 2 | 3 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do 4 | eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing 5 | elit, sed do eiusmod tempor. Lorem ipsum dolor sit amet, consectetur 6 | adipiscing elit, sed do eiusmod tempor 7 | 8 | > Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do 9 | > eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing 10 | > elit, sed do eiusmod tempor. Lorem ipsum dolor sit amet, consectetur 11 | > adipiscing elit, sed do eiusmod tempor 12 | 13 | Lorem ipsum dolor sit amet, consectetur adipiscing elit 14 | 15 | > - Lorem ipsum dolor sit amet, consectetur adipiscing elit 16 | > - Lorem ipsum dolor sit amet, consectetur adipiscing elit 17 | > - Lorem ipsum dolor sit amet, consectetur adipiscing elit 18 | 19 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do 20 | eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing 21 | elit, sed do eiusmod tempor. Lorem ipsum dolor sit amet, consectetur 22 | adipiscing elit, sed do eiusmod tempor -------------------------------------------------------------------------------- /tests/test_lb_07.html: -------------------------------------------------------------------------------- 1 |Lorem ipsum dolor sit amet, consectetur adipiscing elit
2 |Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
5 |Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
8 |Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
11 |Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
14 | -------------------------------------------------------------------------------- /tests/test_lb_07.out: -------------------------------------------------------------------------------- 1 | Lorem ipsum dolor sit amet, consectetur adipiscing elit 2 | 3 | - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do 4 | eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing 5 | elit, sed do eiusmod tempor. Lorem ipsum dolor sit amet, consectetur 6 | adipiscing elit, sed do eiusmod tempor 7 | - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do 8 | eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing 9 | elit, sed do eiusmod tempor. Lorem ipsum dolor sit amet, consectetur 10 | adipiscing elit, sed do eiusmod tempor 11 | - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do 12 | eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing 13 | elit, sed do eiusmod tempor. Lorem ipsum dolor sit amet, consectetur 14 | adipiscing elit, sed do eiusmod tempor 15 | 16 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do 17 | eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing 18 | elit, sed do eiusmod tempor. Lorem ipsum dolor sit amet, consectetur 19 | adipiscing elit, sed do eiusmod tempor -------------------------------------------------------------------------------- /tests/test_lb_08.html: -------------------------------------------------------------------------------- 1 |Lorem ipsum dolor sit amet, consectetur adipiscing elit
2 |3 |11 |4 |10 |5 |
9 |- Lorem ipsum dolor sit amet, consectetur adipiscing elit
6 |- Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
7 |- Lorem ipsum dolor sit amet, consectetur adipiscing elit
8 |
12 |15 |Lorem ipsum dolor sit amet, consectetur adipiscing elit
13 |Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
14 |
Lorem ipsum dolor sit amet, consectetur adipiscing elit
16 | -------------------------------------------------------------------------------- /tests/test_lb_08.out: -------------------------------------------------------------------------------- 1 | Lorem ipsum dolor sit amet, consectetur adipiscing elit 2 | 3 | >> - Lorem ipsum dolor sit amet, consectetur adipiscing elit 4 | >> - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do 5 | >> eiusmod tempor. Lorem ipsum dolor sit amet, consectetur 6 | >> adipiscing elit, sed do eiusmod tempor. Lorem ipsum dolor sit 7 | >> amet, consectetur adipiscing elit, sed do eiusmod tempor 8 | >> - Lorem ipsum dolor sit amet, consectetur adipiscing elit 9 | 10 | > Lorem ipsum dolor sit amet, consectetur adipiscing elit 11 | > 12 | > Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do 13 | > eiusmod tempor. Lorem ipsum dolor sit amet, consectetur adipiscing 14 | > elit, sed do eiusmod tempor. Lorem ipsum dolor sit amet, consectetur 15 | > adipiscing elit, sed do eiusmod tempor 16 | 17 | Lorem ipsum dolor sit amet, consectetur adipiscing elit -------------------------------------------------------------------------------- /tests/test_lb_09.html: -------------------------------------------------------------------------------- 1 |2 |4 |Lorem ipsum dolor sit amet, consectetur adipiscing elit
3 |
5 |15 |Lorem ipsum dolor sit amet, consectetur adipiscing elit
6 |14 |def hello_world(): 7 | print('hello') 8 | if True: 9 | print('world') 10 | print('!!!') 11 | 12 | hello_world() 13 |
Lorem ipsum dolor sit amet, consectetur adipiscing elit
16 |def hello_world():
17 | print('hello')
18 | if True:
19 | print('world')
20 | print('!!!')
21 |
22 | hello_world()
23 |
24 | Lorem ipsum dolor sit amet, consectetur adipiscing elit
25 | -------------------------------------------------------------------------------- /tests/test_lb_09.out: -------------------------------------------------------------------------------- 1 | > Lorem ipsum dolor sit amet, consectetur adipiscing elit 2 | 3 | > Lorem ipsum dolor sit amet, consectetur adipiscing elit 4 | > 5 | > | def hello_world(): 6 | > | print('hello') 7 | > | if True: 8 | > | print('world') 9 | > | print('!!!') 10 | > | 11 | > | hello_world() 12 | 13 | Lorem ipsum dolor sit amet, consectetur adipiscing elit 14 | 15 | | def hello_world(): 16 | | print('hello') 17 | | if True: 18 | | print('world') 19 | | print('!!!') 20 | | 21 | | hello_world() 22 | 23 | Lorem ipsum dolor sit amet, consectetur adipiscing elit --------------------------------------------------------------------------------