Expand description
Turbo Vision - A modern Text User Interface (TUI) framework for Rust.
Turbo Vision is a Rust port of the classic Borland Turbo Vision framework, providing a powerful and flexible system for building terminal-based applications with a rich set of widgets and an event-driven architecture.
§Features
- Event-driven architecture - Handle keyboard, mouse, and custom events
- Flexible view hierarchy - Compose UIs from reusable widget components
- Built-in widgets - Windows, dialogs, buttons, input fields, lists, menus
- Syntax highlighting - Extensible syntax highlighting system for editors
- Command system - Global command routing and enable/disable states
- Clipboard support - Copy/paste operations
- History management - Input history for text fields
- Double-buffered rendering - Flicker-free terminal updates
- Mouse support - Full mouse capture and tracking
- Borland TV compatibility - Familiar API for Turbo Vision users
§Quick Start
use turbo_vision::prelude::*;
fn main() -> turbo_vision::core::error::Result<()> {
// Create application with terminal
let mut app = Application::new()?;
// Create a simple window
let mut window = turbo_vision::views::window::Window::new(
Rect::new(10, 5, 50, 15),
"My First Window"
);
// Add a button
let button = turbo_vision::views::button::Button::new(
Rect::new(15, 5, 25, 7),
"Click Me",
turbo_vision::core::command::CM_OK,
false
);
window.add(Box::new(button));
// Add window to desktop
app.desktop.add(Box::new(window));
// Run event loop
app.running = true;
while app.running {
app.desktop.draw(&mut app.terminal);
app.terminal.flush()?;
if let Ok(Some(mut event)) = app.terminal.poll_event(
std::time::Duration::from_millis(50)
) {
app.desktop.handle_event(&mut event);
if event.what == EventType::Command {
match event.command {
CM_QUIT => app.running = false,
CM_OK => {
// Handle button click
app.running = false;
}
_ => {}
}
}
}
}
app.terminal.shutdown()?;
Ok(())
}§Architecture
The framework is organized into several key modules:
§Core Modules
-
core- Fundamental types and utilities -
views- Built-in widgets and view components -
app- Application infrastructureApplication- Main application coordinator
-
terminal- Terminal abstraction layerTerminal- Crossterm-based rendering backend
§Application Structure
Application
├── Terminal (crossterm backend)
├── Desktop (window manager)
│ ├── Background
│ └── Windows/Dialogs
│ └── Child widgets (buttons, inputs, etc.)
├── MenuBar (optional)
└── StatusLine (optional)§Examples
§Creating a Dialog
use turbo_vision::prelude::*;
use turbo_vision::views::{dialog::Dialog, button::Button, static_text::StaticText};
let dialog_bounds = Rect::new(20, 8, 60, 16);
let mut dialog = Dialog::new_modal(dialog_bounds, "Confirmation");
// Add message text
let text = StaticText::new(
Rect::new(2, 2, 38, 3),
"Are you sure you want to continue?"
);
dialog.add(Box::new(text));
// Add OK button
let ok_button = Button::new(
Rect::new(10, 4, 18, 6),
"OK",
turbo_vision::core::command::CM_OK,
true // default button
);
dialog.add(Box::new(ok_button));
// Add Cancel button
let cancel_button = Button::new(
Rect::new(22, 4, 32, 6),
"Cancel",
turbo_vision::core::command::CM_CANCEL,
false
);
dialog.add(Box::new(cancel_button));
dialog§Handling Events
use turbo_vision::prelude::*;
app.running = true;
while app.running {
// Draw UI
app.desktop.draw(&mut app.terminal);
app.terminal.flush()?;
// Poll for events
if let Ok(Some(mut event)) = app.terminal.poll_event(
std::time::Duration::from_millis(50)
) {
// Let desktop handle event
app.desktop.handle_event(&mut event);
// Check for commands
if event.what == EventType::Command {
match event.command {
CM_QUIT => {
app.running = false;
}
_ => {}
}
}
}
}§Borland Turbo Vision Compatibility
This implementation maintains conceptual compatibility with Borland Turbo Vision while modernizing the design for Rust’s ownership model:
- TView →
Viewtrait - TWindow →
Window - TDialog →
Dialog - TButton →
Button - TInputLine →
InputLine - TProgram →
Application
Event handling uses Rust’s ownership system instead of raw pointers, with events bubbling up through the call stack rather than using owner pointers.
§See Also
- Examples - Complete working examples
- Borland TV Documentation - Original reference
Modules§
- app
- Application module providing the main application structure and event loop.
- core
- Core module containing fundamental TUI framework types.
- helpers
- Helper functions and utilities for common UI patterns.
- prelude
- terminal
- Terminal abstraction layer for turbo-vision.
- views
- Views module containing all UI components and widgets.