droidtui 0.5.3

A beautiful Terminal User Interface (TUI) for Android development and ADB commands
Documentation
# DroidTUI ๐Ÿค–

[![Crates.io](https://img.shields.io/crates/v/droidtui.svg)](https://crates.io/crates/droidtui)
[![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
[![Release](https://github.com/sorinirimies/droidtui/actions/workflows/release.yml/badge.svg)](https://github.com/sorinirimies/droidtui/actions/workflows/release.yml)
[![CI](https://github.com/sorinirimies/droidtui/actions/workflows/ci.yml/badge.svg)](https://github.com/sorinirimies/droidtui/actions/workflows/ci.yml)

A beautiful Terminal User Interface (TUI) for Android development โ€” ADB commands, live logcat viewer, device dashboard, and more. Built with Rust, Ratatui, and the pure-Rust `adb_client` crate (no Android SDK required).

## Features โœจ

### ๐Ÿ“บ Live Logcat Viewer
Full-screen, real-time logcat streaming with professional-grade tooling:

- **Live streaming** via `adb_client`'s native API โ€” no `adb` binary needed
- **Regex search** (`r` toggle) โ€” powerful pattern matching (`Error|Exception`, `OkHttp.*failed`)
- **Find filter** (`f`) โ€” case-insensitive substring search with match highlighting
- **Exclude filter** (`e`) โ€” negative matching to hide noisy tags/messages
- **Tag & PID filters** (`t`, `p`) โ€” dedicated filter fields
- **Log level filter** (`l`) โ€” cycle minimum level V โ†’ D โ†’ I โ†’ W โ†’ E โ†’ F
- **Per-tag color hashing** โ€” each tag gets a stable, visually distinct color
- **Stack trace folding** (`F`) โ€” detect and fold/unfold Java/Kotlin stack traces
- **Line detail popup** (`Enter`) โ€” inspect any line with full message, JSON formatting
- **Bookmarks** (`m`, `[`, `]`) โ€” mark lines and jump between them
- **Copy to clipboard** (`y`) โ€” copy selected line via `pbcopy`/`xclip`
- **Soft wrap** (`w`) โ€” wrap long messages across multiple rows with aligned indentation
- **Compact mode** (`x`) โ€” hide timestamp/PID columns for more message space
- **Horizontal scroll** (`โ†`/`โ†’`) โ€” scroll long messages when wrap is off
- **Auto-scroll** โ€” sticks to bottom; manual scroll disables; `G`/`End` re-enables
- **Pause / Resume** (`Space`) โ€” freeze the view without losing the stream
- **Live stats** โ€” lines/sec rate and per-level counters in the status bar
- **Save logs** (`s`) โ€” save to file with path input dialog
- **Save Asโ€ฆ** (`S`) โ€” browse with integrated file explorer, `Shift+S` to save in current folder
- **JSON export** โ€” Tab in save dialog cycles TXT/JSON format (JSONL for Nushell/jq)
- **Bounded channel** โ€” `sync_channel(10k)` with backpressure prevents OOM during bursts
- **JSON detection** โ€” auto-detects and pretty-prints JSON in log messages with syntax coloring

### ๐Ÿ“ฑ ADB Command Dashboard
- **Device panel** โ€” live device selector with model, Android version, battery, RAM, CPU stats
- **40+ typed commands** โ€” packages, system, network, root toolkit, bootloader & flash
- **Fastboot support** โ€” OEM unlock/lock, wipe data, device info
- **Type-safe execution** โ€” compile-time guarantees via `adb_client` crate

### ๐ŸŽจ Theme System
- **12 named presets** โ€” Default, Dracula, Nord, Gruvbox Dark, Catppuccin Mocha, Tokyo Night, Solarized Dark, Moonfly, Oxocarbon, Forest, Neon, Mono
- **Global selector** (`Shift+T`) โ€” works from any screen
- **11 colour fields** โ€” brand, accent, success, dim, fg, sel_bg, warn, error, surface, border, key_hint

### ๐Ÿ–ฅ๏ธ CLI Query Mode
Stream logcat as JSON lines to stdout โ€” designed for piping into Nushell, jq, or grep:

```bash
droidtui --query                          # Stream live logcat as JSONL
droidtui --query --last 500               # Dump last 500 lines
droidtui --query --level E                # Only errors
droidtui --query --tag MyApp              # Filter by tag
droidtui --query --grep "timeout"         # Filter by message
droidtui --query | nu -c 'lines | each { from json } | where level == "Error"'
```

### ๐Ÿ“‚ Nushell Recipe Scripts
Pre-built analysis scripts in `scripts/logcat/`:

| Script | What it does |
|--------|-------------|
| `top_tags.nu` | Rank tags by frequency (top 20) |
| `error_summary.nu` | Group Error/Fatal by tag with sample messages |
| `timeline.nu` | Log volume + error count per second |
| `find_crashes.nu` | Detect Fatal entries, ANRs, exceptions |
| `filter_json.nu` | Extract and pretty-print JSON payloads from messages |

```bash
droidtui --query --last 5000 > logcat.jsonl
nu scripts/logcat/top_tags.nu logcat.jsonl
```

## Installation ๐Ÿ”ง

### From crates.io

```bash
cargo install droidtui
```

### From source

```bash
git clone https://github.com/sorinirimies/droidtui.git
cd droidtui
cargo install --path .
```

### Prerequisites

- **ADB server** running (`adb start-server`) โ€” the `adb` binary is only needed to start the server; all commands use the pure-Rust `adb_client` crate
- A connected Android device with USB debugging enabled

## Usage ๐ŸŽฎ

```bash
droidtui          # Launch the TUI
droidtui --query   # CLI mode โ€” stream logcat as JSON
droidtui --help    # Show all options
```

### Key Bindings โ€” Main Menu

| Key | Action |
|-----|--------|
| `โ†‘`/`โ†“` or `j`/`k` | Navigate menu |
| `Tab` / `Shift+Tab` | Jump between sections |
| `Enter` | Execute selected command |
| `L` | Open Live Logcat |
| `T` | Open Theme Selector |
| `d` | Cycle connected device |
| `r` | Refresh device info |
| `q` / `Esc` | Quit |

### Key Bindings โ€” Logcat Viewer

#### Navigation
| Key | Action |
|-----|--------|
| `โ†‘`/`โ†“` or `j`/`k` | Scroll up/down |
| `PgUp` / `PgDn` | Scroll 20 lines |
| `g` / `G` or `Home`/`End` | Jump to top / bottom |
| `โ†` / `โ†’` | Horizontal scroll (when wrap off) |
| `0` | Reset horizontal scroll |

#### Filters
| Key | Action |
|-----|--------|
| `f` | Find (search filter) |
| `e` | Exclude filter (negative match) |
| `t` | Tag filter |
| `p` | PID filter |
| `l` | Cycle log level (Vโ†’Dโ†’Iโ†’Wโ†’Eโ†’F) |
| `r` | Toggle regex mode |

#### Actions
| Key | Action |
|-----|--------|
| `Enter` | Line detail popup (with JSON formatting) |
| `y` | Copy line to clipboard |
| `m` | Toggle bookmark |
| `[` / `]` | Jump to prev/next bookmark |
| `F` | Fold/unfold stack trace |
| `w` | Toggle soft wrap |
| `x` | Toggle compact mode |
| `Space` | Pause / resume |
| `c` | Clear all entries |
| `s` | Save logs |
| `S` | Save Asโ€ฆ (file browser) |
| `q` / `Esc` | Close logcat |

#### Save Dialog
| Key | Action |
|-----|--------|
| `Enter` | Save to typed path |
| `S` | Save Asโ€ฆ (open file browser) |
| `Tab` | Cycle format: TXT all โ†’ TXT filtered โ†’ JSON all โ†’ JSON filtered |
| `Esc` | Cancel |

#### File Browser (Save Asโ€ฆ)
| Key | Action |
|-----|--------|
| `โ†‘`/`โ†“` | Navigate |
| `Enter` / `l` | Open directory / select file |
| `h` / `โ†` / `Backspace` | Go to parent |
| `Shift+S` | Save Here (into current directory) |
| `/` | Incremental search |
| `n` | Create new folder |
| `.` | Toggle hidden files |
| `s` | Cycle sort mode |
| `Esc` | Back to path input |

## Architecture ๐Ÿ—๏ธ

DroidTUI follows an **Elm-like architecture** with clear separation of concerns:

```
โ”Œโ”€โ”€ Model โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ app state, menu, logcat,      โ”‚
โ”‚ device status, theme          โ”‚
โ”œโ”€โ”€ Message โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ all possible state changes    โ”‚
โ”œโ”€โ”€ Update โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ message โ†’ state transitions   โ”‚
โ”œโ”€โ”€ View โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ model โ†’ terminal rendering    โ”‚
โ”œโ”€โ”€ Event โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ keyboard, tick โ†’ messages     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
```

### Project Structure

```
droidtui/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ main.rs       # Entry point + CLI query mode
โ”‚   โ”œโ”€โ”€ app.rs        # Event loop, key โ†’ message mapping
โ”‚   โ”œโ”€โ”€ model.rs      # All application state
โ”‚   โ”œโ”€โ”€ view.rs       # UI rendering (ratatui)
โ”‚   โ”œโ”€โ”€ update.rs     # State transitions
โ”‚   โ”œโ”€โ”€ message.rs    # Message enum
โ”‚   โ”œโ”€โ”€ event.rs      # Async event handling
โ”‚   โ”œโ”€โ”€ menu.rs       # Command menu widget
โ”‚   โ”œโ”€โ”€ adb.rs        # ADB client abstraction
โ”‚   โ”œโ”€โ”€ fastboot.rs   # Fastboot command support
โ”‚   โ”œโ”€โ”€ logcat.rs     # Logcat viewer (streaming, parsing, filters, stats)
โ”‚   โ”œโ”€โ”€ theme.rs      # Theme system (12 presets, selector)
โ”‚   โ”œโ”€โ”€ effects.rs    # Visual effects (TachyonFX)
โ”‚   โ””โ”€โ”€ lib.rs        # Library exports
โ”œโ”€โ”€ scripts/
โ”‚   โ”œโ”€โ”€ logcat/       # Nushell recipe scripts
โ”‚   โ”œโ”€โ”€ bump_version.nu
โ”‚   โ””โ”€โ”€ release_prepare.nu
โ”œโ”€โ”€ tests/
โ”‚   โ””โ”€โ”€ adb_integration_tests.rs
โ”œโ”€โ”€ examples/
โ””โ”€โ”€ Cargo.toml
```

## Dependencies ๐Ÿ“ฆ

| Crate | Purpose |
|-------|---------|
| `ratatui` | Terminal UI framework |
| `crossterm` | Cross-platform terminal I/O |
| `adb_client` | Pure-Rust ADB protocol client |
| `tokio` | Async runtime |
| `tachyonfx` | Visual effects & animations |
| `regex` | Regex search in logcat |
| `serde` + `serde_json` | JSON serialization for logcat export |
| `tui-file-explorer` | File browser widget (save dialog) |
| `color-eyre` | Error handling |

## Development ๐Ÿ› ๏ธ

```bash
cargo test                    # Run all 209 tests
cargo clippy --all-targets --all-features -- -D warnings  # Lint
cargo fmt --check             # Format check
just release patch            # Bump, test, tag, push
```

### Adding New ADB Commands

1. Add a variant to `AdbCommand` in `src/adb.rs`
2. Implement the handler in `AdbManager::execute`
3. Add a menu entry in `src/menu.rs` via `build_entries()`
4. Tests in `tests/adb_integration_tests.rs`

## Contributing ๐Ÿค

1. Fork the repository
2. Create your feature branch (`git checkout -b feature/amazing`)
3. Run `cargo fmt && cargo clippy --all-targets --all-features -- -D warnings && cargo test`
4. Commit and push
5. Open a Pull Request

## License ๐Ÿ“„

MIT โ€” Copyright (c) Sorin Albu-Irimies

## Acknowledgments ๐Ÿ™

- [Ratatui]https://ratatui.rs โ€” TUI framework
- [adb_client]https://github.com/nicoulaj/adb_client โ€” Pure-Rust ADB client
- [TachyonFX]https://github.com/junkdog/tachyonfx โ€” Visual effects
- [tui-file-explorer]https://github.com/sorinirimies/tui-file-explorer โ€” File browser widget

---

**Made with โค๏ธ and โ˜• for Android developers** ยท *Powered by Rust ๐Ÿฆ€*