mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-21 13:38:31 +02:00
Fix editor config when an argument with a space is used
This commit is contained in:
parent
cdaf1f5a36
commit
455720f788
4 changed files with 44 additions and 4 deletions
|
@ -39,6 +39,15 @@ Feature: Basic reading and writing to a journal
|
||||||
When we open the editor and enter nothing
|
When we open the editor and enter nothing
|
||||||
Then we should see the message "[Nothing saved to file]"
|
Then we should see the message "[Nothing saved to file]"
|
||||||
|
|
||||||
|
Scenario: Sending an argument with spaces to the editor should work
|
||||||
|
Given we use the config "editor-args.yaml"
|
||||||
|
When we open the editor and enter "lorem ipsum"
|
||||||
|
Then the editor should have been called with 5 arguments
|
||||||
|
And the editor arguments should contain "vim"
|
||||||
|
And the editor arguments should contain "-f"
|
||||||
|
And the editor arguments should contain "-c"
|
||||||
|
And the editor arguments should contain "setf markdown"
|
||||||
|
|
||||||
Scenario: Writing an empty entry from the command line
|
Scenario: Writing an empty entry from the command line
|
||||||
Given we use the config "basic.yaml"
|
Given we use the config "basic.yaml"
|
||||||
When we run "jrnl" and enter nothing
|
When we run "jrnl" and enter nothing
|
||||||
|
|
12
features/data/configs/editor-args.yaml
Normal file
12
features/data/configs/editor-args.yaml
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
default_hour: 9
|
||||||
|
default_minute: 0
|
||||||
|
editor: vim -f -c 'setf markdown'
|
||||||
|
encrypt: false
|
||||||
|
highlight: true
|
||||||
|
journals:
|
||||||
|
default: features/journals/simple.journal
|
||||||
|
linewrap: 80
|
||||||
|
tagsymbols: "@"
|
||||||
|
template: false
|
||||||
|
timeformat: "%Y-%m-%d %H:%M"
|
||||||
|
indent_character: "|"
|
|
@ -85,6 +85,7 @@ def open_editor_and_enter(context, text=""):
|
||||||
text = text or context.text or ""
|
text = text or context.text or ""
|
||||||
|
|
||||||
def _mock_editor_function(command):
|
def _mock_editor_function(command):
|
||||||
|
context.editor_command = command
|
||||||
tmpfile = command[-1]
|
tmpfile = command[-1]
|
||||||
with open(tmpfile, "w+") as f:
|
with open(tmpfile, "w+") as f:
|
||||||
f.write(text)
|
f.write(text)
|
||||||
|
@ -92,7 +93,17 @@ def open_editor_and_enter(context, text=""):
|
||||||
return tmpfile
|
return tmpfile
|
||||||
|
|
||||||
with patch("subprocess.call", side_effect=_mock_editor_function):
|
with patch("subprocess.call", side_effect=_mock_editor_function):
|
||||||
run(context, "jrnl")
|
context.execute_steps('when we run "jrnl"')
|
||||||
|
|
||||||
|
|
||||||
|
@then("the editor should have been called with {num} arguments")
|
||||||
|
def count_editor_args(context, num):
|
||||||
|
assert len(context.editor_command) == int(num)
|
||||||
|
|
||||||
|
|
||||||
|
@then('the editor arguments should contain "{arg}"')
|
||||||
|
def contains_editor_arg(context, arg):
|
||||||
|
assert arg in context.editor_command
|
||||||
|
|
||||||
|
|
||||||
def _mock_getpass(inputs):
|
def _mock_getpass(inputs):
|
||||||
|
|
14
jrnl/util.py
14
jrnl/util.py
|
@ -9,6 +9,7 @@ from string import punctuation, whitespace
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
|
import textwrap
|
||||||
from typing import Callable, Optional
|
from typing import Callable, Optional
|
||||||
import unicodedata
|
import unicodedata
|
||||||
|
|
||||||
|
@ -172,10 +173,17 @@ def get_text_from_editor(config, template=""):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
subprocess.call(
|
subprocess.call(
|
||||||
shlex.split(config["editor"], posix="win" not in sys.platform) + [tmpfile]
|
shlex.split(config["editor"], posix="win32" not in sys.platform) + [tmpfile]
|
||||||
)
|
)
|
||||||
except AttributeError:
|
except Exception as e:
|
||||||
subprocess.call(config["editor"] + [tmpfile])
|
error_msg = f"""
|
||||||
|
{ERROR_COLOR}{str(e)}{RESET_COLOR}
|
||||||
|
|
||||||
|
Please check the 'editor' key in your config file for errors:
|
||||||
|
{repr(config['editor'])}
|
||||||
|
"""
|
||||||
|
print(textwrap.dedent(error_msg).strip(), file=sys.stderr)
|
||||||
|
exit(1)
|
||||||
|
|
||||||
with open(tmpfile, "r", encoding="utf-8") as f:
|
with open(tmpfile, "r", encoding="utf-8") as f:
|
||||||
raw = f.read()
|
raw = f.read()
|
||||||
|
|
Loading…
Add table
Reference in a new issue