mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-07-06 00:16:13 +02:00
move editor function into editor file
This commit is contained in:
parent
7e674af3e2
commit
54bcfddd3c
2 changed files with 19 additions and 12 deletions
|
@ -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
|
||||
|
|
14
jrnl/jrnl.py
14
jrnl/jrnl.py
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue