From b44fbfeea0cc11b142468912378ded34f7f1ce7b Mon Sep 17 00:00:00 2001 From: mecaneer23 Date: Sun, 17 Sep 2023 21:17:58 -0500 Subject: [PATCH] fix checkbox rendering on most terminals --- README.md | 1 - src/class_todo.py | 4 ++-- src/get_args.py | 18 +++++++++++++++++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1b76e61..4231a6a 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/src/class_todo.py b/src/class_todo.py index 1cd1deb..0fea51b 100644 --- a/src/class_todo.py +++ b/src/class_todo.py @@ -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: @@ -67,7 +67,7 @@ def set_color(self, color: int) -> None: def get_box(self) -> str: table = { - "+": "☑ ", + "+": f"{CHECKBOX} ", "-": "☐ ", None: "", } diff --git a/src/get_args.py b/src/get_args.py index cb9cf48..f2cf2d7 100644 --- a/src/get_args.py +++ b/src/get_args.py @@ -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" @@ -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( @@ -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)