From 7f5c201925346a434ef8a580bbba53e5c86236df Mon Sep 17 00:00:00 2001 From: Derek Schmidt Date: Fri, 1 Mar 2019 14:17:58 -0700 Subject: [PATCH] Minor compose window cleanup / misc fixes + Remove excess padding on width + Rename TextModal to EntryModal + Remove duplicate delete key handler + Redraw when CW modal closes + Return empty string rather than None --- toot/ui/app.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/toot/ui/app.py b/toot/ui/app.py index 1060098..c18beba 100644 --- a/toot/ui/app.py +++ b/toot/ui/app.py @@ -318,7 +318,7 @@ class HelpModal(Modal): ] -class TextModal(Modal): +class EntryModal(Modal): def __init__(self, stdscr, title, footer=None, size=(None, None)): self.content = [] self.cursor_pos = 0 @@ -333,8 +333,8 @@ class TextModal(Modal): height, width, y, x = self.get_size_pos(stdscr) self.window = curses.newwin(height, width, y, x) - self.text_window = self.window.derwin(height - (self.pad_y * 2), width - (self.pad_x * 2 + 1), self.pad_y, self.pad_x) - self.text_window.keypad(1) + self.text_window = self.window.derwin(height - (self.pad_y * 2), width - (self.pad_x * 2), self.pad_y, self.pad_x) + self.text_window.keypad(True) self.draw() self.panel = curses.panel.new_panel(self.window) @@ -347,7 +347,7 @@ class TextModal(Modal): else: height = int(screen_height / 1.33) if self.size[1]: - width = self.size[1] + (self.pad_x * 2 + 1) + 1 + width = self.size[1] + (self.pad_x * 2) + 1 else: width = int(screen_width / 1.25) @@ -391,11 +391,6 @@ class TextModal(Modal): if self.cursor_pos >= 0 and self.cursor_pos < len(self.content): del self.content[self.cursor_pos] - elif ch == curses.KEY_DC: - if self.cursor_pos > 0 and self.cursor_pos <= len(self.content): - del self.content[self.cursor_pos - 1] - self.cursor_pos -= 1 - elif ch == curses.KEY_LEFT: if self.cursor_pos > 0: self.cursor_pos -= 1 @@ -423,18 +418,19 @@ class TextModal(Modal): if not self.do_command(ch): break self.hide() - return ''.join(self.content) if len(self.content) > 0 else None + return ''.join(self.content) -class ComposeModal(TextModal): +class ComposeModal(EntryModal): def __init__(self, stdscr): super().__init__(stdscr, title="Compose a toot", footer="^G to submit, ^Q to quit, ^S to mark sensitive (cw)") self.cw = None - self.cwmodal = TextModal(stdscr, title="Content warning", size=(1, 60)) + self.cwmodal = EntryModal(stdscr, title="Content warning", size=(1, 60)) def do_command(self, ch): if ch == curses.ascii.ctrl(ord('s')): - self.cw = self.cwmodal.loop() + self.cw = self.cwmodal.loop() or None + self.draw() return True else: return super().do_command(ch)