Skip to content

Commit

Permalink
feat: use color names first letter rather than number (rgybmcw)
Browse files Browse the repository at this point in the history
  • Loading branch information
mecaneer23 committed Mar 11, 2024
1 parent 1cf6d10 commit a9753db
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 19 deletions.
8 changes: 5 additions & 3 deletions src/class_todo.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@ def _init_box_char(self, pointer: int) -> tuple[BoxChar, int]:
def _init_color(self, pointer: int) -> tuple[Color, int]:
if (
len(self.text) > pointer + 1
and self.text[pointer].isdigit()
and self.text[pointer + 1] == " "
):
return Color(int(self.text[pointer])), pointer + 2
if self.text[pointer].isdigit():
return Color(int(self.text[pointer])), pointer + 2
if self.text[pointer] in "rgybmcw":
return Color.from_first_char(self.text[pointer]), pointer + 2
return Color.WHITE, pointer

def _init_attrs(self) -> tuple[BoxChar, Color, str]:
Expand Down Expand Up @@ -167,7 +169,7 @@ def __repr__(self) -> str:
self.box_char != BoxChar.NONE and not self.is_empty(),
str(self.box_char),
),
Chunk(self.color != Color.WHITE, str(self.color.as_int())),
Chunk(self.color != Color.WHITE, str(self.color.as_char())),
Chunk(
(self.box_char != BoxChar.NONE and not self.is_empty())
or self.color != Color.WHITE,
Expand Down
17 changes: 17 additions & 0 deletions src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,23 @@ def as_int(self) -> int:
"""
return self.value

def as_char(self) -> str:
"""Get lowercase first letter of color"""
return self.name[0].lower()

@staticmethod
def from_first_char(char: str) -> "Color":
"""Return the color corresponding to its first character"""
return {
"r": Color.RED,
"g": Color.GREEN,
"y": Color.YELLOW,
"b": Color.BLUE,
"m": Color.MAGENTA,
"c": Color.CYAN,
"w": Color.WHITE,
}[char]

@staticmethod
def as_dict() -> dict[str, int]:
"""
Expand Down
31 changes: 15 additions & 16 deletions todo.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
-1 fix strikethrough
-1 fix long lines (longer than width // 2 - 1)
-1 fix moving down onto a toggled line
-4 implement multiline todos
-4 allow multiline paste
-4 allow multiline print
-5 make startup faster
-1 fix silence if dependencies are not installed
-2 add unit tests?
-2 use color names first letter rather than number (rgybmcw)
-3 add docstrings to `public` functions
-3 clipboard
-3 get_todo
-3 todo.py
-3 migrate from sometimes using `int` as cursor, to always using `Cursor`s
-3 migrate from `win: Any` to `win: curses.window`
-r fix strikethrough
-r fix long lines (longer than width // 2 - 1)
-r fix moving down onto a toggled line
-b implement multiline todos
-b allow multiline paste
-b allow multiline print
-m make startup faster
-r fix silence if dependencies are not installed
-g add unit tests?
-y add docstrings to `public` functions
-y clipboard
-y get_todo
-y todo.py
-y migrate from sometimes using `int` as cursor, to always using `Cursor`s
-y migrate from `win: Any` to `win: curses.window`
- fix gui support

0 comments on commit a9753db

Please sign in to comment.