Crates.io | liblouis |
lib.rs | liblouis |
version | 0.4.0 |
created_at | 2025-09-26 00:01:15.887949+00 |
updated_at | 2025-09-26 00:01:15.887949+00 |
description | Safe, idiomatic Rust bindings for BrlAPI (BRLTTY's braille display API) |
homepage | https://codeberg.org/hjozwiak/brlapi-rs |
repository | https://codeberg.org/hjozwiak/brlapi-rs |
max_upload_size | |
id | 1855230 |
size | 33,156 |
Safe, idiomatic Rust bindings for BrlAPI, the Application Programming Interface for BRLTTY (the screen reader for blind people using braille displays).
Safe and idiomatic: Memory-safe Rust wrappers around the C BrlAPI library
Automatic resource management: Connections and TTY modes are cleaned up automatically
Thread-safe: Uses BrlAPI's handle-based API for thread safety
Cross-platform: Works on Linux, macOS, and other Unix-like systems
Comprehensive: Covers all major BrlAPI functionality including:
Well-documented: Extensive documentation with examples
Add this to your Cargo.toml
:
[dependencies]
brlapi = "0.4"
use brlapi::util;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Send a quick message - handles everything automatically
util::send_message("Hello from Rust!")?;
Ok(())
}
use brlapi::{Connection, text};
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Connect to BrlAPI
let connection = Connection::open()?;
// Get display information
let (width, height) = connection.display_size()?;
println!("Braille display: {width}×{height} cells");
// Send multiple oneshot messages
text::oneshot::write_message(&connection, "First message")?;
text::oneshot::write_message(&connection, "Second message")?;
// Connection automatically closed when dropped
Ok(())
}
use brlapi::{Connection, TtyMode};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let connection = Connection::open()?;
// TTY mode with automatic cleanup when dropped
let (tty_mode, tty_num) = TtyMode::enter_auto(&connection)?;
println!("Using virtual console {tty_num}");
// Use convenience methods on TtyMode for efficient multiple writes
tty_mode.write_text("First line")?;
tty_mode.write_text("Second line")?;
tty_mode.write_notification("Notification without cursor")?;
// TTY mode automatically exited here when tty_mode goes out of scope
Ok(())
}
use brlapi::{Connection, text};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let connection = Connection::open()?;
// Get user's preferred contraction table from BRLTTY
let user_table = connection.user_contraction_table()?;
println!("Using contraction table: {}", user_table);
// Send contracted text using user preferences
text::oneshot::write_contracted_message(&connection, "Hello world")?;
// Or use specific table if needed
text::oneshot::write_contracted_message_with_table(
&connection, "Hello world", "en-us-g2.ctb")?;
Ok(())
}
BrlAPI development libraries: Required for building
sudo apt install libbrlapi-dev
sudo dnf install brlapi-devel
sudo pacman -S brltty
BRLTTY daemon: Required for runtime
Most distributions: sudo systemctl start brltty
This library works with any braille display supported by BRLTTY, including:
HIMS: BrailleSense, BrailleEdge, SyncBraille
Freedom Scientific: Focus, PAC Mate
HumanWare: Brailliant, BrailleNote
Baum: VarioConnect, SuperVario, EcoVario
HandyTech: Braille Star, Active Braille
Alva: Satellite, BC series
And many more…
This workspace consists of four main crates:
brlapi-sys
- Low-level BrlAPI FFI bindingsbindgen
louis-sys
- Low-level liblouis FFI bindingsbindgen
from liblouis headerslouis
- Safe liblouis wrapperSafe Rust abstractions over louis-sys
Thread-safe braille contraction and translation
Table resolution and locale handling
Integrated with brlapi
for seamless contraction
brlapi
- High-level safe wrapperSafe Rust abstractions over brlapi-sys
Automatic resource management with RAII
Idiomatic error handling with Result<T, BrlApiError>
Thread-safe operations using handle-based API
Integrated liblouis support for braille contraction
In the workspace:
cargo build
For release builds:
cargo build --release
cargo test
Note: Some tests require a running BRLTTY daemon to pass completely.
For CI environments or resource-constrained systems, you can control test behavior:
CI=1
- Automatically reduces concurrency levels
BRLAPI_TEST_THREADS
- Number of threads for concurrent tests (default: 5, CI: 2)
BRLAPI_TEST_CONNECTIONS
- Number of connections for multi-connection tests (default: 3, CI: 2)
See the examples/
directory for more examples:
simple.rs
- Basic usage with automatic TTY detectiontutorial.rs
- Comprehensive tutorial with all featureserror_handling.rs
- Demonstrates proper error handling patternscooperative_notifications.rs
- Simple cooperative braille notificationsintegration_test.rs
- Complete liblouis integration testingraw_mode_demo.rs
- Safe raw mode demonstration (requires --features dangerous-raw-mode
)raw_mode_firmware_pattern.rs
- Advanced firmware simulation (requires --features dangerous-raw-mode
)suspend_mode_demo.rs
- Suspend mode demonstration (requires --features dangerous-suspend-mode
)Run an example with:
cargo run --example simple
cargo run --example tutorial
cargo run --example integration_test
cargo run --example cooperative_notifications
cargo run --example raw_mode_demo --features dangerous-raw-mode
API Documentation - Complete API reference
BrlAPI Manual - Official BrlAPI documentation
BRLTTY User Manual - BRLTTY setup and configuration
This project is licensed under the GNU Lesser General Public License v2.1 or later - see the LICENSE
file for details.
This is the same license as BrlAPI and BRLTTY, ensuring compatibility with the broader ecosystem.