Skip to content

Commit 2d8c5be

Browse files
committed
Moved error and markdown to specific files
1 parent 2f43cef commit 2d8c5be

File tree

4 files changed

+53
-54
lines changed

4 files changed

+53
-54
lines changed

src/arguments/error.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from termcolor import colored
2+
3+
4+
class SearchError():
5+
def __init__(self, error_statement, suggestion="Try again"):
6+
# the error statement
7+
self.error_statement = error_statement
8+
9+
# the suggestion statement
10+
self.suggestion = suggestion
11+
12+
self.evoke_search_error(self.error_statement)
13+
14+
def evoke_search_error(self, error_statement):
15+
print_text = [
16+
colored(error_statement, 'red'),
17+
colored(self.suggestion, 'green')
18+
]
19+
for text_to_print in print_text:
20+
print(text_to_print)

src/arguments/markdown.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from rich.markdown import Markdown
2+
from rich.console import Console
3+
import html as html
4+
5+
class MarkdownRenderer(object):
6+
def __init__(self, markdown_text, console_print=True):
7+
assert isinstance(markdown_text, str), "Expected a string"
8+
9+
markdown_text = html.unescape(markdown_text)
10+
self.markdown_text = markdown_text
11+
self.do_console_print = bool(console_print)
12+
13+
self.console = Console() # rich console
14+
15+
self.render = self.print_mark_down_text()
16+
17+
def print_mark_down_text(self):
18+
rendered_markdown = Markdown(self.markdown_text)
19+
20+
if self.do_console_print:
21+
self.console.print(rendered_markdown)
22+
23+
return rendered_markdown
24+
25+
def __repr__(self):
26+
return str(self.render)

src/arguments/search.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
import argparse
33
import webbrowser
44
from termcolor import colored
5-
from .utility import Utility, SearchError
65
import sys as sys
76

7+
from .error import SearchError
8+
from .utility import Utility
9+
810

911
class Prompt():
1012
def __init__(self, message):

src/arguments/utility.py

Lines changed: 4 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,12 @@
1-
import requests
2-
import html
31
from termcolor import colored
2+
import requests
43
from rich.console import Console
5-
from rich.markdown import Markdown
64
import sys as sys
75

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
588

9+
console = Console()
5910

6011
class Utility():
6112
def __init__(self):

0 commit comments

Comments
 (0)