xmyshell 0.2.20__tar.gz → 0.2.21__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.
- {xmyshell-0.2.20/xmyshell.egg-info → xmyshell-0.2.21}/PKG-INFO +1 -1
- {xmyshell-0.2.20 → xmyshell-0.2.21}/pyproject.toml +1 -1
- {xmyshell-0.2.20 → xmyshell-0.2.21}/xmyshell/completer.py +7 -7
- {xmyshell-0.2.20 → xmyshell-0.2.21}/xmyshell/environment.py +14 -4
- {xmyshell-0.2.20 → xmyshell-0.2.21}/xmyshell/kernel.py +21 -21
- {xmyshell-0.2.20 → xmyshell-0.2.21}/xmyshell/keybindings.py +2 -0
- {xmyshell-0.2.20 → xmyshell-0.2.21}/xmyshell/main.py +10 -12
- {xmyshell-0.2.20 → xmyshell-0.2.21/xmyshell.egg-info}/PKG-INFO +1 -1
- {xmyshell-0.2.20 → xmyshell-0.2.21}/LICENSE +0 -0
- {xmyshell-0.2.20 → xmyshell-0.2.21}/README.md +0 -0
- {xmyshell-0.2.20 → xmyshell-0.2.21}/setup.cfg +0 -0
- {xmyshell-0.2.20 → xmyshell-0.2.21}/xmyshell/__init__.py +0 -0
- {xmyshell-0.2.20 → xmyshell-0.2.21}/xmyshell/__main__.py +0 -0
- {xmyshell-0.2.20 → xmyshell-0.2.21}/xmyshell/data/commands.json +0 -0
- {xmyshell-0.2.20 → xmyshell-0.2.21}/xmyshell/init.py +0 -0
- {xmyshell-0.2.20 → xmyshell-0.2.21}/xmyshell/injection.py +0 -0
- {xmyshell-0.2.20 → xmyshell-0.2.21}/xmyshell/meta.py +0 -0
- {xmyshell-0.2.20 → xmyshell-0.2.21}/xmyshell/stubs/__init__.py +0 -0
- {xmyshell-0.2.20 → xmyshell-0.2.21}/xmyshell/stubs/__init__.pyi +0 -0
- {xmyshell-0.2.20 → xmyshell-0.2.21}/xmyshell/stubs/py.typed +0 -0
- {xmyshell-0.2.20 → xmyshell-0.2.21}/xmyshell/themes.py +0 -0
- {xmyshell-0.2.20 → xmyshell-0.2.21}/xmyshell/update.py +0 -0
- {xmyshell-0.2.20 → xmyshell-0.2.21}/xmyshell/utils.py +0 -0
- {xmyshell-0.2.20 → xmyshell-0.2.21}/xmyshell.egg-info/SOURCES.txt +0 -0
- {xmyshell-0.2.20 → xmyshell-0.2.21}/xmyshell.egg-info/dependency_links.txt +0 -0
- {xmyshell-0.2.20 → xmyshell-0.2.21}/xmyshell.egg-info/entry_points.txt +0 -0
- {xmyshell-0.2.20 → xmyshell-0.2.21}/xmyshell.egg-info/requires.txt +0 -0
- {xmyshell-0.2.20 → xmyshell-0.2.21}/xmyshell.egg-info/top_level.txt +0 -0
|
@@ -10,7 +10,7 @@ import pkgutil
|
|
|
10
10
|
from string import whitespace
|
|
11
11
|
from prompt_toolkit.completion import CompleteEvent, Completer, Completion
|
|
12
12
|
from prompt_toolkit.document import Document
|
|
13
|
-
from .environment import
|
|
13
|
+
from .environment import localspace, aliases
|
|
14
14
|
from .utils import truncate
|
|
15
15
|
from pathlib import Path
|
|
16
16
|
|
|
@@ -273,8 +273,8 @@ class ShellCompleter(Completer):
|
|
|
273
273
|
|
|
274
274
|
obj = None
|
|
275
275
|
root = self._last_identifier(parts[start])
|
|
276
|
-
if root in
|
|
277
|
-
obj =
|
|
276
|
+
if root in localspace:
|
|
277
|
+
obj = localspace[root]
|
|
278
278
|
elif hasattr(__builtins__, root):
|
|
279
279
|
obj = getattr(__builtins__, root)
|
|
280
280
|
elif isinstance(__builtins__, dict) and root in __builtins__:
|
|
@@ -323,10 +323,10 @@ class ShellCompleter(Completer):
|
|
|
323
323
|
else:
|
|
324
324
|
builtins_candidates = []
|
|
325
325
|
|
|
326
|
-
candidates = set(
|
|
326
|
+
candidates = set(localspace.keys()) | set(builtins_candidates)
|
|
327
327
|
for name in sorted(candidates) + KEYWORDS:
|
|
328
|
-
if name in
|
|
329
|
-
meta = truncate(type(
|
|
328
|
+
if name in localspace:
|
|
329
|
+
meta = truncate(type(localspace[name]).__name__, MAX_META_LEN)
|
|
330
330
|
elif name in __builtins__:
|
|
331
331
|
meta = truncate(type(__builtins__[name]).__name__, MAX_META_LEN)
|
|
332
332
|
else:
|
|
@@ -518,4 +518,4 @@ class ShellCompleter(Completer):
|
|
|
518
518
|
return completions
|
|
519
519
|
|
|
520
520
|
def completer_init() -> None:
|
|
521
|
-
|
|
521
|
+
localspace["shell_completer"] = ShellCompleter()
|
|
@@ -7,7 +7,17 @@ from typing import Any
|
|
|
7
7
|
from collections.abc import Mapping
|
|
8
8
|
from .utils import XMYSHELL_MAGIC, getcwd, getlogin, HOME_DIR, xmyshell_cat
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
class LocalSpace(dict):
|
|
11
|
+
def __init__(self, readonly):
|
|
12
|
+
super().__init__()
|
|
13
|
+
self._readonly = readonly
|
|
14
|
+
|
|
15
|
+
def __missing__(self, key):
|
|
16
|
+
if key in self._readonly:
|
|
17
|
+
return self._readonly[key]
|
|
18
|
+
raise KeyError(key)
|
|
19
|
+
|
|
20
|
+
localspace: dict[str, Any] = LocalSpace(os.environ)
|
|
11
21
|
aliases: dict[str, str] = {}
|
|
12
22
|
init_environ: dict[str, str] = dict(os.environ)
|
|
13
23
|
SHELL_CMD = ["cmd", "/c"] if os.name == "nt" else ["/bin/sh", "-c"]
|
|
@@ -52,8 +62,8 @@ _init_namespace: dict[str, Any] = {
|
|
|
52
62
|
|
|
53
63
|
|
|
54
64
|
def load_init_namespace() -> None:
|
|
55
|
-
|
|
56
|
-
|
|
65
|
+
localspace.clear()
|
|
66
|
+
localspace.update(_init_namespace)
|
|
57
67
|
|
|
58
68
|
|
|
59
69
|
def update_namespace(values: Mapping[str, object]) -> None:
|
|
@@ -71,5 +81,5 @@ def update_namespace(values: Mapping[str, object]) -> None:
|
|
|
71
81
|
frame.f_locals.update(values)
|
|
72
82
|
return
|
|
73
83
|
depth += 1
|
|
74
|
-
|
|
84
|
+
localspace.update(values) # kernal
|
|
75
85
|
|
|
@@ -7,7 +7,7 @@ import runpy
|
|
|
7
7
|
import subprocess
|
|
8
8
|
import signal
|
|
9
9
|
import shlex
|
|
10
|
-
from .environment import
|
|
10
|
+
from .environment import localspace, aliases, xmyshell_alias, xmyshell_unalias, SHELL_CMD
|
|
11
11
|
from .utils import pywarning, pyerror, getcwd
|
|
12
12
|
from .meta import HELP_MESSAGE
|
|
13
13
|
|
|
@@ -45,7 +45,7 @@ def _run(cmd_line: list[str] | str, **kwargs) -> subprocess.CompletedProcess:
|
|
|
45
45
|
return subprocess.run(cmd_line, **_kwargs_preexec, **kwargs)
|
|
46
46
|
else:
|
|
47
47
|
return subprocess.run(
|
|
48
|
-
|
|
48
|
+
localspace.get("SHELL_CMD", SHELL_CMD) + [cmd_line],
|
|
49
49
|
**_kwargs_preexec,
|
|
50
50
|
**kwargs,
|
|
51
51
|
)
|
|
@@ -53,11 +53,11 @@ def _run(cmd_line: list[str] | str, **kwargs) -> subprocess.CompletedProcess:
|
|
|
53
53
|
def xmyshell_source(path: str) -> None:
|
|
54
54
|
_updated = runpy.run_path(
|
|
55
55
|
path_name=os.path.expanduser(path),
|
|
56
|
-
init_globals=
|
|
56
|
+
init_globals=localspace,
|
|
57
57
|
run_name="__main__",
|
|
58
58
|
)
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
localspace.clear()
|
|
60
|
+
localspace.update(_updated)
|
|
61
61
|
|
|
62
62
|
|
|
63
63
|
def pyeval(cmd_line: str) -> str:
|
|
@@ -89,7 +89,7 @@ def pyeval(cmd_line: str) -> str:
|
|
|
89
89
|
expr = cmd_line[i+1:j-1].strip()
|
|
90
90
|
if expr:
|
|
91
91
|
try:
|
|
92
|
-
val = eval(expr,
|
|
92
|
+
val = eval(expr, localspace, localspace)
|
|
93
93
|
if not isinstance(
|
|
94
94
|
val, (str, bytes, bytearray, memoryview)
|
|
95
95
|
) and isinstance(val, (Sequence, Generator)):
|
|
@@ -133,14 +133,14 @@ def xmyshell_raw_command(cmd_line: str) -> int | None:
|
|
|
133
133
|
pyerror("pyexec: missing code")
|
|
134
134
|
return -1
|
|
135
135
|
try:
|
|
136
|
-
exec(code,
|
|
137
|
-
|
|
136
|
+
exec(code, localspace, localspace)
|
|
137
|
+
localspace["last_error"] = None
|
|
138
138
|
return 0
|
|
139
139
|
except Exception as e:
|
|
140
140
|
import traceback
|
|
141
141
|
|
|
142
|
-
|
|
143
|
-
|
|
142
|
+
localspace["last_error"] = e
|
|
143
|
+
localspace["last_traceback"] = traceback.format_exc()
|
|
144
144
|
pyerror(f"{type(e).__name__}: {e}")
|
|
145
145
|
return -1
|
|
146
146
|
|
|
@@ -166,7 +166,7 @@ def xmyshell_raw_command(cmd_line: str) -> int | None:
|
|
|
166
166
|
try:
|
|
167
167
|
altname, alias_target = code.split('=', 1)
|
|
168
168
|
altname = altname.strip()
|
|
169
|
-
xmyshell_alias(altname, eval(alias_target,
|
|
169
|
+
xmyshell_alias(altname, eval(alias_target, localspace, {}))
|
|
170
170
|
return 0
|
|
171
171
|
except Exception as e:
|
|
172
172
|
pyerror(f"{type(e).__name__}: {e}")
|
|
@@ -186,15 +186,15 @@ def xmyshell_raw_command(cmd_line: str) -> int | None:
|
|
|
186
186
|
pyerror("print: missing expression")
|
|
187
187
|
return -1
|
|
188
188
|
try:
|
|
189
|
-
result = eval(expr,
|
|
189
|
+
result = eval(expr, localspace, localspace)
|
|
190
190
|
print(result)
|
|
191
|
-
|
|
192
|
-
|
|
191
|
+
localspace["last_error"] = None
|
|
192
|
+
localspace["ans"] = result
|
|
193
193
|
return 0
|
|
194
194
|
except Exception as e:
|
|
195
195
|
import traceback
|
|
196
|
-
|
|
197
|
-
|
|
196
|
+
localspace["last_error"] = e
|
|
197
|
+
localspace["last_traceback"] = traceback.format_exc()
|
|
198
198
|
pyerror(f"{type(e).__name__}: {e}")
|
|
199
199
|
return -1
|
|
200
200
|
|
|
@@ -226,7 +226,7 @@ def xmyshell_raw_command(cmd_line: str) -> int | None:
|
|
|
226
226
|
|
|
227
227
|
if command.startswith("import") or command.startswith("from"):
|
|
228
228
|
try:
|
|
229
|
-
exec(cmd_line,
|
|
229
|
+
exec(cmd_line, localspace, localspace)
|
|
230
230
|
return 0
|
|
231
231
|
except Exception as e:
|
|
232
232
|
pyerror(f"{type(e).__name__}: {e}")
|
|
@@ -248,7 +248,7 @@ def xmyshell(cmd_line: str) -> int:
|
|
|
248
248
|
if sh_cmd:
|
|
249
249
|
with _no_interrupt():
|
|
250
250
|
proc = subprocess.Popen(
|
|
251
|
-
|
|
251
|
+
localspace.get("SHELL_CMD", SHELL_CMD) + [sh_cmd],
|
|
252
252
|
env=os.environ,
|
|
253
253
|
stdin=subprocess.PIPE,
|
|
254
254
|
stdout=subprocess.PIPE,
|
|
@@ -266,7 +266,7 @@ def xmyshell(cmd_line: str) -> int:
|
|
|
266
266
|
sys.stdout = old_stdout
|
|
267
267
|
if target_var:
|
|
268
268
|
result, _ = proc.communicate()
|
|
269
|
-
|
|
269
|
+
localspace[target_var] = result
|
|
270
270
|
return proc.returncode
|
|
271
271
|
else:
|
|
272
272
|
return proc.wait()
|
|
@@ -278,7 +278,7 @@ def xmyshell(cmd_line: str) -> int:
|
|
|
278
278
|
with redirect_stdout(f):
|
|
279
279
|
return_code = xmyshell_raw_command(cmd_line)
|
|
280
280
|
if return_code is not None:
|
|
281
|
-
|
|
281
|
+
localspace[target_var] = f.getvalue()
|
|
282
282
|
return return_code
|
|
283
283
|
else:
|
|
284
284
|
return_code = xmyshell_raw_command(cmd_line)
|
|
@@ -349,7 +349,7 @@ def xmyshell(cmd_line: str) -> int:
|
|
|
349
349
|
result = _run(
|
|
350
350
|
cmd_line, env=os.environ, capture_output=True, text=True
|
|
351
351
|
)
|
|
352
|
-
|
|
352
|
+
localspace[target_var] = result.stdout
|
|
353
353
|
else:
|
|
354
354
|
result = _run(cmd_line, env=os.environ)
|
|
355
355
|
|
|
@@ -371,6 +371,8 @@ def _(event: KeyPressEvent) -> None:
|
|
|
371
371
|
text = buffer.complete_state.current_completion.text
|
|
372
372
|
buffer.complete_state.current_completion.text = text.rstrip()
|
|
373
373
|
buffer.apply_completion(buffer.complete_state.current_completion)
|
|
374
|
+
else:
|
|
375
|
+
buffer.insert_text(" ")
|
|
374
376
|
|
|
375
377
|
@bindings.add(Keys.Enter)
|
|
376
378
|
def handle_enter(event):
|
|
@@ -10,7 +10,7 @@ from prompt_toolkit import HTML, PromptSession
|
|
|
10
10
|
from prompt_toolkit.history import FileHistory
|
|
11
11
|
from prompt_toolkit.auto_suggest import AutoSuggestFromHistory
|
|
12
12
|
from .meta import WELCOME_MESSAGE
|
|
13
|
-
from .environment import
|
|
13
|
+
from .environment import localspace
|
|
14
14
|
from .keybindings import (
|
|
15
15
|
bindings,
|
|
16
16
|
on_cursor_position_changed,
|
|
@@ -21,13 +21,11 @@ from .init import xmyshell_init
|
|
|
21
21
|
from .kernel import pyeval, xmyshell
|
|
22
22
|
from .injection import inject
|
|
23
23
|
|
|
24
|
-
def _continuation(width, line_number, is_soft_wrap):
|
|
25
|
-
return HTML("<style fg='ansidarkgray'>" + '.' * width + "</style>")
|
|
26
24
|
|
|
27
25
|
def xmyshell_main() -> None:
|
|
28
26
|
xmyshell_init()
|
|
29
27
|
|
|
30
|
-
if
|
|
28
|
+
if localspace.get("SHOW_WELCOME"):
|
|
31
29
|
print(WELCOME_MESSAGE)
|
|
32
30
|
print(f"Initialized with {(time_ns() - _start_time) // 1_000_000}ms.")
|
|
33
31
|
|
|
@@ -38,7 +36,7 @@ def xmyshell_main() -> None:
|
|
|
38
36
|
complete_while_typing=True,
|
|
39
37
|
key_bindings=bindings,
|
|
40
38
|
multiline=True,
|
|
41
|
-
prompt_continuation=
|
|
39
|
+
prompt_continuation="",
|
|
42
40
|
)
|
|
43
41
|
session.default_buffer.on_cursor_position_changed += on_cursor_position_changed
|
|
44
42
|
session.default_buffer.on_text_changed += on_text_changed
|
|
@@ -47,16 +45,16 @@ def xmyshell_main() -> None:
|
|
|
47
45
|
while True:
|
|
48
46
|
try:
|
|
49
47
|
cmd_line: str = session.prompt(
|
|
50
|
-
HTML(pyeval(
|
|
51
|
-
rprompt=HTML(pyeval(
|
|
52
|
-
completer=
|
|
53
|
-
placeholder=HTML(
|
|
54
|
-
style=Style.from_dict(
|
|
48
|
+
HTML(pyeval(localspace["shell_prompt"])),
|
|
49
|
+
rprompt=HTML(pyeval(localspace["shell_rprompt"])),
|
|
50
|
+
completer=localspace["shell_completer"],
|
|
51
|
+
placeholder=HTML(localspace["prompt_placeholder"]),
|
|
52
|
+
style=Style.from_dict(localspace["prompt_style"]),
|
|
55
53
|
pre_run=inject,
|
|
56
54
|
)
|
|
57
55
|
start_time = time_ns()
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
localspace["exit_code"] = xmyshell(cmd_line)
|
|
57
|
+
localspace["exec_duration"] = time_ns() - start_time
|
|
60
58
|
clean_buffer()
|
|
61
59
|
except KeyboardInterrupt:
|
|
62
60
|
print("Ctrl-C")
|
|
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
|
|
File without changes
|
|
File without changes
|