mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-10 08:38:32 +02:00
* Update authors to "jrnl contributors" to comply with GPL3 * Include jrnl email address with contributors * Include GPL notice in jrnl --version * Apply consistent copyright and license to all Python files * Add copyright and license to documentation * Add copyright and license to docs theme * Wiping poetry cache to try to resolve a test issue * Testing with Python 3.9.0 in attempt to bypass GitHub Actions failure in 3.9.1 * make format * Exclude Windows Python 3.9 build which is failing due to a GitHub Actions problem * Modify testing to get around this 3.9 issue... * Fix exclude
76 lines
2.5 KiB
Python
76 lines
2.5 KiB
Python
#!/usr/bin/env python
|
|
# encoding: utf-8
|
|
# Copyright (C) 2012-2021 jrnl contributors
|
|
# License: https://www.gnu.org/licenses/gpl-3.0.html
|
|
|
|
from textwrap import TextWrapper
|
|
|
|
from .text_exporter import TextExporter
|
|
|
|
|
|
class FancyExporter(TextExporter):
|
|
"""This Exporter can convert entries and journals into text with unicode box drawing characters."""
|
|
|
|
names = ["fancy", "boxed"]
|
|
extension = "txt"
|
|
|
|
border_a = "┎"
|
|
border_b = "─"
|
|
border_c = "╮"
|
|
border_d = "╘"
|
|
border_e = "═"
|
|
border_f = "╕"
|
|
border_g = "┃"
|
|
border_h = "│"
|
|
border_i = "┠"
|
|
border_j = "╌"
|
|
border_k = "┤"
|
|
border_l = "┖"
|
|
border_m = "┘"
|
|
|
|
@classmethod
|
|
def export_entry(cls, entry):
|
|
"""Returns a fancy unicode representation of a single entry."""
|
|
date_str = entry.date.strftime(entry.journal.config["timeformat"])
|
|
linewrap = entry.journal.config["linewrap"] or 78
|
|
initial_linewrap = linewrap - len(date_str) - 2
|
|
body_linewrap = linewrap - 2
|
|
card = [
|
|
cls.border_a + cls.border_b * (initial_linewrap) + cls.border_c + date_str
|
|
]
|
|
w = TextWrapper(
|
|
width=initial_linewrap,
|
|
initial_indent=cls.border_g + " ",
|
|
subsequent_indent=cls.border_g + " ",
|
|
)
|
|
title_lines = w.wrap(entry.title)
|
|
card.append(
|
|
title_lines[0].ljust(initial_linewrap + 1)
|
|
+ cls.border_d
|
|
+ cls.border_e * (len(date_str) - 1)
|
|
+ cls.border_f
|
|
)
|
|
w.width = body_linewrap
|
|
if len(title_lines) > 1:
|
|
for line in w.wrap(
|
|
" ".join(
|
|
[
|
|
title_line[len(w.subsequent_indent) :]
|
|
for title_line in title_lines[1:]
|
|
]
|
|
)
|
|
):
|
|
card.append(line.ljust(body_linewrap + 1) + cls.border_h)
|
|
if entry.body:
|
|
card.append(cls.border_i + cls.border_j * body_linewrap + cls.border_k)
|
|
for line in entry.body.splitlines():
|
|
body_lines = w.wrap(line) or [cls.border_g]
|
|
for body_line in body_lines:
|
|
card.append(body_line.ljust(body_linewrap + 1) + cls.border_h)
|
|
card.append(cls.border_l + cls.border_b * body_linewrap + cls.border_m)
|
|
return "\n".join(card)
|
|
|
|
@classmethod
|
|
def export_journal(cls, journal):
|
|
"""Returns a unicode representation of an entire journal."""
|
|
return "\n".join(cls.export_entry(entry) for entry in journal)
|