Skip to content

Commit

Permalink
💄 Improve styling of colored cards (gkeep)
Browse files Browse the repository at this point in the history
Instead of giving the card a black background and coloring the text some
color, remove the border (because border on background is ugly) and make
the background the card's color. The foreground color is determined with
`readable_on`. Also update `readable_on` to return Rich colors by
default, since it's what I'm using everywhere.
  • Loading branch information
ewen-lbh committed May 8, 2021
1 parent 129a0b4 commit 5041355
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
7 changes: 5 additions & 2 deletions ideaseed/gkeep.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
VALID_COLOR_NAMES)
from ideaseed.ondisk import Idea
from ideaseed.utils import (answered_yes_to, ask, case_insensitive_find,
error_message_no_object_found, print_dry_run)
error_message_no_object_found, print_dry_run,
readable_on)

rich.traceback.install()

Expand Down Expand Up @@ -174,7 +175,9 @@ def push_to_gkeep(
description=body,
labels=map(to_ui_label, labels),
card_title="",
card_style=to_rich_color(color) + " on black",
card_style="default"
if color == "White"
else f"{readable_on(COLOR_NAME_TO_HEX_MAP[color])} on {to_rich_color(color)}",
milestone=None,
assignees=assign,
project=None,
Expand Down
10 changes: 8 additions & 2 deletions ideaseed/ui.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from shutil import get_terminal_size
from typing import Iterable, NamedTuple, Optional

import rich.box
import rich.markup
from rich import print
from rich.align import Align
Expand Down Expand Up @@ -69,7 +70,7 @@ class Label(NamedTuple):
url: Optional[str] = None

def __str__(self) -> str:
s = f"[#{readable_on(self.color)} on #{self.color}]{self.name}[/]"
s = f"[{readable_on(self.color)} on #{self.color}]{self.name}[/]"
if self.url:
s = href(s, self.url)
return s
Expand Down Expand Up @@ -107,7 +108,12 @@ def make_card(
label_row.add_row(", ".join(map(str, labels)))
card.add_row(label_row)

return Panel(card, title=card_title, style=card_style)
return Panel(
card,
title=card_title,
style=card_style,
box=rich.box.ROUNDED if "on " not in card_style else Box(" \n" * 8),
)


def make_table(
Expand Down
2 changes: 1 addition & 1 deletion ideaseed/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def process_response(self, value: str) -> PromptType:
return val


def readable_on(background: str, light: str = "FFFFFF", dark: str = "000000") -> str:
def readable_on(background: str, light: str = "white", dark: str = "black") -> str:
"""
Choses either ``light`` or ``dark`` based on the background color
the text is supposed to be written on ``background`` (also given as an hex int)
Expand Down

0 comments on commit 5041355

Please sign in to comment.