lithe-cli 0.6.4__tar.gz → 0.6.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of lithe-cli might be problematic. Click here for more details.
- {lithe_cli-0.6.4 → lithe_cli-0.6.5}/PKG-INFO +1 -1
- {lithe_cli-0.6.4 → lithe_cli-0.6.5}/lithe_cli/__init__.py +1 -1
- {lithe_cli-0.6.4 → lithe_cli-0.6.5}/lithe_cli/prompts.py +23 -0
- {lithe_cli-0.6.4 → lithe_cli-0.6.5}/lithe_cli.egg-info/PKG-INFO +1 -1
- {lithe_cli-0.6.4 → lithe_cli-0.6.5}/LICENSE +0 -0
- {lithe_cli-0.6.4 → lithe_cli-0.6.5}/README.md +0 -0
- {lithe_cli-0.6.4 → lithe_cli-0.6.5}/lithe_cli/__main__.py +0 -0
- {lithe_cli-0.6.4 → lithe_cli-0.6.5}/lithe_cli/agent.py +0 -0
- {lithe_cli-0.6.4 → lithe_cli-0.6.5}/lithe_cli/config.py +0 -0
- {lithe_cli-0.6.4 → lithe_cli-0.6.5}/lithe_cli/main.py +0 -0
- {lithe_cli-0.6.4 → lithe_cli-0.6.5}/lithe_cli/py.typed +0 -0
- {lithe_cli-0.6.4 → lithe_cli-0.6.5}/lithe_cli/setup.py +0 -0
- {lithe_cli-0.6.4 → lithe_cli-0.6.5}/lithe_cli/tui.py +0 -0
- {lithe_cli-0.6.4 → lithe_cli-0.6.5}/lithe_cli/ui.py +0 -0
- {lithe_cli-0.6.4 → lithe_cli-0.6.5}/lithe_cli.egg-info/SOURCES.txt +0 -0
- {lithe_cli-0.6.4 → lithe_cli-0.6.5}/lithe_cli.egg-info/dependency_links.txt +0 -0
- {lithe_cli-0.6.4 → lithe_cli-0.6.5}/lithe_cli.egg-info/entry_points.txt +0 -0
- {lithe_cli-0.6.4 → lithe_cli-0.6.5}/lithe_cli.egg-info/requires.txt +0 -0
- {lithe_cli-0.6.4 → lithe_cli-0.6.5}/lithe_cli.egg-info/top_level.txt +0 -0
- {lithe_cli-0.6.4 → lithe_cli-0.6.5}/pyproject.toml +0 -0
- {lithe_cli-0.6.4 → lithe_cli-0.6.5}/setup.cfg +0 -0
- {lithe_cli-0.6.4 → lithe_cli-0.6.5}/tests/test_cli.py +0 -0
|
@@ -13,6 +13,9 @@ used ``input``/``getpass``/readline are all upstream concerns now.
|
|
|
13
13
|
|
|
14
14
|
from __future__ import annotations
|
|
15
15
|
|
|
16
|
+
import re
|
|
17
|
+
import sys
|
|
18
|
+
|
|
16
19
|
from prompt_toolkit import prompt
|
|
17
20
|
from prompt_toolkit.formatted_text import ANSI
|
|
18
21
|
from prompt_toolkit.history import FileHistory, InMemoryHistory
|
|
@@ -27,6 +30,24 @@ _UTF8_HINT = (
|
|
|
27
30
|
"请把终端与 locale 设为 UTF-8(如 export LANG=C.UTF-8)后重试。"
|
|
28
31
|
)
|
|
29
32
|
|
|
33
|
+
_ANSI_RE = re.compile(r"\x1b\[[0-9;]*m")
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _plain_line(message: str) -> str:
|
|
37
|
+
"""Line input when prompt_toolkit cannot run: on Windows its console
|
|
38
|
+
backend (Win32Output/Windows10_Output) needs a real screen buffer and
|
|
39
|
+
raises NoConsoleScreenBufferError when either end is a pipe or redirect —
|
|
40
|
+
POSIX degrades to plain-text output there, Windows does not. No line
|
|
41
|
+
editing exists in a pipe anyway, so the builtin is enough."""
|
|
42
|
+
return input(_ANSI_RE.sub("", message))
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def _pipe_safe() -> bool:
|
|
46
|
+
"""True when both ends are interactive and prompt_toolkit can own them."""
|
|
47
|
+
if sys.platform == "win32":
|
|
48
|
+
return sys.stdout.isatty() and sys.stdin.isatty()
|
|
49
|
+
return True
|
|
50
|
+
|
|
30
51
|
|
|
31
52
|
def history_file():
|
|
32
53
|
"""Where chat history persists, next to the saved endpoint."""
|
|
@@ -47,6 +68,8 @@ def open_history() -> FileHistory:
|
|
|
47
68
|
|
|
48
69
|
def chat_line(message: str, history) -> str:
|
|
49
70
|
"""The chat REPL prompt: colored, history-searchable, paste-safe."""
|
|
71
|
+
if not _pipe_safe():
|
|
72
|
+
return _plain_line(message)
|
|
50
73
|
return prompt(
|
|
51
74
|
ANSI(message),
|
|
52
75
|
history=history,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|