Skip to content

Commit 0f1ce53

Browse files
committed
Some simplifications
1 parent 1fdbeda commit 0f1ce53

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

curtsies/formatstring.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,6 @@ def parse_args(
839839
for arg in args:
840840
if not isinstance(arg, str):
841841
raise ValueError(f"args must be strings: {arg!r}")
842-
arg = cast(str, arg)
843842
if arg.lower() in FG_COLORS:
844843
if "fg" in kwargs:
845844
raise ValueError("fg specified twice")
@@ -878,11 +877,9 @@ def fmtstr(string: Union[str, FmtStr], *args: Any, **kwargs: Any) -> FmtStr:
878877
on_red(bold(blue('blarg')))
879878
"""
880879
atts = parse_args(args, kwargs)
881-
if isinstance(string, FmtStr):
882-
pass
883-
elif isinstance(string, str):
880+
if isinstance(string, str):
884881
string = FmtStr.from_str(string)
885-
else:
882+
elif not isinstance(string, FmtStr):
886883
raise ValueError(
887884
f"Bad Args: {string!r} (of type {type(string)}), {args!r}, {kwargs!r}"
888885
)

curtsies/window.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
Optional,
88
IO,
99
Dict,
10+
Sequence,
1011
TypeVar,
1112
Type,
1213
Tuple,
@@ -197,12 +198,9 @@ def render_to_terminal(
197198
self.on_terminal_size_change(height, width)
198199

199200
current_lines_by_row: Dict[int, Optional[FmtStr]] = {}
200-
rows = list(range(height))
201-
rows_for_use = rows[: len(array)]
202-
rest_of_rows = rows[len(array) :]
203201

204202
# rows which we have content for and don't require scrolling
205-
for row, line in zip(rows_for_use, array):
203+
for row, line in enumerate(array):
206204
current_lines_by_row[row] = line
207205
if line == self._last_lines_by_row.get(row, None):
208206
continue
@@ -212,7 +210,7 @@ def render_to_terminal(
212210
self.write(self.t.clear_eol)
213211

214212
# rows onscreen that we don't have content for
215-
for row in rest_of_rows:
213+
for row in range(len(array), height):
216214
if self._last_lines_by_row and row not in self._last_lines_by_row:
217215
continue
218216
self.write(self.t.move(row, 0))
@@ -421,7 +419,9 @@ def _get_cursor_vertical_diff_once(self) -> int:
421419
return cursor_dy
422420

423421
def render_to_terminal(
424-
self, array: Union[FSArray, List[FmtStr]], cursor_pos: Tuple[int, int] = (0, 0)
422+
self,
423+
array: Union[FSArray, Sequence[FmtStr]],
424+
cursor_pos: Tuple[int, int] = (0, 0),
425425
) -> int:
426426
"""Renders array to terminal, returns the number of lines scrolled offscreen
427427

0 commit comments

Comments
 (0)