Skip to content

Commit f612a07

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 until they occupy 200 columns in the ratio 20:60:20.
1 parent 0cc3888 commit f612a07

File tree

1 file changed

+40
-5
lines changed

1 file changed

+40
-5
lines changed

zulipterminal/ui.py

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class View(urwid.WidgetWrap):
3232

3333
LEFT_WIDTH = 27
3434
RIGHT_WIDTH = 23
35+
MAX_TOTAL_WIDTH = 200
3536

3637
def __init__(self, controller: Any) -> None:
3738
self.controller = controller
@@ -142,16 +143,19 @@ def main_window(self) -> Any:
142143
if self.autohide:
143144
body = [
144145
(self.LEFT_WIDTH, self.left_panel),
145-
("weight", 10, self.center_panel),
146+
("weight", 80, self.center_panel),
146147
(0, self.right_panel),
147148
]
148149
else:
149150
body = [
150151
(self.LEFT_WIDTH, self.left_panel),
151-
("weight", 10, self.center_panel),
152+
("weight", 60, self.center_panel),
152153
(self.RIGHT_WIDTH, self.right_panel),
153154
]
154155
self.body = urwid.Columns(body, focus_column=0)
156+
padded_body = urwid.Padding(
157+
self.body, align="center", width=self.MAX_TOTAL_WIDTH
158+
)
155159

156160
# NOTE: message_view is None, but middle_column_view is called above
157161
# and sets it.
@@ -177,22 +181,36 @@ def main_window(self) -> Any:
177181
)
178182

179183
w = urwid.Frame(
180-
self.body, title_bar, focus_part="body", footer=self.footer_view()
184+
padded_body, title_bar, focus_part="body", footer=self.footer_view()
181185
)
182186
return w
183187

184188
def show_left_panel(self, *, visible: bool, ignore_check: bool = False) -> None:
185189
if not self.autohide and self.mode != "small" and not ignore_check:
186190
return
187-
option = ("given", self.LEFT_WIDTH) if visible else ("given", 0)
191+
192+
if visible and self.mode != "wide":
193+
option = ("given", self.LEFT_WIDTH)
194+
elif visible and self.mode == "wide":
195+
option = ("weight", 20)
196+
else:
197+
option = ("given", 0)
198+
188199
self.body.contents[0] = (self.left_panel, self.body.options(*option))
189200
if visible:
190201
self.body.focus_position = 0
191202

192203
def show_right_panel(self, *, visible: bool, ignore_check: bool = False) -> None:
193204
if not self.autohide and self.mode != "small" and not ignore_check:
194205
return
195-
option = ("given", self.RIGHT_WIDTH) if visible else ("given", 0)
206+
207+
if visible and self.mode != "wide":
208+
option = ("given", self.RIGHT_WIDTH)
209+
elif visible and self.mode == "wide":
210+
option = ("weight", 20)
211+
else:
212+
option = ("given", 0)
213+
196214
self.body.contents[2] = (self.right_panel, self.body.options(*option))
197215
if visible:
198216
self.body.focus_position = 2
@@ -336,6 +354,23 @@ def render(self, size: urwid_Box, focus: bool) -> Any:
336354
self.show_left_panel(visible=True, ignore_check=True)
337355
self.body.focus_position = prev_focus
338356

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

341376

0 commit comments

Comments
 (0)