Skip to content

Commit 48a235b

Browse files
committed
__rich_console__ implementation in questionContent and questionInfoTable
1 parent e21e7ca commit 48a235b

File tree

8 files changed

+16
-8
lines changed

8 files changed

+16
-8
lines changed

leetcode/main.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77

88
# the file can be generated when the user displsays the question
99

10-
# TODO: Loading animations where needed
1110
# TODO: handle the wrong cases in the args parser
12-
# TODO: loading ASCII art
1311
# TODO: pipes support
1412
# TODO: add a command to open the question in editor
1513
# TODO: add a command to show the solution in the terminal

leetcode/models/graphql_question_content.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,8 @@ def execute(self):
2020

2121
def show(self):
2222
for x in self.question_panels:
23-
print(x)
23+
print(x)
24+
25+
def __rich_console__(self, console: Console, options):
26+
for x in self.question_panels:
27+
yield x

leetcode/models/graphql_question_info_table.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,7 @@ def format_table(self):
5959

6060
def show(self):
6161
print(self.table)
62+
63+
def __rich_console__(self, console: Console, options):
64+
return self.table.__rich_console__(console, options)
6265

leetcode/models/graphql_question_of_today.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def show(self):
8080
titleSlug = self.result.question.titleSlug
8181
with Loader('Fetching question content...', ''):
8282
question_content = questionContent(titleSlug)
83-
question_content.show()
83+
print(question_content)
8484

8585
elif self.browserFlag:
8686
self.show_info_table()

leetcode/models/problem_by_id_slug.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,6 @@ def execute(self, args):
6363
def show(self):
6464
# TODO: make the __repr__ method for this class
6565
question_info_table = questionInfoTable(self.title_slug)
66-
question_info_table.show()
66+
print(question_info_table)
6767
question_content = questionContent(self.title_slug)
68-
question_content.show()
68+
print(question_content)

leetcode/models/styles.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import rich
22
from rich import print
33
from rich.align import VerticalAlignMethod
4-
from rich.console import JustifyMethod, OverflowMethod, RenderableType
4+
from rich.console import Console, ConsoleOptions, JustifyMethod, OverflowMethod, RenderResult, RenderableType
55
from rich.style import Style, StyleType
66
from rich.table import Table
77
from rich.text import Text
@@ -54,6 +54,7 @@ def add_row(self, *renderables: RenderableType | None, style: StyleType | None =
5454
renderables[self.status_column_index] = status_retranslate[renderables[self.status_column_index]]
5555
renderables = tuple(renderables)
5656
return super().add_row(*renderables, style=style, end_section=end_section)
57+
5758

5859
class CustomBar(Bar):
5960
BEGIN_BLOCK_ELEMENTS = ["█", "█", "█", "▐", "▐", "▐", "▕", "▕"]

leetcode/models/submit.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ def execute(self, args):
4646
except Exception as e:
4747
console.print(f"{e.__class__.__name__}: {e}", style=ALERT)
4848

49-
# TODO: inform about the file not found
5049
def load_code(self, filename):
5150
with open(filename, 'r') as file:
5251
code = file.read()

solution.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Solution:
2+
def sum(self, num1: int, num2: int) -> int:
3+
return num1 + num2

0 commit comments

Comments
 (0)