# write_terminal_escape

> **Function** in `deepagents_code`

📖 [View in docs](https://reference.langchain.com/python/deepagents-code/terminal_escape/write_terminal_escape)

Best-effort write of a terminal control sequence.

Prefers `/dev/tty` so the sequence reaches the terminal even when stdout
or stderr are redirected. Falls back to `sys.__stderr__` only if it is a
TTY.

Returns `False` (no-op) when output is disabled or no TTY is reachable.

## Signature

```python
write_terminal_escape(
    sequence: str,
) -> bool
```

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `sequence` | `str` | Yes | Raw escape sequence to write, including leading `\x1b`/`ESC` and terminator. |

## Returns

`bool`

`True` if the sequence was written and flushed without error.

---

[View source on GitHub](https://github.com/langchain-ai/deepagents/blob/0412009c5441bef8d75a427e1da8909e33ab5b56/libs/code/deepagents_code/terminal_escape.py#L82)