Download tasks/headless-terminal/solution/headless_terminal.py from pedrodev2026/Mini-TBench: direct link, hf CLI and curl.
- Browser
- Download file 938 Bytes
-
https://huggingface.co/datasets/pedrodev2026/Mini-TBench/resolve/main/tasks/headless-terminal/solution/headless_terminal.py
- Command line
-
hf download hf://datasets/pedrodev2026/Mini-TBench/tasks/headless-terminal/solution/headless_terminal.py
-
curl -L -o headless_terminal.py https://huggingface.co/datasets/pedrodev2026/Mini-TBench/resolve/main/tasks/headless-terminal/solution/headless_terminal.py
938 Bytes
| import subprocess | |
| import time | |
| import uuid | |
| from base_terminal import BaseTerminal | |
| class HeadlessTerminal(BaseTerminal): | |
| def __init__(self): | |
| self._session_id = str(uuid.uuid4()) | |
| subprocess.run( | |
| ["tmux", "new-session", "-d", "-s", self._session_id], | |
| check=True, | |
| stdout=subprocess.DEVNULL, | |
| stderr=subprocess.DEVNULL, | |
| ) | |
| def send_keystrokes(self, keystrokes: str, wait_sec: float = 0.0) -> None: | |
| """ | |
| Sends keystrokes to the terminal. | |
| Args: | |
| keystrokes: The keystrokes to send to the terminal. | |
| wait_sec: The number of seconds to wait for the command to complete. | |
| """ | |
| subprocess.run( | |
| ["tmux", "send-keys", "-t", self._session_id, keystrokes], | |
| check=True, | |
| stdout=subprocess.DEVNULL, | |
| stderr=subprocess.DEVNULL, | |
| ) | |
| time.sleep(wait_sec) | |