@@ -35,6 +35,7 @@ class ShellPTY: |
| 35 | 35 | timeout: float = 5.0, |
| 36 | 36 | prompt_pattern: Optional[str] = None, |
| 37 | 37 | env: Optional[dict] = None, |
| 38 | + profile: Optional[dict] = None, |
| 38 | 39 | ): |
| 39 | 40 | """ |
| 40 | 41 | Initialize the PTY wrapper. |
@@ -44,10 +45,16 @@ class ShellPTY: |
| 44 | 45 | timeout: Default timeout for expect operations (seconds) |
| 45 | 46 | prompt_pattern: Regex pattern to match the shell prompt |
| 46 | 47 | env: Additional environment variables |
| 48 | + profile: Shell profile dict (from profile.py) |
| 47 | 49 | """ |
| 48 | 50 | self.shell_path = shell_path |
| 49 | 51 | 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 | + ) |
| 51 | 58 | self.custom_env = env or {} |
| 52 | 59 | self.child: Optional[pexpect.spawn] = None |
| 53 | 60 | self._output_buffer: str = "" |
@@ -64,15 +71,18 @@ class ShellPTY: |
| 64 | 71 | env["LANG"] = "en_US.UTF-8" |
| 65 | 72 | env["LC_ALL"] = "en_US.UTF-8" |
| 66 | 73 | |
| 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" |
| 76 | 86 | |
| 77 | 87 | # Apply custom environment |
| 78 | 88 | env.update(self.custom_env) |