1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
// (C) 2025 - Enzo Lombardi
//! 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
//!
//! ```rust,no_run
//! 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
//! - [`geometry`](core::geometry) - Point, Rect for positioning
//! - [`event`](core::event) - Event handling and keyboard/mouse input
//! - [`command`](core::command) - Command IDs and routing
//! - [`error`](core::error) - Error types and Result alias
//! - [`palette`](core::palette) - Color management
//!
//! - **[`views`]** - Built-in widgets and view components
//! - [`View`](views::View) - Base trait for all UI components
//! - [`Window`](views::window::Window), [`Dialog`](views::dialog::Dialog) - Containers
//! - [`Button`](views::button::Button), [`InputLine`](views::input_line::InputLine) - Controls
//! - [`Editor`](views::editor::Editor) - Multi-line text editor
//! - [`MenuBar`](views::menu_bar::MenuBar), [`StatusLine`](views::status_line::StatusLine) - Navigation
//!
//! - **[`app`]** - Application infrastructure
//! - [`Application`](app::Application) - Main application coordinator
//!
//! - **[`terminal`]** - Terminal abstraction layer
//! - [`Terminal`](terminal::Terminal) - Crossterm-based rendering backend
//!
//! ## Application Structure
//!
//! ```text
//! Application
//! ├── Terminal (crossterm backend)
//! ├── Desktop (window manager)
//! │ ├── Background
//! │ └── Windows/Dialogs
//! │ └── Child widgets (buttons, inputs, etc.)
//! ├── MenuBar (optional)
//! └── StatusLine (optional)
//! ```
//!
//! # Examples
//!
//! ## Creating a Dialog
//!
//! ```rust,no_run
//! use turbo_vision::prelude::*;
//! use turbo_vision::views::{dialog::Dialog, button::Button, static_text::StaticText};
//!
//! # fn create_dialog() -> Box<Dialog> {
//! 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
//!
//! ```rust,no_run
//! use turbo_vision::prelude::*;
//! # use turbo_vision::app::Application;
//! # use turbo_vision::core::error::Result;
//! # fn example(mut app: Application) -> Result<()> {
//!
//! 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;
//! }
//! _ => {}
//! }
//! }
//! }
//! }
//! # Ok(())
//! # }
//! ```
//!
//! # Borland Turbo Vision Compatibility
//!
//! This implementation maintains conceptual compatibility with Borland Turbo Vision
//! while modernizing the design for Rust's ownership model:
//!
//! - **TView** → [`View`](views::View) trait
//! - **TWindow** → [`Window`](views::window::Window)
//! - **TDialog** → [`Dialog`](views::dialog::Dialog)
//! - **TButton** → [`Button`](views::button::Button)
//! - **TInputLine** → [`InputLine`](views::input_line::InputLine)
//! - **TProgram** → [`Application`](app::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](https://github.com/anthropics/turbo-vision/tree/main/examples) - Complete working examples
//! - [Borland TV Documentation](https://github.com/magiblot/tvision) - Original reference
// Core modules
// SSH server support (only available with ssh feature)
// Test utilities (only available with test-util feature)
// Re-export commonly used types