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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
// SPDX-License-Identifier: LGPL-2.1
//! High-level Rust bindings for BrlAPI
//!
//! This crate provides safe, idiomatic Rust bindings for BrlAPI, the
//! Application Programming Interface for BRLTTY (the screen reader for
//! blind people using braille displays).
//!
//! # Overview
//!
//! BrlAPI allows applications to interact with braille displays through the
//! BRLTTY daemon. This crate provides:
//!
//! - Safe connection management with automatic cleanup
//! - Thread-safe operations using handle-based API
//! - Rust-friendly error handling with thiserror integration
//! - High-level abstractions for display operations
//!
//! # Quick Start
//!
//! For a single message (most convenient):
//! ```no_run
//! use brlapi::util;
//!
//! fn main() -> Result<(), brlapi::BrlApiError> {
//! // Send a quick message - handles everything automatically
//! util::send_message("System notification: Build completed successfully")?;
//! Ok(())
//! }
//! ```
//!
//! For multiple messages with manual management:
//! ```no_run
//! use brlapi::{Connection, text};
//!
//! fn main() -> Result<(), brlapi::BrlApiError> {
//! // Connect to BrlAPI with default settings
//! let connection = Connection::open()?;
//!
//! // Get display information
//! let (width, height) = connection.display_size()?;
//! println!("Display: {width}x{height}");
//!
//! // Send multiple oneshot messages
//! text::util::write_message(&connection, "Processing file 1 of 5")?;
//! text::util::write_message(&connection, "Processing file 2 of 5")?;
//! text::util::write_message(&connection, "All files processed")?;
//!
//! Ok(())
//! }
//! ```
//!
//! For sustained display control (most efficient):
//! ```no_run
//! use brlapi::{Connection, TtyMode};
//! use std::{thread, time::Duration};
//!
//! fn main() -> Result<(), brlapi::BrlApiError> {
//! let connection = Connection::open()?;
//! let (tty_mode, tty_num) = TtyMode::enter_auto(&connection, None)?;
//! println!("Using virtual console {tty_num}");
//!
//! // Write multiple messages efficiently
//! tty_mode.write_text("Monitoring system status...")?;
//! thread::sleep(Duration::from_secs(1));
//!
//! tty_mode.write_text("CPU usage: 45%, Memory: 2.1GB")?;
//! thread::sleep(Duration::from_secs(1));
//!
//! tty_mode.write_text("All systems operational")?;
//!
//! // TTY mode automatically exited when tty_mode is dropped
//! Ok(())
//! }
//! ```
//!
//! For interactive applications with key handling:
//! ```no_run
//! use brlapi::{Connection, TtyMode, keys::constants};
//! use std::time::Duration;
//!
//! fn main() -> Result<(), brlapi::BrlApiError> {
//! let connection = Connection::open()?;
//! let (tty_mode, _) = TtyMode::enter_auto(&connection, None)?;
//! let key_reader = tty_mode.key_reader();
//!
//! // Accept only arrow keys and escape
//! key_reader.accept_keys(brlapi::RangeType::Code, &[
//! constants::KEY_SYM_LEFT,
//! constants::KEY_SYM_RIGHT,
//! constants::KEY_SYM_UP,
//! constants::KEY_SYM_DOWN,
//! constants::KEY_SYM_ESCAPE,
//! ])?;
//!
//! tty_mode.write_text("Use arrow keys to navigate, ESC to quit")?;
//!
//! loop {
//! match key_reader.read_key_timeout(Duration::from_secs(1))? {
//! Some(key_code) => {
//! if key_code == constants::KEY_SYM_ESCAPE {
//! tty_mode.write_text("Goodbye!")?;
//! break;
//! } else if constants::utils::is_keysym(key_code) {
//! tty_mode.write_text(&format!("Key: {:04X}", key_code))?;
//! }
//! }
//! None => {
//! // Timeout - continue waiting
//! }
//! }
//! }
//!
//! Ok(())
//! }
//! ```
//!
//! For display information and capabilities:
//! ```no_run
//! use brlapi::Connection;
//!
//! fn main() -> Result<(), brlapi::BrlApiError> {
//! let connection = Connection::open()?;
//!
//! // Convenient direct access via connection
//! let display = connection.display_info()?;
//! println!("Connected to {} braille display:", display.driver_name());
//! println!(" Model: {}", display.model_identifier());
//! println!(" Size: {}x{} cells ({} total)",
//! display.width(), display.height(), display.total_cells());
//!
//! if display.is_single_line() {
//! println!(" Type: Standard single-line display");
//! } else {
//! println!(" Type: Multi-line display");
//! }
//!
//! // Or query individual properties
//! let (width, height) = connection.display_size()?;
//! let driver = connection.display_driver()?;
//!
//! Ok(())
//! }
//! ```
//!
//! # Connection Management
//!
//! Connections are managed through the [`Connection`] struct, which automatically
//! handles cleanup when dropped:
//!
//! ```no_run
//! use brlapi::{Connection, ConnectionSettings};
//!
//! // Default connection
//! let conn = Connection::open()?;
//!
//! // Custom connection settings
//! let settings = ConnectionSettings::localhost();
//! let conn = Connection::open_with_settings(Some(&settings))?;
//!
//! // Connection is automatically closed when conn goes out of scope
//! # Ok::<(), brlapi::BrlApiError>(())
//! ```
//!
//! # TTY Mode Management
//!
//! For RAII-style TTY mode management, use the [`TtyMode`] wrapper:
//!
//! ```no_run
//! use brlapi::{Connection, TtyMode};
//!
//! fn main() -> Result<(), brlapi::BrlApiError> {
//! let connection = Connection::open()?;
//!
//! // Automatic TTY detection with RAII cleanup
//! let (tty_mode, tty_num) = TtyMode::enter_auto(&connection, None)?;
//! println!("Using virtual console {tty_num}");
//!
//! tty_mode.write_text("Application started successfully")?;
//! // TTY mode automatically exited when tty_mode is dropped
//!
//! Ok(())
//! }
//! ```
//!
//! For compatibility with existing code, you can also use `TryFrom`:
//!
//! ```no_run
//! use brlapi::{Connection, TtyMode};
//!
//! fn main() -> Result<(), brlapi::BrlApiError> {
//! let connection = Connection::open()?;
//! let tty_mode = TtyMode::try_from(&connection)?;
//!
//! tty_mode.write_text("Legacy mode compatibility test")?;
//!
//! Ok(())
//! }
//! ```
//!
//! # Cooperative Display Sharing
//!
//! For applications that need to share the braille display politely with
//! screen readers like Orca, use the [`cooperative`] module:
//!
//! ```no_run
//! use brlapi::cooperative;
//!
//! fn main() -> Result<(), brlapi::BrlApiError> {
//! // Simple notifications that automatically cooperate with screen readers
//! cooperative::notify("Build completed successfully")?;
//! cooperative::alert("Critical error occurred!")?;
//!
//! Ok(())
//! }
//! ```
//!
//! For applications that need ongoing display access:
//! ```no_run
//! use brlapi::cooperative::{CooperativeDisplay, AppType};
//!
//! fn main() -> Result<(), brlapi::BrlApiError> {
//! let mut display = CooperativeDisplay::open(AppType::UserApp)?;
//!
//! // Show brief messages that automatically yield to screen readers
//! display.show_status("Processing file 5 of 20")?;
//! display.show_brief_message("Press Enter to continue", std::time::Duration::from_secs(3))?;
//!
//! Ok(())
//! }
//! ```
// Re-export main types for convenience
pub use Connection;
pub use ;
pub use Display;
pub use ;
pub use ;
pub use ParameterMonitor;
pub use ConnectionSettings;
pub use ;
pub use TtyMode;
/// Library version information
/// Utility functions for working with BrlAPI
// Include comprehensive documentation tests