Thank you for your interest in contributing to bevy_tui_texture! This document provides guidelines and information for contributors.
- Getting Started
- Development Setup
- Code Style
- Testing
- Submitting Changes
- Project Structure
- Performance Guidelines
- Fork the Repository - Create your own fork of the project
- Clone Your Fork -
git clone https://github.com/YOUR_USERNAME/bevy_tui_texture.git - Create a Branch -
git checkout -b feature/your-feature-name - Make Changes - Implement your feature or fix
- Test - Run tests and examples to verify your changes
- Submit PR - Push to your fork and create a pull request
- Rust 1.96 or later (2024 edition)
- A GPU with WGPU support
- Basic familiarity with Bevy, ratatui, and WGPU
# Clone the repository
git clone https://github.com/tt-toe/bevy_tui_texture.git
cd bevy_tui_texture
# Build the project
cargo build
# Run tests
cargo test
# Run an example
cargo run --example helloworldExamples are the best way to test your changes:
# Basic examples
cargo run --example helloworld
cargo run --example widget_catalog_2d
cargo run --example multiple_terminals
# 3D examples
cargo run --example widget_catalog_3d
cargo run --example shader_mesh
cargo run --example retro_crt
# Performance testing
cargo run --release --example benchmark
cargo run --release --example benchmark_partialSee README.md's "Examples" section for the full list, one per feature area.
- Follow the Rust Style Guide
- Use
cargo fmtto format code before committing - Use
cargo clippyto catch common mistakes - Maximum line length: 100 characters (soft limit)
- All public APIs must have documentation comments (
///) - Module-level documentation should explain purpose and architecture
- Examples should be included for non-trivial functions
- Update README.md if adding new features
Example (matching the actual style used in src/setup.rs):
/// Requests a resize to `cols` × `rows`. A no-op if the terminal is
/// already that size. No GPU work at the call site - the destination
/// `Image` is recreated in place, and the sibling `TerminalDimensions`
/// component (and, for a `TuiKind::WorldQuad`, the mesh's aspect ratio)
/// update automatically on the next `gpu_flush_system` pass.
///
/// # Example
///
/// ```no_run
/// # use bevy_tui_texture::prelude::*;
/// # fn resize(mut tui: bevy::prelude::Mut<Tui>) {
/// tui.request_resize(80, 25);
/// # }
/// ```
pub fn request_resize(&mut self, cols: u16, rows: u16) {
// ...
}# Run all tests
cargo test --all-features
# Run one test by name (works across every #[cfg(test)] module)
cargo test resize_to_the_current_size_is_a_no_op
# Run every test in one module
cargo test tui_flush_tests::
# Run tests with logging
RUST_LOG=debug cargo test --all-features- There is no dedicated
tests/directory - add unit tests as an inline#[cfg(test)] mod ...next to the code they cover (seesrc/setup.rs,src/input/mod.rs,src/fonts.rsfor the existing pattern - often several test submodules per file, one per concern) - Prefer testing pure-CPU logic directly (coordinate mapping, dirty tracking, font fallback order, hit-region decoding, ...) - almost everything in this crate can be tested with no GPU adapter at all
- If a test genuinely needs a GPU (a
RenderDevice/RenderQueue), make it skip gracefully when no adapter is available rather than failing CI on headless runners - seeflush_renders_drawn_content_synchronouslyinsrc/setup.rsfor the pattern - Test both success and error cases, including edge cases and boundary conditions
Example (matching the actual style used in src/input/mod.rs):
#[cfg(test)]
mod pixel_to_cell_tests {
use super::super::pixel_to_cell;
#[test]
fn origin_maps_to_first_cell() {
assert_eq!(pixel_to_cell(0.0, 0.0, 8.0, 16.0, 80, 24), (0, 0));
}
#[test]
fn out_of_bounds_pixels_clamp_instead_of_wrapping_or_panicking() {
assert_eq!(
pixel_to_cell(-50.0, -50.0, 8.0, 16.0, 80, 24),
(0, 0),
"negative input must clamp to the first cell"
);
}
}- Update Documentation - Ensure all code changes are documented
- Add Tests - Include tests for new features or bug fixes
- Run CI Checks - Ensure
cargo test,cargo clippy, andcargo fmtpass - Update CHANGELOG - Add entry describing your changes
- Create PR - Provide clear description of changes and motivation
## Description
Brief description of what this PR does.
## Motivation
Why is this change needed? What problem does it solve?
## Changes
- List of specific changes made
- Breaking changes (if any)
## Testing
- How was this tested?
- Which examples were run?
## Checklist
- [ ] Code follows project style guidelines
- [ ] Documentation updated
- [ ] Tests added/updated
- [ ] All tests pass
- [ ] Examples run successfullybevy_tui_texture/
├── src/
│ ├── lib.rs # Crate entry point, prelude, public re-exports
│ ├── bevy_plugin.rs # TerminalPlugin, TerminalSystemSet, render-world GPU dispatch
│ ├── setup.rs # Tui, TerminalTexture, TuiRequest, AttachTerminal - the spawn/draw API
│ ├── fonts.rs # Font loading, Fonts fallback slots, font identity
│ ├── colors.rs # ratatui <-> RGB color conversion
│ ├── backend/
│ │ ├── mod.rs # Backend module entry, GPU pipelines, texture atlas plumbing
│ │ ├── bevy_backend.rs # BevyTerminalBackend (the ratatui::backend::Backend impl)
│ │ ├── rasterize.rs # Glyph rasterization (rustybuzz + raqote)
│ │ └── programmatic_glyphs/ # Box-drawing, braille, block elements, powerline
│ ├── input/
│ │ ├── mod.rs # Input event handling, focus, hit-testing dispatch
│ │ └── ray.rs # 3D mouse raycasting (feature `3d`)
│ └── utils/
│ ├── mod.rs # Shared small utilities (outline geometry, ...)
│ ├── text_atlas.rs # GPU glyph cache (LRU-evicted)
│ └── plan_cache.rs # Text shaping cache
└── examples/ # Example applications, one per feature area (see README.md)
├── assets/ # Fonts, glTF model, shaders (shared by native + wasm)
└── web/ # WASM demo site (index.html, generated wasm/js)
tui.draw(...)is designed to be called every frame regardless of whether content changed - a byte-identical redraw is a free no-op (see CLAUDE.md's "Terminal Rendering" section), so don't build change-detection around it yourself- Share one
Fonts(Arc<Fonts>) across every terminal that uses the same font - they then also share one glyph atlas and rasterize each glyph only once, instead of paying for it per terminal - Avoid creating new fonts or textures in hot loops
- Use
Arcto share immutable data instead of cloning
Two benchmark examples target different workload shapes - see each one's module doc comment for details:
# Full-frame throughput (every cell redrawn every frame)
cargo run --release --example benchmark
# Isolates the cost of unchanged-frame / partial-row redraws
BENCH_MODE=static cargo run --release --example benchmark_partial
BENCH_MODE=partial cargo run --release --example benchmark_partial
# Profile with perf (Linux)
CARGO_PROFILE_RELEASE_DEBUG=true cargo build --release --example benchmark
perf record --call-graph dwarf ./target/release/examples/benchmark
perf reportAlways compare --release numbers against --release numbers - debug
builds are not representative and must not be compared across runs.
Known incomplete spots, from the TODOs currently in the code:
-
src/backend/programmatic_glyphs/box_drawing.rs- remaining box-drawing glyphs (U+250C-U+257F) -
src/backend/programmatic_glyphs/block_elements.rs- proper dark shade block pattern (currently an approximation) -
src/backend/bevy_backend.rs- text extraction from the backend's cell buffer (for accessibility / copy-paste support)
Beyond those:
- Additional examples demonstrating advanced features
- Better error messages and debugging tools
- Documentation improvements
- Alternative font backends
- Open an issue for bugs or feature requests
- Start a discussion for questions or ideas
- Check existing issues before creating new ones
By contributing to bevy_tui_texture, you agree that your contributions will be licensed under the same terms as the project (MIT).
Thank you for contributing to bevy_tui_texture!