rgwfuncs 0.0.67__py3-none-any.whl → 0.0.69__py3-none-any.whl
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.
- rgwfuncs/interactive_shell_lib.py +49 -6
- {rgwfuncs-0.0.67.dist-info → rgwfuncs-0.0.69.dist-info}/METADATA +1 -1
- {rgwfuncs-0.0.67.dist-info → rgwfuncs-0.0.69.dist-info}/RECORD +7 -7
- {rgwfuncs-0.0.67.dist-info → rgwfuncs-0.0.69.dist-info}/LICENSE +0 -0
- {rgwfuncs-0.0.67.dist-info → rgwfuncs-0.0.69.dist-info}/WHEEL +0 -0
- {rgwfuncs-0.0.67.dist-info → rgwfuncs-0.0.69.dist-info}/entry_points.txt +0 -0
- {rgwfuncs-0.0.67.dist-info → rgwfuncs-0.0.69.dist-info}/top_level.txt +0 -0
@@ -1,7 +1,10 @@
|
|
1
|
+
#!/usr/bin/env python3
|
1
2
|
import code
|
2
3
|
import readline
|
3
4
|
import rlcompleter # noqa: F401
|
4
|
-
import sys
|
5
|
+
import sys
|
6
|
+
import os
|
7
|
+
import atexit
|
5
8
|
from typing import Dict, Any
|
6
9
|
from .df_lib import * # noqa: F401, F403, E402
|
7
10
|
from .algebra_lib import * # noqa: F401, F403, E402
|
@@ -9,18 +12,41 @@ from .str_lib import * # noqa: F401, F403, E402
|
|
9
12
|
from .docs_lib import * # noqa: F401, F403, E402
|
10
13
|
|
11
14
|
|
12
|
-
def interactive_shell(local_vars: Dict[str, Any]) -> None:
|
15
|
+
def interactive_shell(local_vars: Dict[str, Any], shell_color: str = '\033[37m') -> None:
|
13
16
|
"""
|
14
17
|
Launches an interactive prompt for inspecting and modifying local variables, making all methods
|
15
|
-
in the rgwfuncs library available by default.
|
18
|
+
in the rgwfuncs library available by default. Persists command history across sessions.
|
16
19
|
|
17
20
|
Parameters:
|
18
21
|
local_vars (dict): Dictionary of local variables to be available in the interactive shell.
|
22
|
+
shell_color (str): ANSI color code for shell output (default: non-bright white '\033[37m').
|
19
23
|
"""
|
24
|
+
|
25
|
+
def setup_readline(shell_color: str = '\033[37m') -> None:
|
26
|
+
"""Set up readline for command history persistence with a given shell color."""
|
27
|
+
HISTORY_FILE = os.path.expanduser("~/.rgwfuncs_shell_history")
|
28
|
+
readline.set_history_length(1000) # Limit history to 1000 lines
|
29
|
+
readline.parse_and_bind("tab: complete") # Enable tab completion
|
30
|
+
if os.path.exists(HISTORY_FILE):
|
31
|
+
try:
|
32
|
+
readline.read_history_file(HISTORY_FILE)
|
33
|
+
except Exception as e:
|
34
|
+
print(f"{shell_color}Warning: Could not load history file: {e}\033[0m")
|
35
|
+
atexit.register(readline.write_history_file, HISTORY_FILE)
|
36
|
+
|
37
|
+
|
38
|
+
def colorize_output(text: str, shell_color: str) -> str:
|
39
|
+
"""Apply shell color to text if it doesn’t already contain ANSI codes."""
|
40
|
+
if '\033[' not in text:
|
41
|
+
return f"{shell_color}{text}\033[0m"
|
42
|
+
return text
|
43
|
+
|
44
|
+
|
20
45
|
if not isinstance(local_vars, dict):
|
21
46
|
raise TypeError("local_vars must be a dictionary")
|
22
47
|
|
23
|
-
readline
|
48
|
+
# Set up readline for history and completion
|
49
|
+
setup_readline(shell_color)
|
24
50
|
|
25
51
|
# Make imported functions available in the REPL
|
26
52
|
local_vars.update(globals())
|
@@ -28,5 +54,22 @@ def interactive_shell(local_vars: Dict[str, Any]) -> None:
|
|
28
54
|
# Create interactive console with local context
|
29
55
|
console = code.InteractiveConsole(locals=local_vars)
|
30
56
|
|
31
|
-
# Start interactive session
|
32
|
-
|
57
|
+
# Start interactive session with a custom banner and exit message
|
58
|
+
banner = f"{shell_color}Welcome to the rgwfuncs interactive shell.\nUse up/down arrows for command history.\nType 'exit()' or Ctrl+D to quit.\033[0m"
|
59
|
+
exitmsg = f"{shell_color}Goodbye.\033[0m"
|
60
|
+
|
61
|
+
# Save original stdout write function
|
62
|
+
original_write = sys.stdout.write
|
63
|
+
|
64
|
+
# Define a pure function to wrap stdout.write
|
65
|
+
def colored_write(text: str) -> None:
|
66
|
+
original_write(colorize_output(text, shell_color))
|
67
|
+
|
68
|
+
# Temporarily replace stdout.write
|
69
|
+
sys.stdout.write = colored_write
|
70
|
+
|
71
|
+
# Start the interactive session
|
72
|
+
console.interact(banner=banner, exitmsg=exitmsg)
|
73
|
+
|
74
|
+
# Restore original stdout.write after exiting
|
75
|
+
sys.stdout.write = original_write
|
@@ -2,11 +2,11 @@ rgwfuncs/__init__.py,sha256=LSn54Tlyskcb6Wab_wUpPLB6UGMe5LdrB3GU88mDEbU,1712
|
|
2
2
|
rgwfuncs/algebra_lib.py,sha256=rKFITfpWfgdBswnbMUuS41XgndEt-jUVz2ObO_ik7eM,42234
|
3
3
|
rgwfuncs/df_lib.py,sha256=r6T-MwyDq9NAPW1Xf6NzSy7ZFicIKdemR-UKu6TZt5g,71111
|
4
4
|
rgwfuncs/docs_lib.py,sha256=y3wSAOPO3qsA4HZ7xAtW8HimM8w-c8hjcEzMRLJ96ao,1960
|
5
|
-
rgwfuncs/interactive_shell_lib.py,sha256=
|
5
|
+
rgwfuncs/interactive_shell_lib.py,sha256=BYSeaW6MHXknLMS52Uzu2WhsWqeAHs-zcmpzkEevn2g,2927
|
6
6
|
rgwfuncs/str_lib.py,sha256=rtAdRlnSJIu3JhI-tA_A0wCiPK2m-zn5RoGpBxv_g-4,2228
|
7
|
-
rgwfuncs-0.0.
|
8
|
-
rgwfuncs-0.0.
|
9
|
-
rgwfuncs-0.0.
|
10
|
-
rgwfuncs-0.0.
|
11
|
-
rgwfuncs-0.0.
|
12
|
-
rgwfuncs-0.0.
|
7
|
+
rgwfuncs-0.0.69.dist-info/LICENSE,sha256=jLvt20gcUZYB8UOvyBvyKQ1qhYYhD__qP7ZDx2lPFkU,1062
|
8
|
+
rgwfuncs-0.0.69.dist-info/METADATA,sha256=-d8qJ2b_S3qA7y0dzjRHlvkPi-LZE5LosmyDh11peDA,60288
|
9
|
+
rgwfuncs-0.0.69.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
10
|
+
rgwfuncs-0.0.69.dist-info/entry_points.txt,sha256=j-c5IOPIQ0252EaOV6j6STio56sbXl2C4ym_fQ0lXx0,43
|
11
|
+
rgwfuncs-0.0.69.dist-info/top_level.txt,sha256=aGuVIzWsKiV1f2gCb6mynx0zx5ma0B1EwPGFKVEMTi4,9
|
12
|
+
rgwfuncs-0.0.69.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|