Skip to content

Commit 0cc3888

Browse files
committed
ui: Make ZT go to into autohide mode if terminal is small.
This commit makes ZT go into autohide mode when terminal width is smaller than MINNORMALWIDTH. This makes the ZT more readable in a small terminal. To do so this makes use of urwid's render method to get maxcols, a Literal `self.mode` which takes values "small", "normal" and "wide" and existing `show_left_panel` and `show_right_panel` methods with small changes.
1 parent dd08598 commit 0cc3888

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

zulipterminal/ui.py

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from typing import Any, List, Optional
66

77
import urwid
8+
from typing_extensions import Literal
89

910
from zulipterminal.config.keys import commands_for_random_tips, is_command_key
1011
from zulipterminal.config.symbols import (
@@ -21,6 +22,9 @@
2122
from zulipterminal.urwid_types import urwid_Box
2223

2324

25+
MINNORMALWIDTH = 103
26+
27+
2428
class View(urwid.WidgetWrap):
2529
"""
2630
A class responsible for providing the application's interface.
@@ -42,6 +46,7 @@ def __init__(self, controller: Any) -> None:
4246

4347
self.message_view: Any = None
4448
self.displaying_selection_hint = False
49+
self.mode: Literal["small", "normal", "wide"] = "normal"
4550

4651
super().__init__(self.main_window())
4752

@@ -176,16 +181,16 @@ def main_window(self) -> Any:
176181
)
177182
return w
178183

179-
def show_left_panel(self, *, visible: bool) -> None:
180-
if not self.autohide:
184+
def show_left_panel(self, *, visible: bool, ignore_check: bool = False) -> None:
185+
if not self.autohide and self.mode != "small" and not ignore_check:
181186
return
182187
option = ("given", self.LEFT_WIDTH) if visible else ("given", 0)
183188
self.body.contents[0] = (self.left_panel, self.body.options(*option))
184189
if visible:
185190
self.body.focus_position = 0
186191

187-
def show_right_panel(self, *, visible: bool) -> None:
188-
if not self.autohide:
192+
def show_right_panel(self, *, visible: bool, ignore_check: bool = False) -> None:
193+
if not self.autohide and self.mode != "small" and not ignore_check:
189194
return
190195
option = ("given", self.RIGHT_WIDTH) if visible else ("given", 0)
191196
self.body.contents[2] = (self.right_panel, self.body.options(*option))
@@ -314,6 +319,25 @@ def mouse_event(
314319

315320
return super().mouse_event(size, event, button, col, row, focus)
316321

322+
def render(self, size: urwid_Box, focus: bool) -> Any:
323+
maxcols, maxrows = size
324+
325+
if not self.autohide:
326+
if maxcols < MINNORMALWIDTH and self.mode != "small":
327+
self.mode = "small"
328+
if self.body.focus_position == 2:
329+
self.show_left_panel(visible=False)
330+
else:
331+
self.show_right_panel(visible=False)
332+
elif maxcols >= MINNORMALWIDTH and self.mode != "normal":
333+
self.mode = "normal"
334+
prev_focus = self.body.focus_position
335+
self.show_right_panel(visible=True, ignore_check=True)
336+
self.show_left_panel(visible=True, ignore_check=True)
337+
self.body.focus_position = prev_focus
338+
339+
return super().render(size, focus)
340+
317341

318342
class Screen(urwid.raw_display.Screen):
319343
def write(self, data: Any) -> None:

0 commit comments

Comments
 (0)