An open API service indexing awesome lists of open source software.

https://github.com/tinywasm/devtui

Reusable terminal user interface abstraction for Go development tools. Built on top of bubbletea, DevTUI provides a pre-configured, minimalist interface where you can inject different handlers to display organized messages and interactions.
https://github.com/tinywasm/devtui

bubbletea golang golang-application golang-library tui tui-app

Last synced: 5 months ago
JSON representation

Reusable terminal user interface abstraction for Go development tools. Built on top of bubbletea, DevTUI provides a pre-configured, minimalist interface where you can inject different handlers to display organized messages and interactions.

Awesome Lists containing this project

README

          

# DevTUI

Project Badges

DevTUI is a **pure display layer** built on Bubbletea that organizes messages from business logic into a clean terminal interface.

## 🎯 Design Philosophy (Consumer-Driven)

DevTUI follows **consumer-driven interface design**: your application defines the UI interface, and DevTUI implements it. This ensures:
- **Zero Coupling**: Business logic never imports `devtui`.
- **High Testability**: Easily mock UI dependencies.
- **Pluggability**: Swap UI implementations without changing core logic.

### Integration Interface
Define this in your application to use DevTUI:
```go
type TuiInterface interface {
NewTabSection(title, description string) any
AddHandler(handler any, timeout time.Duration, color string, tabSection any)
RemoveTabSection(section any) // Dynamic removal
Start(args ...any) // Optional *sync.WaitGroup support
RefreshUI()
ReturnFocus() error
}
```

## 🚀 Quick Start

```go
func main() {
tui := devtui.NewTUI(&devtui.TuiConfig{AppName: "Demo", ExitChan: make(chan bool)})

// 1. Create a section
ops := tui.NewTabSection("Operations", "System Tasks")

// 2. Add handlers (DevTUI detects implemented interfaces automatically)
tui.AddHandler(&MyHandler{}, 5*time.Second, "#10b981", ops)

// 3. Optional: Remove section dynamically
// tui.RemoveTabSection(ops)

tui.Start()
}
```

## 🧩 Handler Interfaces

DevTUI detects 5 specialized interfaces to determine how to display and interact with your handlers:

| Interface | Purpose | Key Methods |
|-----------|---------|-------------|
| **Display** | Read-only info | `Name()`, `Content()` |
| **Edit** | Interactive input | `Label()`, `Value()`, `Change(newVal)` |
| **Execution** | Action buttons | `Label()`, `Execute()` |
| **Interactive** | Rich interaction | `WaitingForUser()`, `Value()`, `Change()` |
| **Loggable** | Auto-logging | `SetLog(func(...any))` |

### 💡 Clean Terminal Policy
Handlers implementing `Loggable` receive a logger. DevTUI only displays the **most recent message** per handler to keep the view focused. Full history is preserved for debugging.

#### 🔄 Animated Progress Logs
For long-running operations, you can use the `LogOpen` and `LogClose` prefixes as the **first argument** to the logger. This triggers an auto-animated spinner and groups messages under the same line.

```go
// Start animation (use "[..." literal or devtui.LogOpen)
handler.log("[...", "Deploying to production")

// ... long operation ...

// Stop animation and show final result (use "...]" literal or devtui.LogClose)
handler.log("...]", "Deployment complete")
```

## ⌨️ Navigation & Shortcuts

- **Tab / Shift+Tab**: Switch tabs
- **Arrows**: Navigate fields / Scroll view
- **Enter / Esc**: Execute (Edit) / Cancel
- **Global Shortcuts**: Handlers can implement `Shortcuts() []map[string]string` to register keys (e.g., 't' for test) that work from any tab.

## 📚 Further Reading

- [→ Why DevTUI? (Full Purpose)](docs/DESCRIPTION.md)
- [→ Complete Demo Example](example/demo/main.go)
- [→ Implementation Examples](example/)

---
[Contributing](https://github.com/tinywasm/cdvelop/blob/main/CONTRIBUTING.md) | Built with [Bubbletea](https://github.com/charmbracelet/bubbletea)