Skip to content

Commit 3a02044

Browse files
committed
shutdown procedure, better scrollbars when window is small
1 parent fcf1655 commit 3a02044

File tree

4 files changed

+29
-26
lines changed

4 files changed

+29
-26
lines changed

src/textual/_linux_driver.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,20 +140,23 @@ def _patch_iflag(cls, attrs: int) -> int:
140140
)
141141

142142
def stop_application_mode(self) -> None:
143-
signal.signal(signal.SIGWINCH, signal.SIG_DFL)
143+
log.debug("stop_application_mode()")
144144

145-
self.console.set_alt_screen(False)
146-
self.console.show_cursor(True)
145+
signal.signal(signal.SIGWINCH, signal.SIG_DFL)
147146

147+
self._disable_mouse_support()
148148
self.exit_event.set()
149-
# if self._key_thread is not None:
150-
# self._key_thread.join()
149+
if self._key_thread is not None:
150+
self._key_thread.join()
151+
151152
if self.attrs_before is not None:
152153
try:
153154
termios.tcsetattr(self.fileno, termios.TCSANOW, self.attrs_before)
154155
except termios.error:
155156
pass
156-
self._disable_mouse_support()
157+
158+
self.console.set_alt_screen(False)
159+
self.console.show_cursor(True)
157160

158161
def run_input_thread(self, loop) -> None:
159162
try:

src/textual/_xterm_parser.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ def parse(self, on_token: TokenCallback) -> Generator[Awaitable, str, None]:
6969
sequence: str = character
7070
while True:
7171
sequence += yield read1()
72+
log.debug(f"sequence={sequence!r}")
7273
keys = get_ansi_sequence(sequence, None)
7374
if keys is not None:
7475
for key in keys:

src/textual/app.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@
4242
uvloop.install()
4343

4444

45+
class ShutdownError(Exception):
46+
pass
47+
48+
4549
@rich_repr
4650
class App(MessagePump):
4751
view: View
@@ -108,7 +112,6 @@ async def _process_messages(self) -> None:
108112
log.exception("error starting application mode")
109113
raise
110114
try:
111-
# self.refresh()
112115
await super().process_messages()
113116
finally:
114117
try:
@@ -125,8 +128,8 @@ async def close_all() -> None:
125128

126129
try:
127130
await asyncio.wait_for(close_all(), timeout=5)
128-
except asyncio.TimeoutError:
129-
raise
131+
except asyncio.TimeoutError as error:
132+
raise ShutdownError("Timeout closing messages pump(s)") from None
130133

131134
self.children.clear()
132135

src/textual/scrollbar.py

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def render_bar(
8181
if ascii_only:
8282
bars = ["|", "|", "|", "|", "|", "|", "|", "|", "|"]
8383
else:
84-
bars = [" ", "▁", "▂", "▃", "▄", "▅", "▆", "▇", "█"]
84+
bars = ["▁", "▂", "▃", "▄", "▅", "▆", "▇", "█"]
8585

8686
back = Color.parse(back_color)
8787
bar = Color.parse(bar_color)
@@ -94,27 +94,23 @@ def render_bar(
9494
step_size = virtual_size / size
9595

9696
start = int(position / step_size * 8)
97-
end = start + int(window_size / step_size * 8)
97+
end = start + max(8, int(window_size / step_size * 8))
9898

9999
start_index, start_bar = divmod(start, 8)
100100
end_index, end_bar = divmod(end, 8)
101101

102-
if window_size / step_size <= 1:
103-
if start_index < len(segments):
104-
segments[start_index] = _Segment(blank, _Style(bgcolor=bar))
105-
else:
106-
segments[start_index:end_index] = [_Segment(blank, _Style(bgcolor=bar))] * (
107-
end_index - start_index
108-
)
102+
segments[start_index:end_index] = [_Segment(blank, _Style(bgcolor=bar))] * (
103+
end_index - start_index
104+
)
109105

110-
if start_index < len(segments):
111-
segments[start_index] = _Segment(
112-
bars[7 - start_bar] * depth, _Style(bgcolor=back, color=bar)
113-
)
114-
if end_index < len(segments):
115-
segments[end_index] = _Segment(
116-
bars[7 - end_bar] * depth, _Style(color=back, bgcolor=bar)
117-
)
106+
if start_index < len(segments):
107+
segments[start_index] = _Segment(
108+
bars[7 - start_bar] * depth, _Style(bgcolor=back, color=bar)
109+
)
110+
if end_index < len(segments):
111+
segments[end_index] = _Segment(
112+
bars[7 - end_bar] * depth, _Style(color=back, bgcolor=bar)
113+
)
118114

119115
return segments
120116

0 commit comments

Comments
 (0)