tenseleyflow/bensch / d925e95

Browse files

integrate profiles into PTY engine

ShellPTY now accepts a profile dict. The start() method applies
test_mode_env, history_disable.env, and rc_disable.env from the
profile instead of hardcoded FORTSH_* environment variables.

Prompt pattern falls through: explicit > profile > default.

Zero FORTSH references remain in shell_pty.py.
Authored by espadonne
SHA
d925e953aa9a1eb9de60e34f4c73c90bc07bfd83
Parents
d92057f
Tree
185e6a4

1 changed file

StatusFile+-
M framework/shell_pty.py 20 10
framework/shell_pty.pymodified
@@ -35,6 +35,7 @@ class ShellPTY:
3535
         timeout: float = 5.0,
3636
         prompt_pattern: Optional[str] = None,
3737
         env: Optional[dict] = None,
38
+        profile: Optional[dict] = None,
3839
     ):
3940
         """
4041
         Initialize the PTY wrapper.
@@ -44,10 +45,16 @@ class ShellPTY:
4445
             timeout: Default timeout for expect operations (seconds)
4546
             prompt_pattern: Regex pattern to match the shell prompt
4647
             env: Additional environment variables
48
+            profile: Shell profile dict (from profile.py)
4749
         """
4850
         self.shell_path = shell_path
4951
         self.timeout = timeout
50
-        self.prompt_pattern = prompt_pattern or self.DEFAULT_PROMPT_PATTERN
52
+        self.profile = profile or {}
53
+        self.prompt_pattern = (
54
+            prompt_pattern
55
+            or self.profile.get("prompt_pattern")
56
+            or self.DEFAULT_PROMPT_PATTERN
57
+        )
5158
         self.custom_env = env or {}
5259
         self.child: Optional[pexpect.spawn] = None
5360
         self._output_buffer: str = ""
@@ -64,15 +71,18 @@ class ShellPTY:
6471
         env["LANG"] = "en_US.UTF-8"
6572
         env["LC_ALL"] = "en_US.UTF-8"
6673
 
67
-        # Enable test mode for cleaner output (less ANSI redraws)
68
-        # Note: Completion is NOT disabled here - tests can use Tab completion
69
-        env["FORTSH_MINIMAL_ECHO"] = "1"
70
-        env["FORTSH_TEST_MODE"] = "1"
71
-        env["HISTFILE"] = "/dev/null"  # Don't load/save history from file
72
-
73
-        # Use /dev/null for clean testing unless specified
74
-        if rc_file is not None:
75
-            env["FORTSH_RC_FILE"] = rc_file
74
+        # Apply profile-driven environment (test mode, history disable, rc disable)
75
+        if self.profile:
76
+            for k, v in self.profile.get("test_mode_env", {}).items():
77
+                env[k] = str(v)
78
+            for k, v in self.profile.get("history_disable", {}).get("env", {}).items():
79
+                env[k] = str(v)
80
+            if rc_file is not None:
81
+                for k, v in self.profile.get("rc_disable", {}).get("env", {}).items():
82
+                    env[k] = str(v)
83
+        else:
84
+            # Fallback: disable history
85
+            env["HISTFILE"] = "/dev/null"
7686
 
7787
         # Apply custom environment
7888
         env.update(self.custom_env)