Skip to content

Commit

Permalink
fix checkbox rendering on most terminals
Browse files Browse the repository at this point in the history
  • Loading branch information
mecaneer23 committed Sep 18, 2023
1 parent b0610b9 commit b44fbfe
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,3 @@ systemctl start docker
## Bugs

- Long todos don't render properly in strikethrough mode (in certain terminals)
- Some terminals display the checkbox character weirdly (currently uses two space workaround)
4 changes: 2 additions & 2 deletions src/class_todo.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# pylint: disable=global-statement, missing-class-docstring
# pylint: disable=missing-function-docstring, missing-module-docstring

from src.get_args import INDENT
from src.get_args import CHECKBOX, INDENT


class Todo:
Expand Down Expand Up @@ -67,7 +67,7 @@ def set_color(self, color: int) -> None:

def get_box(self) -> str:
table = {
"+": "☑ ",
"+": f"{CHECKBOX} ",
"-": "☐ ",
None: "",
}
Expand Down
18 changes: 17 additions & 1 deletion src/get_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
# pylint: disable=missing-function-docstring, missing-module-docstring

from argparse import ArgumentParser, Namespace, RawDescriptionHelpFormatter
from curses import wrapper
from pathlib import Path
from typing import Any

from src.md_to_py import md_table_to_lines

BULLETS = False
CHECKBOX = ""
CONTROLS_BEGIN_INDEX = 67
CONTROLS_END_INDEX = 91
DEFAULT_TODO = "todo.txt"
Expand All @@ -20,6 +23,16 @@
SIMPLE_BOXES = False
STRIKETHROUGH = False

CHECKBOX_OPTIONS = ("🗹", "☑")


def _get_checkbox(win: Any) -> str:
try:
win.addch(0, 0, CHECKBOX_OPTIONS[0])
return CHECKBOX_OPTIONS[0]
except TypeError:
return CHECKBOX_OPTIONS[1]


def get_args() -> Namespace:
parser = ArgumentParser(
Expand Down Expand Up @@ -127,11 +140,14 @@ def get_args() -> Namespace:
help="Allows passing alternate header.\
Default is filename.",
)
return parser.parse_args()
args = vars(parser.parse_args())
args["checkbox"] = wrapper(_get_checkbox) if not args["simple_boxes"] else ""
return Namespace(**args)


command_line_args = get_args()
BULLETS = command_line_args.bullet_display
CHECKBOX = command_line_args.checkbox
ENUMERATE = command_line_args.enumerate
FILENAME = (
Path(command_line_args.filename, DEFAULT_TODO)
Expand Down

0 comments on commit b44fbfe

Please sign in to comment.