Skip to content

Commit

Permalink
fixes #17
Browse files Browse the repository at this point in the history
  • Loading branch information
lnxpy committed Jun 11, 2024
1 parent 311e40e commit 265a92b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
7 changes: 7 additions & 0 deletions hey/consts.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import os
import platform

from platformdirs import user_config_path

# App name
Expand All @@ -6,6 +9,10 @@
# Service address
SERVICE_URL = "https://llm.mdb.ai"

if platform.system().lower() == "windows":
DEFAULT_EDITOR = os.environ.get("EDITOR", "notepad")
else:
DEFAULT_EDITOR = os.environ.get("EDITOR", "vim")

# basic configuration setup
BASE_CONFIG = {
Expand Down
15 changes: 7 additions & 8 deletions hey/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
import subprocess
import tempfile

from rich.console import Console

logger = Console()
from hey.consts import DEFAULT_EDITOR


def open_tmp_editor() -> str:
Expand All @@ -14,12 +12,13 @@ def open_tmp_editor() -> str:
str: input string
"""

with tempfile.NamedTemporaryFile(mode="w+") as temp_file:
with tempfile.NamedTemporaryFile(mode="w+", delete=False) as temp_file:
temp_file_path = temp_file.name

subprocess.run([os.environ["EDITOR"], temp_file_path])
subprocess.run([DEFAULT_EDITOR, temp_file_path])

with open(temp_file_path, "r") as file:
data = file.read()
with open(temp_file_path, "r") as file:
data = file.read()

return data
os.unlink(temp_file_path)
return data

0 comments on commit 265a92b

Please sign in to comment.