mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-07-06 08:26:12 +02:00
Handle invalid colors by not using a color
This commit is contained in:
parent
6ce83c7aa1
commit
89c43664de
2 changed files with 5 additions and 7 deletions
|
@ -33,7 +33,7 @@ and can be edited with any plain text editor.
|
||||||
- `linewrap`
|
- `linewrap`
|
||||||
controls the width of the output. Set to `false` if you don't want to wrap long lines.
|
controls the width of the output. Set to `false` if you don't want to wrap long lines.
|
||||||
- `colors`
|
- `colors`
|
||||||
dictionary that controls the colors used to display journal entries. It has two subkeys, which are: `date` and `title`. Current valid values are: `BLACK`, `RED`, `GREEN`, `YELLOW`, `BLUE`, `MAGENTA`, `CYAN`, and `WHITE`. `colorama.Fore` is used for colorization, and you can find the [docs here](https://github.com/tartley/colorama#colored-output). To disable colored output, set the value to `NONE`.
|
dictionary that controls the colors used to display journal entries. It has two subkeys, which are: `date` and `title`. Current valid values are: `BLACK`, `RED`, `GREEN`, `YELLOW`, `BLUE`, `MAGENTA`, `CYAN`, and `WHITE`. `colorama.Fore` is used for colorization, and you can find the [docs here](https://github.com/tartley/colorama#colored-output). To disable colored output, set the value to `NONE`. If you set the value of any color subkey to an invalid color, no color will be used.
|
||||||
|
|
||||||
!!! note
|
!!! note
|
||||||
Although it seems intuitive to use the `#`
|
Although it seems intuitive to use the `#`
|
||||||
|
|
10
jrnl/util.py
10
jrnl/util.py
|
@ -198,14 +198,12 @@ def get_text_from_editor(config, template=""):
|
||||||
|
|
||||||
def colorize(string, color, bold=False):
|
def colorize(string, color, bold=False):
|
||||||
"""Returns the string colored with colorama.Fore.color. If the color set by
|
"""Returns the string colored with colorama.Fore.color. If the color set by
|
||||||
the user is "NONE", it returns the string without any modification. Otherwise,
|
the user is "NONE" or the color doesn't exist in the colorama.Fore attributes,
|
||||||
If the color set by the user doesn't exist in the colorama.Fore attributes,
|
it returns the string without any modification."""
|
||||||
the colorization is done with WHITE."""
|
color_escape = getattr(colorama.Fore, color.upper(), None)
|
||||||
upper_color = color.upper()
|
if not color_escape:
|
||||||
if upper_color == "NONE":
|
|
||||||
return string
|
return string
|
||||||
|
|
||||||
color_escape = getattr(colorama.Fore, upper_color, colorama.Fore.WHITE)
|
|
||||||
if not bold:
|
if not bold:
|
||||||
return color_escape + string + colorama.Fore.RESET
|
return color_escape + string + colorama.Fore.RESET
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue