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 2c2651e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
6 changes: 6 additions & 0 deletions hey/consts.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
from platformdirs import user_config_path
from platform import platform
import os

# App name
APP_NAME = "Hey"

# 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 2c2651e

Please sign in to comment.