From 8c2de0e6d7fc1840c86d45fc62092c78e1f0a36d Mon Sep 17 00:00:00 2001 From: joaquin garmendia Date: Sat, 17 Oct 2020 18:14:16 -0500 Subject: [PATCH] Add display format option to config file. (#1050) * Add display format option to config file. * Add tests. * Fix `black` error. * Change nested if to top level. --- docs/advanced.md | 3 +++ features/data/configs/format_md.yaml | 19 +++++++++++++++++++ features/data/configs/format_text.yaml | 19 +++++++++++++++++++ features/format.feature | 23 +++++++++++++++++++++++ jrnl/jrnl.py | 5 +++-- 5 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 features/data/configs/format_md.yaml create mode 100644 features/data/configs/format_text.yaml diff --git a/docs/advanced.md b/docs/advanced.md index 67d5553c..3a0172e7 100644 --- a/docs/advanced.md +++ b/docs/advanced.md @@ -38,6 +38,9 @@ and can be edited with a plain text editor. controls the width of the output. Set to `false` if you don't want to wrap long lines. - `colors` dictionary that controls the colors used to display journal entries. It has four subkeys, which are: `body`, `date`, `tags`, and `title`. Current valid values are: `BLACK`, `RED`, `GREEN`, `YELLOW`, `BLUE`, `MAGENTA`, `CYAN`, `WHITE`, and `NONE`. `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. + - `display_format` + specifies formatter to use, formatters available are: + `boxed`, `fancy`, `json`, `markdown`, `md`, `tags`, `text`, `txt`, `xml`, or `yaml`. !!! note Although it seems intuitive to use the `#` diff --git a/features/data/configs/format_md.yaml b/features/data/configs/format_md.yaml new file mode 100644 index 00000000..0b9f1c3b --- /dev/null +++ b/features/data/configs/format_md.yaml @@ -0,0 +1,19 @@ +colors: + body: none + date: none + tags: none + title: none +default_hour: 9 +default_minute: 0 +display_format: markdown +editor: '' +encrypt: false +highlight: true +indent_character: '|' +journals: + default: features/journals/simple.journal +linewrap: 80 +tagsymbols: '@' +template: false +timeformat: '%Y-%m-%d %H:%M' +version: v2.4.5 diff --git a/features/data/configs/format_text.yaml b/features/data/configs/format_text.yaml new file mode 100644 index 00000000..c82ff7a7 --- /dev/null +++ b/features/data/configs/format_text.yaml @@ -0,0 +1,19 @@ +colors: + body: none + date: none + tags: none + title: none +default_hour: 9 +default_minute: 0 +display_format: text +editor: '' +encrypt: false +highlight: true +indent_character: '|' +journals: + default: features/journals/simple.journal +linewrap: 80 +tagsymbols: '@' +template: false +timeformat: '%Y-%m-%d %H:%M' +version: v2.4.5 diff --git a/features/format.feature b/features/format.feature index e689a9f3..9b8d82a5 100644 --- a/features/format.feature +++ b/features/format.feature @@ -512,3 +512,26 @@ Feature: Custom formats | basic_encrypted | | basic_folder | | basic_dayone | + + Scenario: Markdown Support from config file + Given we use the config "format_md.yaml" + When we run "jrnl -n 1" + Then the output should be + """ + # 2013 + + ## June + + ### 2013-06-10 15:40 Life is good. + + But I'm better. + """ + + Scenario: Text Formatter from config file + Given we use the config "format_text.yaml" + When we run "jrnl -n 1" + Then the output should be + """ + [2013-06-10 15:40] Life is good. + But I'm better. + """ diff --git a/jrnl/jrnl.py b/jrnl/jrnl.py index 33eabdd0..3be2e2da 100644 --- a/jrnl/jrnl.py +++ b/jrnl/jrnl.py @@ -300,7 +300,8 @@ def _display_search_results(args, journal, **kwargs): elif args.export: exporter = plugins.get_exporter(args.export) print(exporter.export(journal, args.filename)) - + elif kwargs["config"].get("display_format"): + exporter = plugins.get_exporter(kwargs["config"]["display_format"]) + print(exporter.export(journal, args.filename)) else: - # Default display mode print(journal.pprint())