rgwfuncs 0.0.79__py3-none-any.whl → 0.0.81__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.
@@ -1,43 +1,69 @@
1
- import os
2
- import atexit
1
+ #!/usr/bin/env python3
3
2
  import code
4
- import readline # Assuming this is imported elsewhere in your module
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
- class CustomConsole(code.InteractiveConsole):
13
- """Custom console to make user input white while keeping prompts and output default."""
14
- def raw_input(self, prompt=""):
15
- # Print the prompt (>>>), then switch to white for input
16
- sys.stdout.write(prompt) # Prompt in default color
17
- sys.stdout.write("\033[97m") # Switch to white for input
18
- sys.stdout.flush()
19
- try:
20
- line = input() # User types in white
21
- except EOFError:
22
- raise # Handle Ctrl+D gracefully
23
- finally:
24
- sys.stdout.write("\033[0m") # Reset to default after input
25
- sys.stdout.flush()
26
- return line
27
-
28
- def interactive_shell(local_vars: Dict[str, Any], shell_color: str = '') -> None:
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.
29
23
  """
30
- Launches an interactive prompt for inspecting and modifying local variables, making all methods
31
- in the rgwfuncs library available by default. Persists command history across sessions.
32
- User input is displayed in white; other text uses the terminal's default color.
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 (the prompt will be white).
31
+ if s == sys.ps1 or s == sys.ps2:
32
+ self.wrapped.write(s)
33
+ return
34
+
35
+ # Process the text line by line so that each new line gets the blue color.
36
+ # (We only want to color “output”, not the prompt.)
37
+ lines = s.split('\n')
38
+ for i, line in enumerate(lines):
39
+ # Only prepend blue if we are at a new line.
40
+ if self.at_line_start and line:
41
+ self.wrapped.write(BLUE + line)
42
+ else:
43
+ self.wrapped.write(line)
44
+ # If this is not the last line, then the newline was in the string.
45
+ if i < len(lines) - 1:
46
+ self.wrapped.write('\n' + RESET) # reset after newline
47
+ self.at_line_start = True
48
+ else:
49
+ # If the last chunk is non-empty, we are in the middle of a line.
50
+ self.at_line_start = (line == "")
51
+ # Note: Do not flush automatically here.
52
+
53
+ def flush(self):
54
+ self.wrapped.flush()
55
+
56
+ def interactive_shell(local_vars: Dict[str, Any]) -> None:
57
+ """
58
+ Launches an interactive prompt for inspecting and modifying local variables,
59
+ making all methods in the rgwfuncs library available by default.
60
+ Persists command history across sessions.
33
61
 
34
62
  Parameters:
35
63
  local_vars (dict): Dictionary of local variables to be available in the interactive shell.
36
- shell_color (str): ANSI color code for shell output (default: empty for terminal default).
37
64
  """
38
-
39
- def setup_readline(shell_color: str = '') -> None:
40
- """Set up readline for history persistence with a given shell color."""
65
+ def setup_readline() -> None:
66
+ """Set up readline for history persistence."""
41
67
  HISTORY_FILE = os.path.expanduser("~/.rgwfuncs_shell_history")
42
68
  readline.set_history_length(1000)
43
69
  readline.parse_and_bind("tab: complete")
@@ -45,28 +71,37 @@ def interactive_shell(local_vars: Dict[str, Any], shell_color: str = '') -> None
45
71
  try:
46
72
  readline.read_history_file(HISTORY_FILE)
47
73
  except Exception as e:
48
- print(f"{shell_color}Warning: Could not load history file: {e}")
74
+ print(f"Warning: Could not load history file: {e}")
49
75
  atexit.register(readline.write_history_file, HISTORY_FILE)
50
76
 
51
77
  if not isinstance(local_vars, dict):
52
78
  raise TypeError("local_vars must be a dictionary")
53
79
 
54
- # Set up readline for history and completion
80
+ # Set up readline history and completion
55
81
  setup_readline()
56
82
 
57
83
  # Make imported functions available in the REPL
58
84
  local_vars.update(globals())
59
85
 
60
- # Set prompt to plain text (no color)
61
- sys.ps1 = ">>> "
86
+ # Set up custom prompts.
87
+ # The prompt text itself is printed in white.
88
+ sys.ps1 = WHITE + ">>> " + RESET
89
+ sys.ps2 = WHITE + "... " + RESET
90
+
91
+ # Wrap sys.stdout to emit blue-colored output.
92
+ sys.stdout = BlueStdout(sys.stdout)
62
93
 
63
- # Create custom console with local context
64
- console = CustomConsole(locals=local_vars)
94
+ # Create an interactive console with the provided locals.
95
+ console = code.InteractiveConsole(locals=local_vars)
65
96
 
66
- # Start interactive session with a custom banner and exit message in default color
67
- banner = f"{shell_color}Welcome to the rgwfuncs interactive shell.\nUse up/down arrows for command history.\nType 'exit()' or Ctrl+D to quit."
68
- exitmsg = f"{shell_color}Goodbye."
97
+ # Custom banner and exit message
98
+ banner = ("Welcome to the rgwfuncs interactive shell.\n"
99
+ "Use up/down arrows for command history.\n"
100
+ "Type 'exit()' or Ctrl+D to quit.")
101
+ exitmsg = "Goodbye."
69
102
 
70
- # Run the interactive session
71
- console.interact(banner=banner, exitmsg=exitmsg)
103
+ try:
104
+ console.interact(banner=banner)
105
+ finally:
106
+ print(exitmsg)
72
107
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: rgwfuncs
3
- Version: 0.0.79
3
+ Version: 0.0.81
4
4
  Summary: A functional programming paradigm for mathematical modelling and data science
5
5
  Home-page: https://github.com/ryangerardwilson/rgwfunc
6
6
  Author: Ryan Gerard Wilson
@@ -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=Pdujo-XdtfnCpudzHz0jSnYes0hNbHfPpREu4Fq1K0M,2979
5
+ rgwfuncs/interactive_shell_lib.py,sha256=0XW9QY88z2_hNOwY49K8KinqSCvCTtuOeryCTysLcEM,3729
6
6
  rgwfuncs/str_lib.py,sha256=rtAdRlnSJIu3JhI-tA_A0wCiPK2m-zn5RoGpBxv_g-4,2228
7
- rgwfuncs-0.0.79.dist-info/LICENSE,sha256=jLvt20gcUZYB8UOvyBvyKQ1qhYYhD__qP7ZDx2lPFkU,1062
8
- rgwfuncs-0.0.79.dist-info/METADATA,sha256=gTXvRXdi0hv7sSEW8TQIZdAHL0nrgtFx7kskQyL2FpM,60288
9
- rgwfuncs-0.0.79.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
10
- rgwfuncs-0.0.79.dist-info/entry_points.txt,sha256=j-c5IOPIQ0252EaOV6j6STio56sbXl2C4ym_fQ0lXx0,43
11
- rgwfuncs-0.0.79.dist-info/top_level.txt,sha256=aGuVIzWsKiV1f2gCb6mynx0zx5ma0B1EwPGFKVEMTi4,9
12
- rgwfuncs-0.0.79.dist-info/RECORD,,
7
+ rgwfuncs-0.0.81.dist-info/LICENSE,sha256=jLvt20gcUZYB8UOvyBvyKQ1qhYYhD__qP7ZDx2lPFkU,1062
8
+ rgwfuncs-0.0.81.dist-info/METADATA,sha256=avh7CV9-GnXlR1nK0jK1g1akypILcus-vx5UU0hibm8,60288
9
+ rgwfuncs-0.0.81.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
10
+ rgwfuncs-0.0.81.dist-info/entry_points.txt,sha256=j-c5IOPIQ0252EaOV6j6STio56sbXl2C4ym_fQ0lXx0,43
11
+ rgwfuncs-0.0.81.dist-info/top_level.txt,sha256=aGuVIzWsKiV1f2gCb6mynx0zx5ma0B1EwPGFKVEMTi4,9
12
+ rgwfuncs-0.0.81.dist-info/RECORD,,