rgwfuncs 0.0.80__py3-none-any.whl → 0.0.82__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 +75 -51
- {rgwfuncs-0.0.80.dist-info → rgwfuncs-0.0.82.dist-info}/METADATA +1 -1
- {rgwfuncs-0.0.80.dist-info → rgwfuncs-0.0.82.dist-info}/RECORD +7 -7
- {rgwfuncs-0.0.80.dist-info → rgwfuncs-0.0.82.dist-info}/LICENSE +0 -0
- {rgwfuncs-0.0.80.dist-info → rgwfuncs-0.0.82.dist-info}/WHEEL +0 -0
- {rgwfuncs-0.0.80.dist-info → rgwfuncs-0.0.82.dist-info}/entry_points.txt +0 -0
- {rgwfuncs-0.0.80.dist-info → rgwfuncs-0.0.82.dist-info}/top_level.txt +0 -0
@@ -1,46 +1,71 @@
|
|
1
|
-
|
2
|
-
import atexit
|
1
|
+
#!/usr/bin/env python3
|
3
2
|
import code
|
4
|
-
import readline
|
3
|
+
import readline
|
4
|
+
import rlcompleter # noqa: F401
|
5
5
|
import sys
|
6
|
+
import os
|
7
|
+
import atexit
|
6
8
|
from typing import Dict, Any
|
7
9
|
from .df_lib import * # noqa: F401, F403, E402
|
8
10
|
from .algebra_lib import * # noqa: F401, F403, E402
|
9
11
|
from .str_lib import * # noqa: F401, F403, E402
|
10
12
|
from .docs_lib import * # noqa: F401, F403, E402
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
sys.
|
30
|
-
|
31
|
-
|
14
|
+
# ANSI color escape codes
|
15
|
+
BLUE = "\033[34m"
|
16
|
+
WHITE = "\033[37m"
|
17
|
+
RESET = "\033[0m"
|
18
|
+
|
19
|
+
class BlueStdout:
|
20
|
+
"""
|
21
|
+
A wrapper for sys.stdout that automatically prepends blue
|
22
|
+
color codes on output, unless the output appears to be a prompt.
|
23
|
+
"""
|
24
|
+
def __init__(self, wrapped):
|
25
|
+
self.wrapped = wrapped
|
26
|
+
self.at_line_start = True
|
27
|
+
|
28
|
+
def write(self, s):
|
29
|
+
# If the written text exactly matches one of our prompt strings,
|
30
|
+
# assume it should be displayed as-is.
|
31
|
+
if s == sys.ps1 or s == sys.ps2:
|
32
|
+
self.wrapped.write(s)
|
33
|
+
return
|
34
|
+
|
35
|
+
# Process text, coloring new lines with blue.
|
36
|
+
lines = s.split('\n')
|
37
|
+
for i, line in enumerate(lines):
|
38
|
+
if self.at_line_start and line:
|
39
|
+
self.wrapped.write(BLUE + line)
|
40
|
+
else:
|
41
|
+
self.wrapped.write(line)
|
42
|
+
if i < len(lines) - 1:
|
43
|
+
self.wrapped.write('\n' + RESET)
|
44
|
+
self.at_line_start = True
|
45
|
+
else:
|
46
|
+
self.at_line_start = (line == "")
|
47
|
+
|
48
|
+
def flush(self):
|
49
|
+
self.wrapped.flush()
|
50
|
+
|
51
|
+
def isatty(self):
|
52
|
+
return self.wrapped.isatty()
|
53
|
+
|
54
|
+
def __getattr__(self, attr):
|
55
|
+
# Delegate attribute access to the wrapped object.
|
56
|
+
return getattr(self.wrapped, attr)
|
57
|
+
|
58
|
+
def interactive_shell(local_vars: Dict[str, Any]) -> None:
|
32
59
|
"""
|
33
|
-
Launches an interactive prompt for inspecting and modifying local variables,
|
34
|
-
in the rgwfuncs library available by default.
|
35
|
-
|
60
|
+
Launches an interactive prompt for inspecting and modifying local variables,
|
61
|
+
making all methods in the rgwfuncs library available by default.
|
62
|
+
Persists command history across sessions.
|
36
63
|
|
37
64
|
Parameters:
|
38
65
|
local_vars (dict): Dictionary of local variables to be available in the interactive shell.
|
39
|
-
shell_color (str): ANSI color code for shell output (default: blue '\033[94m').
|
40
66
|
"""
|
41
|
-
|
42
|
-
|
43
|
-
"""Set up readline for history persistence with a given shell color."""
|
67
|
+
def setup_readline() -> None:
|
68
|
+
"""Set up readline for history persistence."""
|
44
69
|
HISTORY_FILE = os.path.expanduser("~/.rgwfuncs_shell_history")
|
45
70
|
readline.set_history_length(1000)
|
46
71
|
readline.parse_and_bind("tab: complete")
|
@@ -48,37 +73,36 @@ def interactive_shell(local_vars: Dict[str, Any], shell_color: str = '\033[94m')
|
|
48
73
|
try:
|
49
74
|
readline.read_history_file(HISTORY_FILE)
|
50
75
|
except Exception as e:
|
51
|
-
print(f"
|
76
|
+
print(f"Warning: Could not load history file: {e}")
|
52
77
|
atexit.register(readline.write_history_file, HISTORY_FILE)
|
53
78
|
|
54
79
|
if not isinstance(local_vars, dict):
|
55
80
|
raise TypeError("local_vars must be a dictionary")
|
56
81
|
|
57
|
-
#
|
58
|
-
sys.stdout.write("\033[94mBLUE TEST\033[0m\n")
|
59
|
-
sys.stdout.write("\033[97mWHITE TEST\033[0m\n")
|
60
|
-
sys.stdout.flush()
|
61
|
-
|
62
|
-
# Set initial color to blue
|
63
|
-
sys.stdout.write("\033[94m")
|
64
|
-
sys.stdout.flush()
|
65
|
-
|
66
|
-
# Set up readline
|
82
|
+
# Set up readline history and completion.
|
67
83
|
setup_readline()
|
68
84
|
|
69
|
-
# Make imported functions available in the REPL
|
85
|
+
# Make imported functions available in the REPL.
|
70
86
|
local_vars.update(globals())
|
71
87
|
|
72
|
-
# Set
|
73
|
-
sys.ps1 = ">>> "
|
88
|
+
# Set up custom prompts (displayed in white).
|
89
|
+
sys.ps1 = WHITE + ">>> " + RESET
|
90
|
+
sys.ps2 = WHITE + "... " + RESET
|
91
|
+
|
92
|
+
# Wrap sys.stdout to emit blue-colored output.
|
93
|
+
sys.stdout = BlueStdout(sys.stdout)
|
74
94
|
|
75
|
-
# Create
|
76
|
-
console =
|
95
|
+
# Create an interactive console with the provided locals.
|
96
|
+
console = code.InteractiveConsole(locals=local_vars)
|
77
97
|
|
78
|
-
#
|
79
|
-
banner =
|
80
|
-
|
98
|
+
# Custom banner and exit message.
|
99
|
+
banner = ("Welcome to the rgwfuncs interactive shell.\n"
|
100
|
+
"Use up/down arrows for command history.\n"
|
101
|
+
"Type 'exit()' or Ctrl+D to quit.")
|
102
|
+
exitmsg = "Goodbye."
|
81
103
|
|
82
|
-
|
83
|
-
|
104
|
+
try:
|
105
|
+
console.interact(banner=banner)
|
106
|
+
finally:
|
107
|
+
print(exitmsg)
|
84
108
|
|
@@ -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=fbZJvN2HmRxNCW-8nfmpLBhVkgJ-TMtrrczKwLIUykI,3492
|
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.82.dist-info/LICENSE,sha256=jLvt20gcUZYB8UOvyBvyKQ1qhYYhD__qP7ZDx2lPFkU,1062
|
8
|
+
rgwfuncs-0.0.82.dist-info/METADATA,sha256=miNL402pXn_kxoj-XvU1CaVyygcpQnvjcEQ5RiguoG8,60288
|
9
|
+
rgwfuncs-0.0.82.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
10
|
+
rgwfuncs-0.0.82.dist-info/entry_points.txt,sha256=j-c5IOPIQ0252EaOV6j6STio56sbXl2C4ym_fQ0lXx0,43
|
11
|
+
rgwfuncs-0.0.82.dist-info/top_level.txt,sha256=aGuVIzWsKiV1f2gCb6mynx0zx5ma0B1EwPGFKVEMTi4,9
|
12
|
+
rgwfuncs-0.0.82.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|