在 daemon 优化了异常处理行为; 为编辑器等也设置了可定义的环境变量; 更新 README;

This commit is contained in:
2025-10-05 14:28:07 +08:00
parent a6b2905ad2
commit 5f5a492342
13 changed files with 109 additions and 51 deletions

View File

@@ -2,13 +2,16 @@ import os
code_snippet_dir = os.getenv("CODE_SNIPPET_DIR")
code_snippet_port = os.getenv("CODE_SNIPPET_PORT")
code_snippet_rofi = os.getenv("CODE_SNIPPET_ROFI")
code_snippet_rofi = os.getenv("CODE_SNIPPET_ROFI", "rofi")
code_snippet_editor = os.getenv("CODE_SNIPPET_EDITOR","nvim")
action_list = "LIST"
action_add = "ADD"
action_edit = "EDIT"
action_delete = "DELETE"
editor_class = "code_snippet_editor"
template_add = """
## Snippet

View File

@@ -25,11 +25,11 @@
#
import atexit
from datetime import datetime
from decimal import Decimal, InvalidOperation
import signal
import subprocess
import time
from datetime import datetime
from decimal import Decimal, InvalidOperation
# Python < 3.2 doesn't provide a context manager interface for Popen.
# Let's make our own wrapper if needed.

View File

@@ -8,6 +8,8 @@ import subprocess
import tempfile
from pathlib import Path
from CodeSnippetRofi.common.constant import editor_class, code_snippet_editor
from common.constant import template_add, template_edit
from entity.result import ActionResult
from helper.api_helper import run_edit, run_add
@@ -201,23 +203,23 @@ def _open_with_nvim(file_path: str) -> None:
# 根据终端类型添加特定参数
if name == 'alacritty':
cmd.extend(['--class', 'floating-nvim', '-e', 'nvim', file_path])
cmd.extend(['--class', editor_class, '-e', code_snippet_editor, file_path])
elif name == 'kitty':
cmd.extend(['--class', 'floating-nvim', 'nvim', file_path])
cmd.extend(['--class', editor_class, code_snippet_editor, file_path])
elif name == 'foot':
cmd.extend(['-a', 'floating-nvim', 'nvim', file_path])
cmd.extend(['-a', editor_class, code_snippet_editor, file_path])
elif name == 'wezterm':
cmd.extend(['start', '--class', 'floating-nvim', '--', 'nvim', file_path])
cmd.extend(['start', '--class', editor_class, '--', code_snippet_editor, file_path])
elif name.startswith('gnome-terminal'):
cmd.extend(['--class=floating-nvim', '--', 'nvim', file_path])
cmd.extend([f'--class={editor_class}', '--', code_snippet_editor, file_path])
elif name == 'konsole':
cmd.extend(['--class', 'floating-nvim', '-e', 'nvim', file_path])
cmd.extend(['--class', editor_class, '-e', code_snippet_editor, file_path])
elif name == 'urxvt':
cmd.extend(['-name', 'floating-nvim', '-e', 'nvim', file_path])
cmd.extend(['-name', editor_class, '-e', code_snippet_editor, file_path])
elif name == 'xterm':
cmd.extend(['-class', 'floating-nvim', '-e', 'nvim', file_path])
cmd.extend(['-class', editor_class, '-e', code_snippet_editor, file_path])
else:
cmd.extend(['-e', 'nvim', file_path])
cmd.extend(['-e', code_snippet_editor, file_path])
# 阻塞执行命令,直到进程结束
subprocess.run(cmd)

View File

@@ -1,11 +1,6 @@
import os
from common.constant import code_snippet_rofi
from common import rofi
from common.constant import code_snippet_rofi
from menu.MainMenu import MainMenu
if code_snippet_rofi is None:
r = rofi.Rofi()
else:
r = rofi.Rofi(code_snippet_rofi)
r = rofi.Rofi(code_snippet_rofi)
MainMenu(r).run()