mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-20 21:18:32 +02:00
Fix newline colorization bug
Debug code left intact since there are more bugs to fix :/
This commit is contained in:
parent
77472261de
commit
8d0aa98200
1 changed files with 14 additions and 8 deletions
22
jrnl/util.py
22
jrnl/util.py
|
@ -17,7 +17,7 @@ import subprocess
|
||||||
import codecs
|
import codecs
|
||||||
import unicodedata
|
import unicodedata
|
||||||
import shlex
|
import shlex
|
||||||
from string import punctuation
|
from string import punctuation, whitespace
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
@ -197,6 +197,10 @@ def get_text_from_editor(config, template=""):
|
||||||
return raw
|
return raw
|
||||||
|
|
||||||
|
|
||||||
|
def text_debug(msg, text):
|
||||||
|
print(f"{msg} : {repr(text)}")
|
||||||
|
|
||||||
|
|
||||||
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" or the color doesn't exist in the colorama.Fore attributes,
|
the user is "NONE" or the color doesn't exist in the colorama.Fore attributes,
|
||||||
|
@ -228,8 +232,7 @@ def highlight_tags_with_background_color(entry, text, color, bold=False):
|
||||||
:rtype: List of tuples
|
:rtype: List of tuples
|
||||||
:returns [(colorized_str, original_str)]"""
|
:returns [(colorized_str, original_str)]"""
|
||||||
for fragment in fragments:
|
for fragment in fragments:
|
||||||
for part in fragment.lstrip().split(" "):
|
for part in fragment.lstrip(" ").lstrip("\t").split(" "):
|
||||||
# part = part.strip()
|
|
||||||
if part and part[0] not in config['tagsymbols']:
|
if part and part[0] not in config['tagsymbols']:
|
||||||
yield (colorize(part, color, bold), part)
|
yield (colorize(part, color, bold), part)
|
||||||
elif part:
|
elif part:
|
||||||
|
@ -248,21 +251,24 @@ def highlight_tags_with_background_color(entry, text, color, bold=False):
|
||||||
|
|
||||||
final_text = ""
|
final_text = ""
|
||||||
previous_piece = ""
|
previous_piece = ""
|
||||||
# [print("FRAG: '" + repr(frag) + "'") for frag in text_fragments]
|
[text_debug("FRAG BEFORE COLORIZED_GEN", frag) for frag in text_fragments]
|
||||||
for colorized_piece, piece in colorized_text_generator(text_fragments):
|
for colorized_piece, piece in colorized_text_generator(text_fragments):
|
||||||
# If it's punctuation and the previous word was a tag, add it directly after the tag.
|
# If it's punctuation and the previous word was a tag, add it directly after the tag.
|
||||||
# TODO: This logic seems flawed...
|
# TODO: This logic seems flawed...
|
||||||
if piece in punctuation and previous_piece[0] in config['tagsymbols']:
|
text_debug("PIECE", piece)
|
||||||
# print("PUNCT, POST TAG: '" + colorized_piece + "'")
|
if all(char in punctuation + whitespace for char in piece) \
|
||||||
|
or previous_piece.endswith("\n") \
|
||||||
|
or (previous_piece and previous_piece[0] in config['tagsymbols']):
|
||||||
|
text_debug("ALL PUNCT OR POST TAG", colorized_piece)
|
||||||
final_text += colorized_piece
|
final_text += colorized_piece
|
||||||
else:
|
else:
|
||||||
# Otherwise just append it.
|
# Otherwise just append it.
|
||||||
# print("NOT PUNCT OR NOT POST TAG: '" + colorized_piece + "'")
|
text_debug("NOT PUNCT OR NOT POST TAG", colorized_piece)
|
||||||
final_text += " " + colorized_piece
|
final_text += " " + colorized_piece
|
||||||
final_text = final_text.lstrip()
|
final_text = final_text.lstrip()
|
||||||
|
|
||||||
previous_piece = piece
|
previous_piece = piece
|
||||||
# print("DONE")
|
print("DONE")
|
||||||
return final_text.lstrip()
|
return final_text.lstrip()
|
||||||
else:
|
else:
|
||||||
return text
|
return text
|
||||||
|
|
Loading…
Add table
Reference in a new issue