mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-20 13:08:31 +02:00
Pretty print journal entry titles and dates.
Changes appearance of all jrnl viewing commands, such as $ jrnl --short and $ jrnl -n {NUM}. Fix #508
This commit is contained in:
parent
ef23d7eabe
commit
e7da8c12a0
3 changed files with 20 additions and 6 deletions
|
@ -5,7 +5,7 @@ from __future__ import unicode_literals
|
|||
import re
|
||||
import textwrap
|
||||
from datetime import datetime
|
||||
from .util import split_title
|
||||
from .util import split_title, bold, colorize_red
|
||||
|
||||
|
||||
class Entry:
|
||||
|
@ -79,7 +79,10 @@ class Entry:
|
|||
else:
|
||||
indent = ""
|
||||
if not short and self.journal.config['linewrap']:
|
||||
title = textwrap.fill(date_str + " " + self.title, self.journal.config['linewrap'])
|
||||
# Color date red and make sure first line of title is bolded
|
||||
title = textwrap.fill(colorize_red(date_str) + " " + bold(self.title), self.journal.config['linewrap'])
|
||||
# Make sure all lines after the first are bolded, too
|
||||
title = "".join([bold(part) + "\n" for part in title.split("\n")])
|
||||
body = "\n".join([
|
||||
textwrap.fill(
|
||||
line,
|
||||
|
@ -90,7 +93,7 @@ class Entry:
|
|||
for line in self.body.rstrip(" \n").splitlines()
|
||||
])
|
||||
else:
|
||||
title = date_str + " " + self.title.rstrip("\n ")
|
||||
title = colorize_red(date_str) + " " + bold(self.title.rstrip("\n "))
|
||||
body = self.body.rstrip("\n ")
|
||||
|
||||
# Suppress bodies that are just blanks and new lines.
|
||||
|
|
|
@ -152,12 +152,12 @@ class Journal(object):
|
|||
for tag in self.search_tags:
|
||||
tagre = re.compile(re.escape(tag), re.IGNORECASE)
|
||||
pp = re.sub(tagre,
|
||||
lambda match: util.colorize(match.group(0)),
|
||||
lambda match: util.colorize_cyan(match.group(0)),
|
||||
pp, re.UNICODE)
|
||||
else:
|
||||
pp = re.sub(
|
||||
Entry.Entry.tag_regex(self.config['tagsymbols']),
|
||||
lambda match: util.colorize(match.group(0)),
|
||||
lambda match: util.colorize_cyan(match.group(0)),
|
||||
pp
|
||||
)
|
||||
return pp
|
||||
|
|
13
jrnl/util.py
13
jrnl/util.py
|
@ -180,11 +180,22 @@ def get_text_from_editor(config, template=""):
|
|||
return raw
|
||||
|
||||
|
||||
def colorize(string):
|
||||
def colorize_cyan(string):
|
||||
"""Returns the string wrapped in cyan ANSI escape"""
|
||||
return u"\033[36m{}\033[39m".format(string)
|
||||
|
||||
|
||||
def colorize_red(string):
|
||||
"""Returns the string wrapped in red ANSI escape"""
|
||||
return u"\033[91m{}\033[0m".format(string)
|
||||
|
||||
|
||||
def bold(string):
|
||||
"""Returns the string wrapped in bold ANSI escape. Bug / feature that it
|
||||
also colors the text blue, for some unknown reason."""
|
||||
return u"\033[1m{}\033[0m".format(string)
|
||||
|
||||
|
||||
def slugify(string):
|
||||
"""Slugifies a string.
|
||||
Based on public domain code from https://github.com/zacharyvoase/slugify
|
||||
|
|
Loading…
Add table
Reference in a new issue