|
1 | | -import requests |
2 | | -import html |
3 | 1 | from termcolor import colored |
| 2 | +import requests |
4 | 3 | from rich.console import Console |
5 | | -from rich.markdown import Markdown |
6 | 4 | import sys as sys |
7 | 5 |
|
8 | | -# the rich console |
9 | | -console = Console() |
10 | | - |
11 | | -# render markdown text in the terminal |
12 | | -# def print_markdown(markdown): |
13 | | -# md = Markdown(markdown) |
14 | | -# console.print(md) |
15 | | - |
16 | | - |
17 | | -class MarkdownRenderer(object): |
18 | | - def __init__(self, markdown_text, console_print=True): |
19 | | - assert isinstance(markdown_text, str), "Expected a string" |
20 | | - |
21 | | - markdown_text = html.unescape(markdown_text) |
22 | | - self.markdown_text = markdown_text |
23 | | - self.do_console_print = bool(console_print) |
24 | | - |
25 | | - self.console = Console() # rich console |
26 | | - |
27 | | - self.render = self.print_mark_down_text() |
28 | | - |
29 | | - def print_mark_down_text(self): |
30 | | - rendered_markdown = Markdown(self.markdown_text) |
31 | | - |
32 | | - if self.do_console_print: |
33 | | - self.console.print(rendered_markdown) |
34 | | - |
35 | | - return rendered_markdown |
36 | | - |
37 | | - def __repr__(self): |
38 | | - return str(self.render) |
39 | | - |
40 | | - |
41 | | -class SearchError(): |
42 | | - def __init__(self, error_statement, suggestion="Try again"): |
43 | | - # the error statement |
44 | | - self.error_statement = error_statement |
45 | | - |
46 | | - # the suggestion statement |
47 | | - self.suggestion = suggestion |
48 | | - |
49 | | - self.evoke_search_error(self.error_statement) |
50 | | - |
51 | | - def evoke_search_error(self, error_statement): |
52 | | - print_text = [ |
53 | | - colored(error_statement, 'red'), |
54 | | - colored(self.suggestion, 'green') |
55 | | - ] |
56 | | - for text_to_print in print_text: |
57 | | - print(text_to_print) |
| 6 | +from .error import SearchError |
| 7 | +from .markdown import MarkdownRenderer |
58 | 8 |
|
| 9 | +console = Console() |
59 | 10 |
|
60 | 11 | class Utility(): |
61 | 12 | def __init__(self): |
|
0 commit comments