Allow custom extensions when editing (for easier syntax highlighting) (#1139)

* Create tests and steps for temporary filename suffix
* Have temporary filename suffix be -{template_filename} or .jrnl
* Finalize extension_editor_file
* Make suffix local variable in get_text_from_editor
This commit is contained in:
Karim Rahal 2021-01-02 23:23:15 +02:00 committed by GitHub
parent c47c1e209e
commit e9fd5cdc0e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 42 additions and 1 deletions

View file

@ -5,6 +5,7 @@ import subprocess
import sys
import tempfile
import textwrap
from pathlib import Path
from .color import ERROR_COLOR
from .color import RESET_COLOR
@ -12,7 +13,11 @@ from .os_compat import on_windows
def get_text_from_editor(config, template=""):
filehandle, tmpfile = tempfile.mkstemp(prefix="jrnl", text=True, suffix=".txt")
suffix = ".jrnl"
if config["template"]:
template_filename = Path(config["template"]).name
suffix = "-" + template_filename
filehandle, tmpfile = tempfile.mkstemp(prefix="jrnl", text=True, suffix=suffix)
os.close(filehandle)
with open(tmpfile, "w", encoding="utf-8") as f: