From e5fdf72fb67d9771263b6aad535d11996917c23d Mon Sep 17 00:00:00 2001 From: Jonathan Wren Date: Sat, 7 May 2022 10:53:46 -0700 Subject: [PATCH] Move around code to separate concerns of each function a bit more --- jrnl/output.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/jrnl/output.py b/jrnl/output.py index 5022887a..13d932d7 100644 --- a/jrnl/output.py +++ b/jrnl/output.py @@ -53,12 +53,7 @@ def print_msgs( args = style.decoration.args for msg in msgs: - args["border_style"] = msg.style.color - if msg.style == MsgStyle.ERROR: - args["title"] = "Error" - - if is_keyboard_int(msg): - print() + args = _add_extra_style_args_if_needed(args, msg=msg) m = format_msg(msg) m.append(delimiter) @@ -70,10 +65,24 @@ def print_msgs( Console(stderr=True).print(callback(text, **args)) +def _add_extra_style_args_if_needed(args, msg): + args["border_style"] = msg.style.color + if msg.style == MsgStyle.ERROR: + args["title"] = "Error" + return args + + def is_keyboard_int(msg: Message) -> bool: return msg.text == MsgText.KeyboardInterruptMsg def format_msg(msg: Message) -> Text: - text = textwrap.dedent(msg.text.value.format(**msg.params)).strip() + text = "" + + if is_keyboard_int(msg): + # extra line break for keyboard interrupts + text = "\n" + + text += textwrap.dedent(msg.text.value.format(**msg.params)).strip() return Text(text) +