xmyshell 0.2.19__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.
Files changed (28) hide show
  1. {xmyshell-0.2.19/xmyshell.egg-info → xmyshell-0.2.21}/PKG-INFO +11 -2
  2. {xmyshell-0.2.19 → xmyshell-0.2.21}/README.md +10 -1
  3. {xmyshell-0.2.19 → xmyshell-0.2.21}/pyproject.toml +1 -1
  4. {xmyshell-0.2.19 → xmyshell-0.2.21}/xmyshell/completer.py +7 -7
  5. {xmyshell-0.2.19 → xmyshell-0.2.21}/xmyshell/environment.py +14 -4
  6. {xmyshell-0.2.19 → xmyshell-0.2.21}/xmyshell/kernel.py +22 -22
  7. {xmyshell-0.2.19 → xmyshell-0.2.21}/xmyshell/keybindings.py +19 -0
  8. {xmyshell-0.2.19 → xmyshell-0.2.21}/xmyshell/main.py +12 -9
  9. {xmyshell-0.2.19 → xmyshell-0.2.21}/xmyshell/meta.py +1 -0
  10. {xmyshell-0.2.19 → xmyshell-0.2.21/xmyshell.egg-info}/PKG-INFO +11 -2
  11. {xmyshell-0.2.19 → xmyshell-0.2.21}/LICENSE +0 -0
  12. {xmyshell-0.2.19 → xmyshell-0.2.21}/setup.cfg +0 -0
  13. {xmyshell-0.2.19 → xmyshell-0.2.21}/xmyshell/__init__.py +0 -0
  14. {xmyshell-0.2.19 → xmyshell-0.2.21}/xmyshell/__main__.py +0 -0
  15. {xmyshell-0.2.19 → xmyshell-0.2.21}/xmyshell/data/commands.json +0 -0
  16. {xmyshell-0.2.19 → xmyshell-0.2.21}/xmyshell/init.py +0 -0
  17. {xmyshell-0.2.19 → xmyshell-0.2.21}/xmyshell/injection.py +0 -0
  18. {xmyshell-0.2.19 → xmyshell-0.2.21}/xmyshell/stubs/__init__.py +0 -0
  19. {xmyshell-0.2.19 → xmyshell-0.2.21}/xmyshell/stubs/__init__.pyi +0 -0
  20. {xmyshell-0.2.19 → xmyshell-0.2.21}/xmyshell/stubs/py.typed +0 -0
  21. {xmyshell-0.2.19 → xmyshell-0.2.21}/xmyshell/themes.py +0 -0
  22. {xmyshell-0.2.19 → xmyshell-0.2.21}/xmyshell/update.py +0 -0
  23. {xmyshell-0.2.19 → xmyshell-0.2.21}/xmyshell/utils.py +0 -0
  24. {xmyshell-0.2.19 → xmyshell-0.2.21}/xmyshell.egg-info/SOURCES.txt +0 -0
  25. {xmyshell-0.2.19 → xmyshell-0.2.21}/xmyshell.egg-info/dependency_links.txt +0 -0
  26. {xmyshell-0.2.19 → xmyshell-0.2.21}/xmyshell.egg-info/entry_points.txt +0 -0
  27. {xmyshell-0.2.19 → xmyshell-0.2.21}/xmyshell.egg-info/requires.txt +0 -0
  28. {xmyshell-0.2.19 → xmyshell-0.2.21}/xmyshell.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: xmyshell
3
- Version: 0.2.19
3
+ Version: 0.2.21
4
4
  Summary: XmyShell is a shell-like tool built on top of prompt_toolkit which provides a persistent Python runtime.
5
5
  Requires-Python: >=3.12
6
6
  Description-Content-Type: text/markdown
@@ -126,8 +126,16 @@ Here is an example (though there are other ways to do this, it is just an exampl
126
126
  ❯ pip install {cat("requirements.txt").splitlines()}
127
127
  ```
128
128
 
129
+ - Multiline input with ending `\`.
130
+ ```
131
+ [~] $ pyexec
132
+ ......
133
+ ......def foo():
134
+ ...... print("Hello!")
135
+ [~] $ pyexec foo()
136
+ Hello!
137
+ ```
129
138
 
130
- - Syntax highlighting via `prompt_toolkit`
131
139
  - Powerful auto-completion, history search, and automatic bracket/quote pairing
132
140
  - Startup configuration: `~/.xmyshell/config.py` loaded at launch
133
141
  - Cross-platform (Windows, Linux, macOS)
@@ -190,6 +198,7 @@ The path of config file.
190
198
  - `Ctrl+R` -> Reverse incremental searching (history).
191
199
  - `Ctrl+Z` -> Undo.
192
200
  - `Ctrl+Y` -> Redo.
201
+ - `Ctrl+G` -> Hide completions.
193
202
  - `Ctrl+D` -> Exit XmyShell.
194
203
  - Auto bracket/parenthesis/quote pairing
195
204
 
@@ -116,8 +116,16 @@ Here is an example (though there are other ways to do this, it is just an exampl
116
116
  ❯ pip install {cat("requirements.txt").splitlines()}
117
117
  ```
118
118
 
119
+ - Multiline input with ending `\`.
120
+ ```
121
+ [~] $ pyexec
122
+ ......
123
+ ......def foo():
124
+ ...... print("Hello!")
125
+ [~] $ pyexec foo()
126
+ Hello!
127
+ ```
119
128
 
120
- - Syntax highlighting via `prompt_toolkit`
121
129
  - Powerful auto-completion, history search, and automatic bracket/quote pairing
122
130
  - Startup configuration: `~/.xmyshell/config.py` loaded at launch
123
131
  - Cross-platform (Windows, Linux, macOS)
@@ -180,6 +188,7 @@ The path of config file.
180
188
  - `Ctrl+R` -> Reverse incremental searching (history).
181
189
  - `Ctrl+Z` -> Undo.
182
190
  - `Ctrl+Y` -> Redo.
191
+ - `Ctrl+G` -> Hide completions.
183
192
  - `Ctrl+D` -> Exit XmyShell.
184
193
  - Auto bracket/parenthesis/quote pairing
185
194
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "xmyshell"
3
- version = "0.2.19"
3
+ version = "0.2.21"
4
4
  description = "XmyShell is a shell-like tool built on top of prompt_toolkit which provides a persistent Python runtime."
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.12"
@@ -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 namespace, aliases
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 namespace:
277
- obj = namespace[root]
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(namespace.keys()) | set(builtins_candidates)
326
+ candidates = set(localspace.keys()) | set(builtins_candidates)
327
327
  for name in sorted(candidates) + KEYWORDS:
328
- if name in namespace:
329
- meta = truncate(type(namespace[name]).__name__, MAX_META_LEN)
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
- namespace["shell_completer"] = ShellCompleter()
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
- namespace: dict[str, Any] = {}
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
- namespace.clear()
56
- namespace.update(_init_namespace)
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
- namespace.update(values) # kernal
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 namespace, aliases, xmyshell_alias, xmyshell_unalias, SHELL_CMD
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
- namespace.get("SHELL_CMD", SHELL_CMD) + [cmd_line],
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=namespace,
56
+ init_globals=localspace,
57
57
  run_name="__main__",
58
58
  )
59
- namespace.clear()
60
- namespace.update(_updated)
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, dict(os.environ), namespace)
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, dict(os.environ), namespace)
137
- namespace["last_error"] = None
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
- namespace["last_error"] = e
143
- namespace["last_traceback"] = traceback.format_exc()
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, namespace, {}))
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, dict(os.environ), namespace)
189
+ result = eval(expr, localspace, localspace)
190
190
  print(result)
191
- namespace["last_error"] = None
192
- namespace["ans"] = result
191
+ localspace["last_error"] = None
192
+ localspace["ans"] = result
193
193
  return 0
194
194
  except Exception as e:
195
195
  import traceback
196
- namespace["last_error"] = e
197
- namespace["last_traceback"] = traceback.format_exc()
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, dict(os.environ), namespace)
229
+ exec(cmd_line, localspace, localspace)
230
230
  return 0
231
231
  except Exception as e:
232
232
  pyerror(f"{type(e).__name__}: {e}")
@@ -234,7 +234,7 @@ def xmyshell_raw_command(cmd_line: str) -> int | None:
234
234
 
235
235
 
236
236
  def xmyshell(cmd_line: str) -> int:
237
- cmd_line = cmd_line.strip()
237
+ cmd_line = cmd_line.strip().replace("\\\n", "\t")
238
238
  if not cmd_line:
239
239
  return 0
240
240
 
@@ -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
- namespace.get("SHELL_CMD", SHELL_CMD) + [sh_cmd],
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
- namespace[target_var] = result
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
- namespace[target_var] = f.getvalue()
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
- namespace[target_var] = result.stdout
352
+ localspace[target_var] = result.stdout
353
353
  else:
354
354
  result = _run(cmd_line, env=os.environ)
355
355
 
@@ -1,5 +1,6 @@
1
1
  import time
2
2
  from prompt_toolkit.buffer import Buffer
3
+ from prompt_toolkit.filters import has_completions
3
4
  from prompt_toolkit.key_binding import KeyBindings, KeyPressEvent
4
5
  from prompt_toolkit.selection import SelectionState
5
6
  from prompt_toolkit.keys import Keys
@@ -370,3 +371,21 @@ def _(event: KeyPressEvent) -> None:
370
371
  text = buffer.complete_state.current_completion.text
371
372
  buffer.complete_state.current_completion.text = text.rstrip()
372
373
  buffer.apply_completion(buffer.complete_state.current_completion)
374
+ else:
375
+ buffer.insert_text(" ")
376
+
377
+ @bindings.add(Keys.Enter)
378
+ def handle_enter(event):
379
+ buffer = event.current_buffer
380
+ current_line = buffer.document.current_line_before_cursor
381
+
382
+ if current_line.rstrip().endswith("\\"):
383
+ stripped = current_line.rstrip()
384
+ buffer.delete_before_cursor(count=len(current_line) - len(stripped) + 1)
385
+ buffer.insert_text("\n")
386
+ else:
387
+ buffer.validate_and_handle()
388
+
389
+ @bindings.add("escape", filter=has_completions, eager=True)
390
+ def cancel_completion(event):
391
+ event.current_buffer.cancel_completion()
@@ -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 namespace
13
+ from .environment import localspace
14
14
  from .keybindings import (
15
15
  bindings,
16
16
  on_cursor_position_changed,
@@ -21,10 +21,11 @@ from .init import xmyshell_init
21
21
  from .kernel import pyeval, xmyshell
22
22
  from .injection import inject
23
23
 
24
+
24
25
  def xmyshell_main() -> None:
25
26
  xmyshell_init()
26
27
 
27
- if namespace.get("SHOW_WELCOME"):
28
+ if localspace.get("SHOW_WELCOME"):
28
29
  print(WELCOME_MESSAGE)
29
30
  print(f"Initialized with {(time_ns() - _start_time) // 1_000_000}ms.")
30
31
 
@@ -34,6 +35,8 @@ def xmyshell_main() -> None:
34
35
  complete_in_thread=True,
35
36
  complete_while_typing=True,
36
37
  key_bindings=bindings,
38
+ multiline=True,
39
+ prompt_continuation="",
37
40
  )
38
41
  session.default_buffer.on_cursor_position_changed += on_cursor_position_changed
39
42
  session.default_buffer.on_text_changed += on_text_changed
@@ -42,16 +45,16 @@ def xmyshell_main() -> None:
42
45
  while True:
43
46
  try:
44
47
  cmd_line: str = session.prompt(
45
- HTML(pyeval(namespace["shell_prompt"])),
46
- rprompt=HTML(pyeval(namespace["shell_rprompt"])),
47
- completer=namespace["shell_completer"],
48
- placeholder=HTML(namespace["prompt_placeholder"]),
49
- style=Style.from_dict(namespace["prompt_style"]),
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"]),
50
53
  pre_run=inject,
51
54
  )
52
55
  start_time = time_ns()
53
- namespace["exit_code"] = xmyshell(cmd_line)
54
- namespace["exec_duration"] = time_ns() - start_time
56
+ localspace["exit_code"] = xmyshell(cmd_line)
57
+ localspace["exec_duration"] = time_ns() - start_time
55
58
  clean_buffer()
56
59
  except KeyboardInterrupt:
57
60
  print("Ctrl-C")
@@ -82,4 +82,5 @@ HELP_MESSAGE = f"""{BOLD}{CYAN}
82
82
  {MAGENTA}Ctrl+R {CYAN}Reverse incremental searching (history).
83
83
  {MAGENTA}Ctrl+Z {CYAN}Undo.
84
84
  {MAGENTA}Ctrl+Y {CYAN}Redo.
85
+ {MAGENTA}Ctrl+G {CYAN}Hide completions.
85
86
  {MAGENTA}Ctrl+D {CYAN}Exit XmyShell.{RESET}"""
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: xmyshell
3
- Version: 0.2.19
3
+ Version: 0.2.21
4
4
  Summary: XmyShell is a shell-like tool built on top of prompt_toolkit which provides a persistent Python runtime.
5
5
  Requires-Python: >=3.12
6
6
  Description-Content-Type: text/markdown
@@ -126,8 +126,16 @@ Here is an example (though there are other ways to do this, it is just an exampl
126
126
  ❯ pip install {cat("requirements.txt").splitlines()}
127
127
  ```
128
128
 
129
+ - Multiline input with ending `\`.
130
+ ```
131
+ [~] $ pyexec
132
+ ......
133
+ ......def foo():
134
+ ...... print("Hello!")
135
+ [~] $ pyexec foo()
136
+ Hello!
137
+ ```
129
138
 
130
- - Syntax highlighting via `prompt_toolkit`
131
139
  - Powerful auto-completion, history search, and automatic bracket/quote pairing
132
140
  - Startup configuration: `~/.xmyshell/config.py` loaded at launch
133
141
  - Cross-platform (Windows, Linux, macOS)
@@ -190,6 +198,7 @@ The path of config file.
190
198
  - `Ctrl+R` -> Reverse incremental searching (history).
191
199
  - `Ctrl+Z` -> Undo.
192
200
  - `Ctrl+Y` -> Redo.
201
+ - `Ctrl+G` -> Hide completions.
193
202
  - `Ctrl+D` -> Exit XmyShell.
194
203
  - Auto bracket/parenthesis/quote pairing
195
204
 
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes