Skip to content

Commit

Permalink
feature: long todos break on last word, not last character
Browse files Browse the repository at this point in the history
  • Loading branch information
mecaneer23 committed Dec 10, 2023
1 parent e3ecd84 commit 25ea1f2
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 9 deletions.
7 changes: 7 additions & 0 deletions src/class_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
3 changes: 2 additions & 1 deletion src/class_todo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 4 additions & 3 deletions src/get_todo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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))
24 changes: 19 additions & 5 deletions todo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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]:
"""
Expand All @@ -452,7 +454,8 @@ def new_todo_next(
stdscr,
todos,
selected + 1,
mode,
default_todo=default_todo,
mode=mode,
)
stdscr.clear()
if temp != todos:
Expand Down Expand Up @@ -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,
)
)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 25ea1f2

Please sign in to comment.