### Run basic example with cargo run --example basic Source: https://github.com/andrewdmorgan/termrender/blob/main/term_render/README.md Command to run the basic example from the examples directory. Requires the project to be built with Cargo. ```bash cargo run --example basic ``` -------------------------------- ### Push branch with git push origin Source: https://github.com/andrewdmorgan/termrender/blob/main/term_render/README.md Command to push the feature branch to the remote repository. Part of the contribution workflow. ```bash git push origin feature/amazing-feature ``` -------------------------------- ### Commit changes with git commit -m Source: https://github.com/andrewdmorgan/termrender/blob/main/term_render/README.md Command to commit changes with a message. Part of the contribution workflow. ```bash git commit -m 'Add amazing feature' ``` -------------------------------- ### Create feature branch with git checkout -b Source: https://github.com/andrewdmorgan/termrender/blob/main/term_render/README.md Command to create a new feature branch for contributing. Part of the contribution workflow. ```bash git checkout -b feature/amazing-feature ``` -------------------------------- ### Basic TermRender application with callback, scene, and widget Source: https://github.com/andrewdmorgan/termrender/blob/main/term_render/README.md Shows the minimal structure of a TermRender app: an AppData struct for state, an app_callback that runs each frame and returns true to exit, and a main function that creates the App, builds a StaticWidgetBuilder widget, attaches it to a Scene, and runs the app. The callback exits on Enter key press or after 15 seconds. Widget names must be unique within a scene because the backend renderer references Windows by that string. ```rust use term_render::{self, event_handler::KeyCode}; use term_render::widget_impls::WidgetBuilder; // this acts as the callback that is called every frame // this is the entry point and any logic needs to branch out from here fn app_callback(app: &mut term_render::App, data: &mut AppData) -> Result { // place app logic here if app.events.read().contains_key_code(KeyCode::Return) { return Ok(true); } if data.time.elapsed().as_secs_f64() > 15.0 { return Ok(true); } Ok(false) // return true to exit the app } // defining the application data structure // this can contain any data you want to use in the app callback struct AppData { pub time: std::time::Instant, } #[tokio::main(flavor = "multi_thread", worker_threads = 10)] async fn main() -> tokio::io::Result<()> { // creating an instance of the app let mut app = term_render::App::new()?; let data = AppData { time: std::time::Instant::now(), }; // creating a new scene to attach widgets to let mut scene = term_render::widget::Scene::new(); // creating a widget using the builder trait. let (widget, window) = term_render::widget_impls::StaticWidgetBuilder::::builder(String::from("name")) .with_border(true) .with_renderer(Box::new(|_size, _position| { Some(vec![]) })) .with_position((10, 10)) .with_size((50, 10)) .build(&app.area.read()).unwrap(); scene.add_widget(widget, window, &mut *app.renderer.write()).unwrap(); app.scene = Some(scene); // running the application with the callback, and provided data for state tracking. app.run(data, |data, app_instance| { app_callback(app_instance, data) }).await.unwrap(); Ok(()) } ``` -------------------------------- ### Add TermRender and Tokio dependencies to Cargo.toml Source: https://github.com/andrewdmorgan/termrender/blob/main/term_render/README.md Declares the term_render crate version 0.1.3 and Tokio 1.47.1 with the 'full' feature set, required for the async runtime used by the library. ```toml [dependencies] term_render = "0.1.3" tokio = { version = "1.47.1", features = ["full"] } ``` -------------------------------- ### Implement Widget trait for custom widget Source: https://github.com/andrewdmorgan/termrender/blob/main/term_render/README.md Shows the required structure for a custom widget by implementing the Widget trait. The type parameter C represents user-defined app data state. Each widget instance must return a unique identifier from get_window_ref(). The update_with_events and update_render methods handle event processing and rendering updates respectively. ```rust use term_render::{Widget, SendSync, event_handler::KeyParser}; // Where type C is the user defined app data state struct MyCustomWidget { // Your widget state } impl Widget for MyCustomWidget { fn get_window_ref(&self) -> String { "my_custom_widget".to_string() // note: each widget instance requires a unique identifyer } fn update_with_events(&mut self, events: &SendSync) { // Handle events } fn update_render(&mut self, window: &mut Window, area: &Rect) { // Update rendering } // ... implement other required methods } ```