Skip to content

Commit ec72248

Browse files
committed
ui: Fix total width of columns and add padding for wide terminals.
This commit adds Padding around a fixed total width of 200 of the columns by centering it for wide terminals. The side columns also expand from their min width untill they occupy 200 columns in the ratio 20:60:20.
1 parent 14551c9 commit ec72248

File tree

1 file changed

+44
-9
lines changed

1 file changed

+44
-9
lines changed

zulipterminal/ui.py

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class View(urwid.WidgetWrap):
2828

2929
LEFT_WIDTH = 27
3030
RIGHT_WIDTH = 23
31+
MAX_TOTAL_WIDTH = 200
3132

3233
def __init__(self, controller: Any) -> None:
3334
self.controller = controller
@@ -138,17 +139,20 @@ def main_window(self) -> Any:
138139
if self.controller.autohide:
139140
body = [
140141
(self.LEFT_WIDTH, self.left_panel),
141-
("weight", 10, self.center_panel),
142+
("weight", 80, self.center_panel),
142143
(0, self.right_panel),
143144
]
144145
else:
145146
body = [
146147
(self.LEFT_WIDTH, self.left_panel),
147-
("weight", 10, self.center_panel),
148+
("weight", 60, self.center_panel),
148149
(self.RIGHT_WIDTH, self.right_panel),
149150
]
150151
self.body = urwid.Columns(body, focus_column=0)
151152
self.focus_col = self.body.focus_position
153+
padded_body = urwid.Padding(
154+
self.body, align="center", width=self.MAX_TOTAL_WIDTH
155+
)
152156

153157
# NOTE: message_view is None, but middle_column_view is called above
154158
# and sets it.
@@ -174,22 +178,36 @@ def main_window(self) -> Any:
174178
)
175179

176180
w = urwid.Frame(
177-
self.body, title_bar, focus_part="body", footer=self.footer_view()
181+
padded_body, title_bar, focus_part="body", footer=self.footer_view()
178182
)
179183
return w
180184

181-
def show_left_panel(self, *, visible: bool) -> None:
182-
if not (self.controller.autohide or self.mode == "small"):
185+
def show_left_panel(self, *, visible: bool, ignore_check: bool = False) -> None:
186+
if not (self.autohide or self.mode == "small" or ignore_check):
183187
return
184-
option = ("given", self.LEFT_WIDTH) if visible else ("given", 0)
188+
189+
if visible and self.mode != "wide":
190+
option = ("given", self.LEFT_WIDTH)
191+
elif visible and self.mode == "wide":
192+
option = ("weight", 20)
193+
else:
194+
option = ("given", 0)
195+
185196
self.body.contents[0] = (self.left_panel, self.body.options(*option))
186197
if visible:
187198
self.focus_col = 0
188199

189-
def show_right_panel(self, *, visible: bool) -> None:
190-
if not (self.controller.autohide or self.mode == "small"):
200+
def show_right_panel(self, *, visible: bool, ignore_check: bool = False) -> None:
201+
if not (self.autohide or self.mode == "small" or ignore_check):
191202
return
192-
option = ("given", self.RIGHT_WIDTH) if visible else ("given", 0)
203+
204+
if visible and self.mode != "wide":
205+
option = ("given", self.RIGHT_WIDTH)
206+
elif visible and self.mode == "wide":
207+
option = ("weight", 20)
208+
else:
209+
option = ("given", 0)
210+
193211
self.body.contents[2] = (self.right_panel, self.body.options(*option))
194212
if visible:
195213
self.focus_col = 2
@@ -333,6 +351,23 @@ def render(self, size: urwid_Box, focus: bool) -> Any:
333351
self.focus_col = prev_focus
334352
self.mode = "normal"
335353

354+
def update_column_options() -> None:
355+
if not self.autohide:
356+
self.show_left_panel(visible=True, ignore_check=True)
357+
self.show_right_panel(visible=True, ignore_check=True)
358+
if self.autohide:
359+
if self.focus_col == 0:
360+
self.show_left_panel(visible=True)
361+
elif self.focus_col == 2:
362+
self.show_right_panel(visible=True)
363+
364+
if maxcols > 160 and not self.mode == "wide":
365+
self.mode = "wide"
366+
update_column_options()
367+
elif maxcols < 160 and self.mode == "wide":
368+
self.mode = "normal"
369+
update_column_options()
370+
336371
return super().render(size, focus)
337372

338373

0 commit comments

Comments
 (0)