xmyshell 0.2.18__tar.gz → 0.2.20__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 (29) hide show
  1. {xmyshell-0.2.18/xmyshell.egg-info → xmyshell-0.2.20}/PKG-INFO +11 -2
  2. {xmyshell-0.2.18 → xmyshell-0.2.20}/README.md +10 -1
  3. {xmyshell-0.2.18 → xmyshell-0.2.20}/pyproject.toml +1 -1
  4. {xmyshell-0.2.18 → xmyshell-0.2.20}/xmyshell/kernel.py +1 -1
  5. {xmyshell-0.2.18 → xmyshell-0.2.20}/xmyshell/keybindings.py +17 -0
  6. {xmyshell-0.2.18 → xmyshell-0.2.20}/xmyshell/main.py +5 -0
  7. xmyshell-0.2.20/xmyshell/meta.py +86 -0
  8. {xmyshell-0.2.18 → xmyshell-0.2.20/xmyshell.egg-info}/PKG-INFO +11 -2
  9. xmyshell-0.2.18/xmyshell/meta.py +0 -74
  10. {xmyshell-0.2.18 → xmyshell-0.2.20}/LICENSE +0 -0
  11. {xmyshell-0.2.18 → xmyshell-0.2.20}/setup.cfg +0 -0
  12. {xmyshell-0.2.18 → xmyshell-0.2.20}/xmyshell/__init__.py +0 -0
  13. {xmyshell-0.2.18 → xmyshell-0.2.20}/xmyshell/__main__.py +0 -0
  14. {xmyshell-0.2.18 → xmyshell-0.2.20}/xmyshell/completer.py +0 -0
  15. {xmyshell-0.2.18 → xmyshell-0.2.20}/xmyshell/data/commands.json +0 -0
  16. {xmyshell-0.2.18 → xmyshell-0.2.20}/xmyshell/environment.py +0 -0
  17. {xmyshell-0.2.18 → xmyshell-0.2.20}/xmyshell/init.py +0 -0
  18. {xmyshell-0.2.18 → xmyshell-0.2.20}/xmyshell/injection.py +0 -0
  19. {xmyshell-0.2.18 → xmyshell-0.2.20}/xmyshell/stubs/__init__.py +0 -0
  20. {xmyshell-0.2.18 → xmyshell-0.2.20}/xmyshell/stubs/__init__.pyi +0 -0
  21. {xmyshell-0.2.18 → xmyshell-0.2.20}/xmyshell/stubs/py.typed +0 -0
  22. {xmyshell-0.2.18 → xmyshell-0.2.20}/xmyshell/themes.py +0 -0
  23. {xmyshell-0.2.18 → xmyshell-0.2.20}/xmyshell/update.py +0 -0
  24. {xmyshell-0.2.18 → xmyshell-0.2.20}/xmyshell/utils.py +0 -0
  25. {xmyshell-0.2.18 → xmyshell-0.2.20}/xmyshell.egg-info/SOURCES.txt +0 -0
  26. {xmyshell-0.2.18 → xmyshell-0.2.20}/xmyshell.egg-info/dependency_links.txt +0 -0
  27. {xmyshell-0.2.18 → xmyshell-0.2.20}/xmyshell.egg-info/entry_points.txt +0 -0
  28. {xmyshell-0.2.18 → xmyshell-0.2.20}/xmyshell.egg-info/requires.txt +0 -0
  29. {xmyshell-0.2.18 → xmyshell-0.2.20}/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.18
3
+ Version: 0.2.20
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.18"
3
+ version = "0.2.20"
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"
@@ -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
 
@@ -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,19 @@ 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
+
375
+ @bindings.add(Keys.Enter)
376
+ def handle_enter(event):
377
+ buffer = event.current_buffer
378
+ current_line = buffer.document.current_line_before_cursor
379
+
380
+ if current_line.rstrip().endswith("\\"):
381
+ stripped = current_line.rstrip()
382
+ buffer.delete_before_cursor(count=len(current_line) - len(stripped) + 1)
383
+ buffer.insert_text("\n")
384
+ else:
385
+ buffer.validate_and_handle()
386
+
387
+ @bindings.add("escape", filter=has_completions, eager=True)
388
+ def cancel_completion(event):
389
+ event.current_buffer.cancel_completion()
@@ -21,6 +21,9 @@ 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
  def xmyshell_main() -> None:
25
28
  xmyshell_init()
26
29
 
@@ -34,6 +37,8 @@ def xmyshell_main() -> None:
34
37
  complete_in_thread=True,
35
38
  complete_while_typing=True,
36
39
  key_bindings=bindings,
40
+ multiline=True,
41
+ prompt_continuation=_continuation,
37
42
  )
38
43
  session.default_buffer.on_cursor_position_changed += on_cursor_position_changed
39
44
  session.default_buffer.on_text_changed += on_text_changed
@@ -0,0 +1,86 @@
1
+ from importlib.metadata import version
2
+
3
+ # ANSI color codes
4
+ RESET = "\033[0m"
5
+ BOLD = "\033[1m"
6
+ NOBOLD = "\033[22m"
7
+ CYAN = "\033[36m"
8
+ GREEN = "\033[92m"
9
+ YELLOW = "\033[93m"
10
+ BLUE = "\033[94m"
11
+ MAGENTA = "\033[95m"
12
+
13
+ NAME = "xmyshell"
14
+ DISPLAY_NAME = "XmyShell"
15
+ VERSION = version(NAME)
16
+ AUTHOR = "CaptainSuo"
17
+ EMAIL = "captainsuo@outlook.com"
18
+ WELCOME_MESSAGE = f"""{BOLD}{BLUE}{DISPLAY_NAME} {CYAN}{VERSION}{RESET}"""
19
+
20
+ HELP_MESSAGE = f"""{BOLD}{CYAN}
21
+ ███╗ ███╗ ███╗ ███╗ ██╗ ██╗ ███████╗ ██╗ ██╗ ███████╗ ██╗ ██╗
22
+ ╚═██╗██╔═╝ ████╗ ████║ ╚██╗ ██╔╝ ██╔════╝ ██║ ██║ ██╔════╝ ██║ ██║
23
+ ╚███╔╝ ██╔████╔██║ ╚████╔╝ ███████╗ ████████║ ██████╗ ██║ ██║
24
+ ██╔██╗ ██║╚██╔╝██║ ╚██╔╝ ╚════██║ ██╔═══██║ ██╔═══╝ ██║ ██║
25
+ ███╔╝ ███╗ ██║ ╚═╝ ██║ ██║ ███████║ ██║ ██║ ███████╗ ███████╗ ███████╗
26
+ ╚══╝ ╚══╝ ╚═╝ ╚═╝ ╚═╝ ╚══════╝ ╚═╝ ╚═╝ ╚══════╝ ╚══════╝ ╚══════╝
27
+ {RESET}
28
+ {WELCOME_MESSAGE}
29
+
30
+ {BOLD}{YELLOW}Built-in Commands{BOLD}{CYAN}
31
+ {BOLD}{GREEN}help{CYAN} {NOBOLD}Show help documents.
32
+ {BOLD}{GREEN}print{CYAN} <expr> {NOBOLD}Evaluate and print a Python expression.
33
+ {BOLD}{GREEN}pyexec{CYAN} <stmt> {NOBOLD}Execute a Python statement.
34
+ {BOLD}{GREEN}source{CYAN} <file.py> {NOBOLD}Run a Python script in the current namespace.
35
+ {BOLD}{GREEN}export{CYAN} <NAME>=<value> {NOBOLD}Set an environment variable (supports {{expr}}).
36
+ {BOLD}{GREEN}import{CYAN} <module> [as <alt>] {NOBOLD}Import a Python module.
37
+ {BOLD}{GREEN}from{CYAN} <module> import <names> {NOBOLD}Import names from a module.
38
+ {BOLD}{GREEN}reload{CYAN} {NOBOLD}Reload environment.
39
+ {BOLD}{GREEN}update{CYAN} [<version>] {NOBOLD}Update xmyshell.
40
+ {BOLD}{GREEN}cd{CYAN} <dir> {NOBOLD}Change directory (supports {{expr}}).
41
+ {BOLD}{GREEN}pwd{CYAN} {NOBOLD}Print working directory.
42
+ {BOLD}{GREEN}clear{CYAN} {NOBOLD}Clear the terminal screen.
43
+ {BOLD}{GREEN}alias{CYAN} altname=<cmd> {NOBOLD}Create an alias command.
44
+ {BOLD}{GREEN}unalias{CYAN} altname {NOBOLD}Remove an alias command.
45
+ {BOLD}{GREEN}exit{CYAN} {NOBOLD}Exit XmyShell.
46
+
47
+ {BOLD}{YELLOW}Inline Python{NOBOLD}{CYAN}
48
+ Use {{expression}} anywhere in a command to expand its result.
49
+ {BOLD}{MAGENTA}Example{NOBOLD}{CYAN} mkdir {{" ".join(f"test{{i}}" for i in range(3))}}
50
+ Escape braces as {{{{ and }}}}.
51
+
52
+ {BOLD}{YELLOW}IO{NOBOLD}{CYAN}
53
+ Append => variable to a command to capture its output while still
54
+ displaying it.
55
+ {BOLD}{MAGENTA}Example{NOBOLD}{CYAN} which python => path
56
+ Redirect the output of Python commands (print, pyexec) with |>
57
+ {BOLD}{MAGENTA}Example{NOBOLD}{CYAN} print "\\n".join(str(i) for i in range(100)) |> grep 42
58
+
59
+ {BOLD}{YELLOW}Helper Functions{NOBOLD}{CYAN}
60
+ {BLUE}getlogin{CYAN}() current username
61
+ {BLUE}getcwd{CYAN}() current working directory
62
+ {BLUE}dirname{CYAN}(p) parent directory of path
63
+ {BLUE}basename{CYAN}(p) final component of path
64
+ {BLUE}cat{CYAN}(file) Shortcut for open(file).read().
65
+ {BLUE}alias{CYAN}(altname, cmd) Same as the command.
66
+ {BLUE}unalias{CYAN}(altname) Same as the command.
67
+
68
+ {BOLD}{YELLOW}Built-in variables{NOBOLD}{CYAN}
69
+ {BLUE}exit_code{CYAN} The exit code of the last command.
70
+ {BLUE}exec_duration{CYAN} The duration which last command took.
71
+ {BLUE}last_error{CYAN} The error raised from last Python operation (if exists).
72
+ {BLUE}last_traceback{CYAN} The traceback of last Python operation (if exists).
73
+ {BLUE}ans{CYAN} The result from last print command.
74
+ {BLUE}HOME_DIR{CYAN} The home directory, similar to "~".
75
+ {BLUE}PROFILE{CYAN} The path of config file.
76
+ {BLUE}SHOW_WELCOME{CYAN} Toggle whether to show welcome message.
77
+ {BLUE}SHELL_CMD{CYAN} Shell command line prefix, e.g. ["cmd", "/c"]
78
+
79
+ {BOLD}{YELLOW}Keyboard Shortcuts{NOBOLD}{CYAN}
80
+ {MAGENTA}↑↓ {CYAN}Navigate through command history.
81
+ {MAGENTA}→ {CYAN}Apply selected history entry to the prompt.
82
+ {MAGENTA}Ctrl+R {CYAN}Reverse incremental searching (history).
83
+ {MAGENTA}Ctrl+Z {CYAN}Undo.
84
+ {MAGENTA}Ctrl+Y {CYAN}Redo.
85
+ {MAGENTA}Ctrl+G {CYAN}Hide completions.
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.18
3
+ Version: 0.2.20
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
 
@@ -1,74 +0,0 @@
1
- from importlib.metadata import version
2
-
3
- NAME = "xmyshell"
4
- DISPLAY_NAME = "XmyShell"
5
- VERSION = version(NAME)
6
- AUTHOR = "CaptainSuo"
7
- EMAIL = "captainsuo@outlook.com"
8
- WELCOME_MESSAGE = f"""{DISPLAY_NAME} {VERSION}"""
9
- HELP_MESSAGE = f"""\033[1;36m
10
- ███╗ ███╗ ███╗ ███╗ ██╗ ██╗ ███████╗ ██╗ ██╗ ███████╗ ██╗ ██╗
11
- ╚═██╗██╔═╝ ████╗ ████║ ╚██╗ ██╔╝ ██╔════╝ ██║ ██║ ██╔════╝ ██║ ██║
12
- ╚███╔╝ ██╔████╔██║ ╚████╔╝ ███████╗ ████████║ ██████╗ ██║ ██║
13
- ██╔██╗ ██║╚██╔╝██║ ╚██╔╝ ╚════██║ ██╔═══██║ ██╔═══╝ ██║ ██║
14
- ███╔╝ ███╗ ██║ ╚═╝ ██║ ██║ ███████║ ██║ ██║ ███████╗ ███████╗ ███████╗
15
- ╚══╝ ╚══╝ ╚═╝ ╚═╝ ╚═╝ ╚══════╝ ╚═╝ ╚═╝ ╚══════╝ ╚══════╝ ╚══════╝
16
- \033[0m
17
- {WELCOME_MESSAGE}
18
-
19
- Built-in Commands:
20
- help Show help documents.
21
- print <expr> Evaluate and print a Python expression.
22
- pyexec <stmt> Execute a Python statement (e.g. pyexec x = 1).
23
- source <file.py> Run a Python script in the current namespace.
24
- export <NAME>=<value> Set an environment variable (supports {{expr}}).
25
- import <module> [as <alt>] Import a Python module.
26
- from <module> import <names> Import names from a module.
27
- reload Reload environment (e.g. exit virtualenv).
28
- update [<version>] Update xmyshell (optionally to a specific version).
29
- cd <dir> Change directory (supports {{expr}}).
30
- pwd Print working directory.
31
- clear Clear the terminal screen.
32
- alias altname=<cmd> Create an alias command.
33
- unalias altname Remove an alias command.
34
- exit Exit XmyShell.
35
-
36
- Inline Python:
37
- Use {{expression}} anywhere in a command to expand its result.
38
- Example: mkdir {{" ".join(f"test{{i}}" for i in range(3))}}
39
- Escape braces as {{{{ and }}}}.
40
-
41
- IO:
42
- Append => variable to a command to capture its output while still
43
- displaying it.
44
- Example: which python => path
45
- Redirect the output of Python commands (print, pyexec) with |>
46
- Example: print "\\n".join(str(i) for i in range(100)) |> grep 42
47
-
48
- Helper Functions:
49
- getlogin() - current username
50
- getcwd() - current working directory
51
- dirname(p) - parent directory of path
52
- basename(p) - final component of path
53
- cat(file) - Shortcut for open(file).read().
54
- alias(altname, cmd) - Same as the command.
55
- unalias(altname) - Same as the command.
56
-
57
- Built-in variables:
58
- exit_code - The exit code of the last command.
59
- exec_duration - The duration which last command took.
60
- last_error - The error raised from last Python operation (if exists).
61
- last_traceback - The traceback of last Python operation (if exists).
62
- ans - The result from last print command.
63
- HOME_DIR - The home directory, similar to "~".
64
- PROFILE - The path of config file.
65
- SHOW_WELCOME - Toggle whether to show welcome message.
66
- SHELL_CMD - Shell command line prefix, e.g. ["cmd", "/c"]
67
-
68
- Keyboard Shortcuts:
69
- ↑↓ - Navigate through command history.
70
- → - Apply selected history entry to the prompt.
71
- Ctrl+R - Reverse incremental searching (history).
72
- Ctrl+Z - Undo.
73
- Ctrl+Y - Redo.
74
- Ctrl+D - Exit XmyShell."""
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes