Metadata-Version: 2.4
Name: clownfish
Version: 0.6.5
Summary: A modern terminal emulator written in Python and Tkinter
Author: ellainng
Author-email: ellainng <299958882+ellainng@users.noreply.github.com>
License-Expression: MIT
License-File: LICENSE
Requires-Dist: pytest>=8.0.0 ; extra == 'dev'
Requires-Dist: ruff>=0.4.0 ; extra == 'dev'
Requires-Dist: escape-colors==0.3.0 ; extra == 'syntax'
Requires-Python: >=3.14
Provides-Extra: dev
Provides-Extra: syntax
Description-Content-Type: text/markdown

# Clownfish 🐟

[![CI](https://github.com/wispsy/clownfish/actions/workflows/ci.yml/badge.svg)](https://github.com/wispsy/clownfish/actions/workflows/ci.yml)
[![Python 3.14+](https://img.shields.io/badge/python-3.14+-blue.svg)](https://www.python.org/downloads/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

A lightweight, modern terminal emulator written in Python and Tkinter, featuring TrueColor rendering, full POSIX PTY bridge, mouse reporting, Unicode wide character support, device attribute queries, and shell integration.

---

## Features

- **Remote SSH Sessions & Integrated Client**: Direct CLI connection via `clownfish ssh [user@]host [-p port] [-i key]`, UI Quick Connect dialog (`Cmd+Shift+O` / `Ctrl+Shift+O`), visual remote tab indicators (`🌐 user@host`), and clean connection teardown.
- **Session Layout Persistence & Restoration**: Automatically serializes open tabs, nested split hierarchies (horizontal and vertical), and working directories across restarts into `~/.config/clownfish/session_state.json` (`--restore` / `--no-restore`).
- **Headless Terminal Interface**: Pure Python programmatic interface (`HeadlessTerminal`) with zero display-server/Tkinter requirements, ideal for CI, AI agent automation, and scripted testing (`get_text()`, `wait_for_text()`, `send_input()`).
- **Split Navigation & Desktop Ergonomics**: Fast split pane keyboard cycling (`Cmd+[` / `Cmd+]` or `Alt+[` / `Alt+]`), split equalization (`Cmd+=` / `Ctrl+=`), high-contrast active-pane visual border highlight (`#4a90e2`), and automatic current working directory inheritance on new tabs (`Cmd+T`) and split panes (`Cmd+D`).
- **High-Throughput PTY Batching & Idle Throttling**: Bounded PTY event processing (`drain_events(max_bytes=512_000)`) with adaptive tick rate (`after(1)` for pending stream bursts, `after(16)` for interactive typing) and cursor state caching to eliminate canvas churn when idle.
- **Security & OSC Integrations**: Base64 clipboard get/set (`OSC 52`) with size-bounded payload decoding, current working directory tracking (`OSC 7`), strict allowlisted URL scheme validation for hyperlinks (`OSC 8`), and desktop notifications (`OSC 9` and `OSC 777`).
- **Unicode Grapheme Clusters & Complex Emojis**: Support for Zero-Width Joiner (ZWJ, `\u200D`) connected emoji sequences (e.g. `👩‍💻`), Fitzpatrick skin tone modifiers, regional indicator flag pairs (`🇯🇵`), and extended emoji/symbol pictographs in monospace terminal grid math.
- **VT/xterm & Keyboard Conformance**: Full F1–F12 function key encoding, standard xterm modified navigation keys (`Ctrl/Alt/Shift + Arrows/Home/End/PageUp/PageDown`), DECOM Origin Mode (`?6h`/`?6l`), DECAWM Auto-wrap Mode (`?7h`/`?7l`), DECSCUSR cursor styles (block, underline, bar), and DEC Mode 2026 Synchronized Output for tear-free rendering.
- **Mouse Motion Reporting**: Button motion tracking (`?1002h`) and any-event motion tracking (`?1003h`) alongside standard press/release (`?1000h`) and SGR format (`?1006h`).
- **Interactive Login Shells & Job Control**: Launches native user shells (`/bin/zsh`, `/bin/bash`) as login interactive shells (`-l -i`) with controlling terminal allocation (`TIOCSCTTY`), pre-spawn window sizing (`TIOCSWINSZ`), and full POSIX job control (`Ctrl+C`, `Ctrl+Z`, `fg`, `bg`).
- **Non-Destructive Soft-Wrap Reflow**: Dynamic text reflow (`Row.is_wrapped`) when resizing terminal columns, preserving character buffers, styles, wide glyphs, and cursor positioning without data loss.
- **Screen-Editing VT Sequences**: Full support for Cursor Next/Previous Line (`CSI E`/`F`), Erase Characters (`CSI X`), Insert/Delete Lines (`CSI L`/`M`), Scroll Up/Down (`CSI S`/`T`), and ANSI Cursor Save/Restore (`CSI s`/`u`).
- **Prompt Preservation on Clear**: Complete terminal reset (`Cmd+K` / `Ctrl+K`) flushes scrollback while requesting interactive shell redraw (`Ctrl+L`), preserving partially typed command lines.
- **Dynamic Window & Tab Titles**: Shell `precmd` window and tab title sequences (`OSC 0` and `OSC 2`) update desktop tab headers in real time.
- **Multi-Tab Terminal Sessions**: Manage multiple independent terminal sessions with tab switching shortcuts (`Cmd+T`, `Cmd+W`, `Cmd+1..9`, `Ctrl+Tab`).
- **Split Panes**: Divide any tab vertically (`Cmd+D`) or horizontally (`Cmd+Shift+D`) with native resizable sash dividers.
- **In-Buffer Search**: Interactive search bar (`Cmd+F`) across active terminal screen and scrollback history with match highlighting and cycling.
- **User Preferences**: Persistent configuration in `~/.config/clownfish/config.json`.
- **TrueColor & 256-Color Support**: Full 24-bit RGB TrueColor escaping and standard ANSI 16/256 palette support.
- **Full Screen & Scrollback Clear**: Complete terminal reset with `Cmd+K` (macOS) or `Ctrl+K` (Linux/Windows) that flushes active screen and all 10,000 lines of scrollback buffer.
- **Unicode Wide Characters & Emojis**: Character classification via East Asian Width (`unicodedata.east_asian_width`) for 2-column CJK characters and emojis with sentinel spacer cells.
- **Device Attribute Queries**: Standard VT220 / xterm query responses for DA1 (`\x1b[c`), DA2 (`\x1b[>c`), DSR / CPR (`\x1b[6n`), and OSC 10/11 color queries, eliminating CLI boot delays.
- **Kitty Keyboard Protocol**: Protocol flag negotiation (`CSI ? u`, `CSI = u`, `CSI > u`, `CSI < u`) enabling disambiguation of modified keystrokes like `Shift+Enter`.
- **OSC 133 Semantic Prompts**: Shell integration tracking prompt start, command execution, and exit codes, enabling prompt-to-prompt jumping (`Cmd+Up` / `Cmd+Down`).
- **OSC 8 Hyperlinks**: Clickable URLs with browser launching via `Cmd+Click` or `Ctrl+Click`.
- **Mouse Tracking**: Normal tracking (`?1000h`) and SGR decimal tracking (`?1006h`) for interactive CLI programs like `vim`, `htop`, and `tmux`.
- **Primary & Alternate Screen Buffers**: Smooth transitions into and out of full-screen terminal programs without corrupting main scrollback.

---

## Installation & Running

Clownfish offers multiple installation channels: native macOS application bundle, Homebrew tap, PyPI package, or source.

### Option 1: macOS Application Bundle (`Clownfish.app`)

Download the latest release archive from [GitHub Releases](https://github.com/wispsy/clownfish/releases):

1. Download `Clownfish-v0.6.3-macos.zip`.
2. Unzip the archive:
   ```bash
   unzip Clownfish-v0.6.3-macos.zip
   ```
3. Move `Clownfish.app` to `/Applications`:
   ```bash
   mv Clownfish.app /Applications/
   ```
4. Launch Clownfish from Spotlight, Finder, or from your terminal with `open /Applications/Clownfish.app`.

> [!NOTE]
> **Platform Support & macOS Gatekeeper**:
> - **macOS**: Built natively for Apple Silicon (arm64); runs on Intel (x86_64) via source or Rosetta.
> - **Linux**: Supported out of the box via Python 3.14 with `python3-tk` (X11 / Wayland).
> - **Code Signing**: Distributed bundles use an ad-hoc signature. If macOS Gatekeeper displays a security notice, clear the quarantine attribute:
>   ```bash
>   xattr -cr /Applications/Clownfish.app
>   ```
>   or right-click `Clownfish.app` and select **Open**.

### Option 2: Homebrew Tap (`wispsy/homebrew-tap`)

Install Clownfish via the official [Wispsy Homebrew tap](https://github.com/wispsy/homebrew-tap):

```bash
# Add the tap
brew tap wispsy/tap

# Install the CLI formula (isolated Python environment)
brew install clownfish

# Or install the standalone macOS GUI application via Cask
brew install --cask wispsy/tap/clownfish
```

### Option 3: PyPI Package (`pip` / `uv`)

Clownfish is published to PyPI and requires Python 3.14+:

```bash
# Using uv (recommended)
uv tool install clownfish

# Or using pip
pip install clownfish
```

Run directly:
```bash
clownfish
```

### Option 4: From Source (Development)

Ensure you have Python 3.14+ and [uv](https://docs.astral.sh/uv/) installed.

```bash
git clone https://github.com/wispsy/clownfish.git
cd clownfish
uv sync --all-extras
uv run clownfish
```

To build the standalone macOS `.app` bundle from source:
```bash
uv run --with pyinstaller python scripts/build_macos_app.py
```

---

## Testing & Quality Assurance

Run the test suite:
```bash
uv run pytest
```

Run code formatting and linting:
```bash
uv run ruff check .
```

---

## Documentation

- [Architecture Guide](docs/architecture.md): Deep dive into screen buffer management, parser state machine, and render loop.
- [Modern Terminal Gap Analysis](docs/modern-terminal-gap-analysis.md): Technical analysis of the fundamental features required for modern terminal emulators.
- [Keyboard & Mouse Shortcuts](docs/shortcuts.md): Guide to shortcuts for clearing buffers, navigation, and clipboard operations.

---

## Project Structure

```text
clownfish/
├── .github/
│   └── workflows/
│       ├── ci.yml                 # GitHub Actions CI workflow (Ubuntu & macOS)
│       └── release.yaml           # Automated PyPI & GitHub Release workflow
├── assets/
│   └── Clownfish.icns             # Multi-resolution macOS application icon
├── docs/
│   ├── architecture.md            # Architecture overview & data flow
│   ├── modern-terminal-gap-analysis.md # Modern terminal specifications
│   └── shortcuts.md               # Keybinding reference
├── packaging/
│   └── homebrew/                  # Homebrew tap formulas & casks
│       ├── Casks/
│       │   └── clownfish.rb
│       └── Formula/
│           └── clownfish.rb
├── scripts/
│   ├── build_macos_app.py         # PyInstaller macOS bundle & zip builder
│   └── publish_homebrew.py        # Homebrew tap release automation
├── src/
│   └── clownfish/
│       ├── __init__.py            # Public API exports & launch function
│       ├── __main__.py            # Module entrypoint (python -m clownfish)
│       ├── config.py              # Configuration dataclasses (TerminalConfig)
│       ├── syntax.py              # Syntax highlighting integration
│       ├── core/                  # Core terminal engine
│       │   ├── models.py          # Data models (Cell, Style, Selection, PromptMarker)
│       │   ├── keyboard.py        # Keystroke encoding & Kitty keyboard protocol
│       │   ├── parser.py          # VT100 / ANSI / OSC escape sequence parser
│       │   ├── screen.py          # Screen buffer, dual grid, autowrap & scrollback
│       │   └── search.py          # In-buffer regex & plain text search engine
│       ├── session/               # Terminal session layer
│       │   ├── session.py         # TerminalSession lifecycle manager
│       │   └── transport.py       # Abstract Transport base class
│       ├── transports/            # Pluggable I/O transports
│       │   ├── pty.py             # POSIX PTYTransport with write buffering
│       │   └── ssh.py             # SSHTransport via OpenSSH PTY bridge
│       └── frontends/
│           └── tkinter/           # Tkinter desktop frontend
│               ├── app.py         # TkTerminalApp main window & menu shortcuts
│               ├── pane.py        # TerminalPane self-contained terminal widget
│               ├── split.py       # SplitView arbitrary nested split pane manager
│               ├── tabs.py        # TabbedTerminalView multi-tab session manager
│               ├── renderer.py    # Canvas text & selection renderer
│               └── input.py       # Pointer & keyboard event translator
├── tests/                         # Comprehensive unit & integration test suite
├── pyproject.toml                 # Project metadata & build settings
└── README.md
```

---

## Roadmap

- [x] Split-pane multiplexing and tabbed sessions.
- [x] In-buffer regex / plain text search with highlight overlay.
- [ ] GPU-accelerated texture atlas rendering via Metal/Vulkan.
- [ ] HarfBuzz typography shaping for developer font ligatures (`->`, `!=`, `===`).
- [ ] Kitty Graphics Protocol inline image streaming.
- [ ] Sixel bitmap rasterization protocol support.

---

## License

This project is licensed under the MIT License.
