move editor function into editor file

This commit is contained in:
Jonathan Wren 2020-08-16 13:09:50 -07:00
parent 7e674af3e2
commit 54bcfddd3c
No known key found for this signature in database
GPG key ID: 43D5FF8722E7F68A
2 changed files with 19 additions and 12 deletions

View file

@ -1,3 +1,4 @@
import logging
import os
import shlex
import subprocess
@ -38,3 +39,19 @@ def get_text_from_editor(config, template=""):
print("[Nothing saved to file]", file=sys.stderr)
return raw
def get_text_from_stdin():
_how_to_quit = "Ctrl+z and then Enter" if on_windows else "Ctrl+d"
print(
f"[Writing Entry; on a blank line, press {_how_to_quit} to finish writing]\n",
file=sys.stderr,
)
try:
raw = sys.stdin.read()
except KeyboardInterrupt:
logging.error("Write mode: keyboard interrupt")
print("[Entry NOT saved to journal]", file=sys.stderr)
sys.exit(0)
return raw

View file

@ -9,8 +9,8 @@ from .color import RESET_COLOR
from .config import get_journal_name
from .config import scope_config
from .editor import get_text_from_editor
from .editor import get_text_from_stdin
from .exception import UserAbort
from .os_compat import on_windows
def run(args):
@ -164,17 +164,7 @@ def _write_in_editor(config):
raw = get_text_from_editor(config, template)
else:
_how_to_quit = "Ctrl+z and then Enter" if on_windows else "Ctrl+d"
print(
f"[Writing Entry; on a blank line, press {_how_to_quit} to finish writing]\n",
file=sys.stderr,
)
try:
raw = sys.stdin.read()
except KeyboardInterrupt:
logging.error("Write mode: keyboard interrupt")
print("[Entry NOT saved to journal]", file=sys.stderr)
sys.exit(0)
raw = get_text_from_stdin()
return raw