diff --git a/src/class_mode.py b/src/class_mode.py index 1149137..1d5bc2e 100644 --- a/src/class_mode.py +++ b/src/class_mode.py @@ -14,6 +14,7 @@ class SingleLineMode(Enum): class SingleLineModeImpl: def __init__(self, mode: "SingleLineMode") -> None: self.mode = mode + self.extra_data: str = "" def toggle(self) -> None: if self.mode == SingleLineMode.ON: @@ -38,3 +39,9 @@ def set_off(self) -> None: def set_once(self) -> None: self.mode = SingleLineMode.ONLY_ONCE + + def get_extra_data(self) -> str: + return self.extra_data + + def set_extra_data(self, extra_data: str) -> None: + self.extra_data = extra_data diff --git a/src/class_todo.py b/src/class_todo.py index 990be23..5a38664 100644 --- a/src/class_todo.py +++ b/src/class_todo.py @@ -53,9 +53,10 @@ def __getitem__(self, key: int) -> str: def __len__(self) -> int: return len(self.display_text) - def set_display_text(self, display_text: str) -> None: + def set_display_text(self, display_text: str) -> "Todo": self.display_text = display_text self.text = repr(self) + return self def is_toggled(self) -> bool: if self.box_char is None: diff --git a/src/get_todo.py b/src/get_todo.py index 37aa461..ad6da87 100644 --- a/src/get_todo.py +++ b/src/get_todo.py @@ -306,7 +306,9 @@ def wgetnstr( if position == len(chars): if len(chars) + 1 >= win.getmaxyx()[1] - 1: mode.set_once() - break + display_text, next_line = "".join(chars).rsplit(" ", 1) + mode.set_extra_data(next_line) + return todo.set_display_text(display_text) win.addstr(1, len(chars) + 1, "█") for i, char in enumerate("".join(chars).ljust(win.getmaxyx()[1] - 2)): win.addstr(1, i + 1, char, curses.A_STANDOUT if i == position else 0) @@ -328,5 +330,4 @@ def wgetnstr( return original chars, position = next_step - todo.set_display_text("".join(chars)) - return todo + return todo.set_display_text("".join(chars)) diff --git a/todo.py b/todo.py index 762e226..9b947c2 100755 --- a/todo.py +++ b/todo.py @@ -103,12 +103,13 @@ def insert_todo( stdscr: Any, todos: list[Todo], index: int, + default_todo: Todo = Todo(), mode: SingleLineModeImpl = SingleLineModeImpl(SingleLineMode.NONE), ) -> list[Todo]: todo = wgetnstr( stdscr, get_newwin(stdscr), - todo=Todo(), + todo=default_todo, prev_todo=todos[index - 1] if len(todos) > 0 else Todo(), mode=mode, ) @@ -432,6 +433,7 @@ def new_todo_next( stdscr: Any, todos: list[Todo], selected: int, + default_todo: Todo = Todo(), mode: SingleLineModeImpl = SingleLineModeImpl(SingleLineMode.NONE), ) -> tuple[list[Todo], int]: """ @@ -452,7 +454,8 @@ def new_todo_next( stdscr, todos, selected + 1, - mode, + default_todo=default_todo, + mode=mode, ) stdscr.clear() if temp != todos: @@ -615,13 +618,18 @@ def handle_cursor_down(todos: list[Todo], selected: Cursor) -> None: def handle_new_todo_next( - stdscr: Any, todos: list[Todo], selected: Cursor, mode: SingleLineModeImpl + stdscr: Any, + todos: list[Todo], + selected: Cursor, + mode: SingleLineModeImpl, + default_todo: Todo = Todo(), ) -> list[Todo]: return selected.todo_set_to( new_todo_next( stdscr, todos, int(selected), + default_todo, mode, ) ) @@ -738,7 +746,7 @@ def handle_enter( prev_todo = todos[int(selected)] if len(todos) > 0 else Todo() if prev_todo.has_box(): return toggle(todos, selected) - return selected.todo_set_to(new_todo_next(stdscr, todos, int(selected), mode)) + return selected.todo_set_to(new_todo_next(stdscr, todos, int(selected), mode=mode)) def print_history(history: UndoRedo) -> None: @@ -914,7 +922,13 @@ def main(stdscr: Any) -> int: todos = handle_new_todo_next(stdscr, todos, selected, single_line_state) continue if single_line_state.is_once(): - todos = handle_new_todo_next(stdscr, todos, selected, single_line_state) + todos = handle_new_todo_next( + stdscr, + todos, + selected, + single_line_state, + Todo().set_display_text(single_line_state.get_extra_data()), + ) single_line_state.set_on() continue next_step = get_main_input(