rgwfuncs 0.0.82__py3-none-any.whl → 0.0.84__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.
@@ -19,20 +19,19 @@ RESET = "\033[0m"
19
19
  class BlueStdout:
20
20
  """
21
21
  A wrapper for sys.stdout that automatically prepends blue
22
- color codes on output, unless the output appears to be a prompt.
22
+ color codes on output.
23
23
  """
24
24
  def __init__(self, wrapped):
25
25
  self.wrapped = wrapped
26
26
  self.at_line_start = True
27
27
 
28
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.
29
+ # Do not interfere with prompt strings.
31
30
  if s == sys.ps1 or s == sys.ps2:
32
31
  self.wrapped.write(s)
33
32
  return
34
33
 
35
- # Process text, coloring new lines with blue.
34
+ # Process text line by line so that new lines are colored.
36
35
  lines = s.split('\n')
37
36
  for i, line in enumerate(lines):
38
37
  if self.at_line_start and line:
@@ -44,17 +43,35 @@ class BlueStdout:
44
43
  self.at_line_start = True
45
44
  else:
46
45
  self.at_line_start = (line == "")
47
-
46
+
48
47
  def flush(self):
49
48
  self.wrapped.flush()
50
49
 
51
50
  def isatty(self):
52
51
  return self.wrapped.isatty()
53
52
 
53
+ def fileno(self):
54
+ return self.wrapped.fileno()
55
+
54
56
  def __getattr__(self, attr):
55
- # Delegate attribute access to the wrapped object.
57
+ # Delegate attribute access to the original stdout.
56
58
  return getattr(self.wrapped, attr)
57
59
 
60
+ class ColorInteractiveConsole(code.InteractiveConsole):
61
+ """Subclass InteractiveConsole to temporarily restore the real stdout when reading input."""
62
+ def raw_input(self, prompt=""):
63
+ # Before calling input(), restore the original stdout so that readline works properly.
64
+ saved_stdout = sys.stdout
65
+ sys.stdout = sys.__stdout__
66
+ try:
67
+ line = input(prompt)
68
+ except EOFError:
69
+ raise
70
+ finally:
71
+ # Restore our blue-printing stdout.
72
+ sys.stdout = saved_stdout
73
+ return line
74
+
58
75
  def interactive_shell(local_vars: Dict[str, Any]) -> None:
59
76
  """
60
77
  Launches an interactive prompt for inspecting and modifying local variables,
@@ -79,23 +96,22 @@ def interactive_shell(local_vars: Dict[str, Any]) -> None:
79
96
  if not isinstance(local_vars, dict):
80
97
  raise TypeError("local_vars must be a dictionary")
81
98
 
82
- # Set up readline history and completion.
99
+ # Set up readline.
83
100
  setup_readline()
84
101
 
85
102
  # Make imported functions available in the REPL.
86
103
  local_vars.update(globals())
87
104
 
88
- # Set up custom prompts (displayed in white).
89
- sys.ps1 = WHITE + ">>> " + RESET
90
- sys.ps2 = WHITE + "... " + RESET
105
+ # Note: Wrap ANSI codes in markers that readline understands so that they don’t count in prompt length.
106
+ sys.ps1 = "\001" + WHITE + "\002" + ">>> " + "\001" + RESET + "\002"
107
+ sys.ps2 = "\001" + WHITE + "\002" + "... " + "\001" + RESET + "\002"
91
108
 
92
- # Wrap sys.stdout to emit blue-colored output.
93
- sys.stdout = BlueStdout(sys.stdout)
109
+ # Wrap sys.stdout for colored output.
110
+ sys.stdout = BlueStdout(sys.__stdout__) # Wrap the original stdout.
94
111
 
95
- # Create an interactive console with the provided locals.
96
- console = code.InteractiveConsole(locals=local_vars)
112
+ # Use our custom interactive console.
113
+ console = ColorInteractiveConsole(locals=local_vars)
97
114
 
98
- # Custom banner and exit message.
99
115
  banner = ("Welcome to the rgwfuncs interactive shell.\n"
100
116
  "Use up/down arrows for command history.\n"
101
117
  "Type 'exit()' or Ctrl+D to quit.")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: rgwfuncs
3
- Version: 0.0.82
3
+ Version: 0.0.84
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=fbZJvN2HmRxNCW-8nfmpLBhVkgJ-TMtrrczKwLIUykI,3492
5
+ rgwfuncs/interactive_shell_lib.py,sha256=fbm9FSGmyT0d2K-5DUmuPMbJxrBLzJvZq9UimS5fhck,4090
6
6
  rgwfuncs/str_lib.py,sha256=rtAdRlnSJIu3JhI-tA_A0wCiPK2m-zn5RoGpBxv_g-4,2228
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,,
7
+ rgwfuncs-0.0.84.dist-info/LICENSE,sha256=jLvt20gcUZYB8UOvyBvyKQ1qhYYhD__qP7ZDx2lPFkU,1062
8
+ rgwfuncs-0.0.84.dist-info/METADATA,sha256=BGBOO2F9AXPg4l5_3fRD40q_zDg5i0sKJxr7dZ4RKts,60288
9
+ rgwfuncs-0.0.84.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
10
+ rgwfuncs-0.0.84.dist-info/entry_points.txt,sha256=j-c5IOPIQ0252EaOV6j6STio56sbXl2C4ym_fQ0lXx0,43
11
+ rgwfuncs-0.0.84.dist-info/top_level.txt,sha256=aGuVIzWsKiV1f2gCb6mynx0zx5ma0B1EwPGFKVEMTi4,9
12
+ rgwfuncs-0.0.84.dist-info/RECORD,,