Merge pull request #287 from pdxlocations:display-bug

Clear stale reply context in draw_text_field function and add corresponding test
This commit is contained in:
pdxlocations
2026-07-24 15:25:38 -07:00
committed by GitHub
2 changed files with 17 additions and 4 deletions
+8 -4
View File
@@ -1675,21 +1675,25 @@ def remove_notification(channel_number: int) -> None:
def draw_text_field(win: curses.window, text: str, color: int) -> None:
win.border()
height, width = win.getmaxyx()
# Put a small hint in the border of the message entry field.
# We key off the "Message:" prompt to avoid affecting other bordered fields.
if isinstance(text, str) and text.startswith("Message:"):
hint = " Ctrl+K Help "
h, w = win.getmaxyx()
x = max(2, w - len(hint) - 2)
x = max(2, width - len(hint) - 2)
try:
win.addstr(0, x, hint, get_color("commands"))
except curses.error:
pass
# Draw the actual field text
# Clear the row before redrawing. Reply context can be longer than the
# next value (or empty after Ctrl+R cancels it), so simply overwriting the
# new text leaves trailing characters from the old context on screen.
try:
win.addstr(1, 1, text, color)
if height > 2 and width > 2:
win.addstr(1, 1, " " * (width - 2), color)
win.addstr(1, 1, text[: max(0, width - 2)], color)
except curses.error:
pass
+9
View File
@@ -152,6 +152,15 @@ class ContactUiTests(unittest.TestCase):
self.assertEqual(ui_state.reply_context, "")
self.assertFalse(ui_state.reply_id_unavailable)
def test_draw_text_field_clears_stale_reply_context(self) -> None:
win = mock.Mock()
win.getmaxyx.return_value = (3, 30)
contact_ui.draw_text_field(win, "Message: ", 1)
self.assertIn(mock.call(1, 1, " " * 28, 1), win.addstr.call_args_list)
self.assertIn(mock.call(1, 1, "Message: ", 1), win.addstr.call_args_list)
def test_handle_ctrl_r_shows_context_when_message_id_is_unavailable(self) -> None:
ui_state.current_window = 1
ui_state.channel_list = ["Primary"]