oxedyne/fe2o3/fe2o3_text/tests/annealer_corpus/ratatui_lib.rs
24.2 KiB, 1 run
created by r1870400018:11778, which is this file's identity for as long as the history lasts, whatever it is later renamed to
download · who wrote it · its history
| 1 | #![no_std] |
| 2 | // show the feature flags in the generated documentation |
| 3 | #![cfg_attr(docsrs, feature(doc_cfg))] |
| 4 | #![doc( |
| 5 | html_logo_url = "https://raw.githubusercontent.com/ratatui/ratatui/main/assets/logo.png", |
| 6 | html_favicon_url = "https://raw.githubusercontent.com/ratatui/ratatui/main/assets/favicon.ico" |
| 7 | )] |
| 8 | #![warn(missing_docs)] |
| 9 | //!  |
| 10 | //! |
| 11 | //! <div align="center"> |
| 12 | //! |
| 13 | //! [![Crate Badge]][Crate] [![Docs Badge]][API Docs] [![CI Badge]][CI Workflow] [![Deps.rs |
| 14 | //! Badge]][Deps.rs]<br> [![Codecov Badge]][Codecov] [![License Badge]](./LICENSE) [![Sponsors |
| 15 | //! Badge]][GitHub Sponsors]<br> [![Discord Badge]][Discord Server] [![Matrix Badge]][Matrix] |
| 16 | //! [![Forum Badge]][Forum]<br> |
| 17 | //! |
| 18 | //! [Ratatui Website] · [API Docs] · [Examples] · [Changelog] · [Breaking Changes]<br> |
| 19 | //! [Contributing] · [Report a bug] · [Request a Feature] · [Create a Pull Request] |
| 20 | //! |
| 21 | //! </div> |
| 22 | //! |
| 23 | //! [Ratatui][Ratatui Website] is a crate for cooking up terminal user interfaces in Rust. It is a |
| 24 | //! lightweight library that provides a set of [widgets](`widgets`) and utilities to build complex |
| 25 | //! Rust TUIs. Ratatui was forked from the [tui-rs] crate in 2023 in order to continue its |
| 26 | //! development. |
| 27 | //! |
| 28 | //! ## Quickstart |
| 29 | //! |
| 30 | //! Add `ratatui` and `crossterm` as dependencies to your cargo.toml: |
| 31 | //! |
| 32 | //! ```shell |
| 33 | //! cargo add ratatui crossterm |
| 34 | //! ``` |
| 35 | //! |
| 36 | //! Then you can create a simple "Hello World" application: |
| 37 | //! |
| 38 | //! ```rust,no_run |
| 39 | //! use crossterm::event; |
| 40 | //! |
| 41 | //! fn main() -> std::io::Result<()> { |
| 42 | //! ratatui::run(|mut terminal| { |
| 43 | //! loop { |
| 44 | //! terminal.draw(|frame| frame.render_widget("Hello World!", frame.area()))?; |
| 45 | //! if event::read()?.is_key_press() { |
| 46 | //! break Ok(()); |
| 47 | //! } |
| 48 | //! } |
| 49 | //! }) |
| 50 | //! } |
| 51 | //! ``` |
| 52 | //! |
| 53 | //! The full code for this example which contains a little more detail is in the [Examples] |
| 54 | //! directory. For more guidance on different ways to structure your application see the |
| 55 | //! [Application Patterns] and [Hello Ratatui tutorial] sections in the [Ratatui Website] and the |
| 56 | //! various [Examples]. There are also several starter [Templates] available to help you get |
| 57 | //! started quickly with common patterns. |
| 58 | //! |
| 59 | //! ## Which setup path should I use? |
| 60 | //! |
| 61 | //! Most application authors should start with one of these entry points: |
| 62 | //! |
| 63 | //! - Use [`run()`] for normal applications. It initializes the terminal, runs your app, and |
| 64 | //! restores the terminal on exit. |
| 65 | //! - Use [`init()`] / [`restore()`] (or [`try_init()`] / [`try_restore()`]) when you want manual |
| 66 | //! control over terminal lifetime and the event loop structure. |
| 67 | //! - Use [`init_with_options()`] / [`try_init_with_options()`] when you need a custom [`Viewport`], |
| 68 | //! such as inline rendering or a fixed drawing region. |
| 69 | //! |
| 70 | //! Reach for [`Terminal::new`] or [`Terminal::with_options`] directly only when you need custom |
| 71 | //! backend construction or terminal setup that Ratatui's convenience functions do not manage. |
| 72 | //! |
| 73 | //! ## Which crate should I use? |
| 74 | //! |
| 75 | //! Most application authors should stay in this `ratatui` crate. It is the docs.rs entry point |
| 76 | //! for building apps and re-exports the pieces most applications need. |
| 77 | //! |
| 78 | //! Reach for other crates in the workspace only when you specifically need a lower-level layer: |
| 79 | //! |
| 80 | //! - [`ratatui-core`] for widget libraries, custom integrations, and lower-level rendering |
| 81 | //! contracts |
| 82 | //! - [`ratatui-widgets`] when you only need the built-in widgets crate as a dependency |
| 83 | //! - [`ratatui-crossterm`], [`ratatui-termion`], or [`ratatui-termwiz`] when you need to select and |
| 84 | //! depend on a backend crate directly |
| 85 | //! |
| 86 | //! # Other documentation |
| 87 | //! |
| 88 | //! - [Ratatui Website] - explains the library's concepts and provides step-by-step tutorials |
| 89 | //! - [Tutorials] - step-by-step guides including [Hello Ratatui tutorial] and [Counter App] |
| 90 | //! - [Recipes] - practical how-to guides for common tasks and patterns |
| 91 | //! - [FAQ] - frequently asked questions and answers |
| 92 | //! - [Templates] - pre-built project templates using [Cargo Generate] |
| 93 | //! - [Showcase] - a gallery of applications and widgets built with Ratatui |
| 94 | //! - [Ratatui Forum][Forum] - a place to ask questions and discuss the library |
| 95 | //! - [API Docs] - the full API documentation for the library on docs.rs. |
| 96 | //! - [Examples] - a collection of examples that demonstrate how to use the library. |
| 97 | //! - [Contributing] - Please read this if you are interested in contributing to the project. |
| 98 | //! - [Changelog] - generated by [git-cliff] utilizing [Conventional Commits]. |
| 99 | //! - [Breaking Changes] - a list of breaking changes in the library. |
| 100 | //! |
| 101 | //! You can also watch the [FOSDEM 2024 talk] about Ratatui which gives a brief introduction to |
| 102 | //! terminal user interfaces and showcases the features of Ratatui, along with a hello world demo. |
| 103 | //! |
| 104 | //! ## Getting Help |
| 105 | //! |
| 106 | //! If you need help or have questions, check out our [FAQ] for common questions and solutions. |
| 107 | //! You can also join our community on [Discord][Discord Server], [Matrix], or post on our |
| 108 | //! [Forum] for assistance and discussions. |
| 109 | //! |
| 110 | //! # Crate Organization |
| 111 | //! |
| 112 | //! Starting with Ratatui 0.30.0, the project was reorganized into a modular workspace to improve |
| 113 | //! compilation times, API stability, and dependency management. Most applications should continue |
| 114 | //! using this main `ratatui` crate, which re-exports everything for convenience: |
| 115 | //! |
| 116 | //! - **[`ratatui`](crate)**: Main crate with complete functionality (recommended for apps) |
| 117 | //! - **[`ratatui-core`]**: Core traits and types for widget libraries |
| 118 | //! - **[`ratatui-widgets`]**: Built-in widget implementations |
| 119 | //! - **Backend crates**: [`ratatui-crossterm`], [`ratatui-termion`], [`ratatui-termwiz`] |
| 120 | //! - **[`ratatui-macros`]**: Macros for simplifying the boilerplate |
| 121 | //! |
| 122 | //! **For application developers**: `ratatui` remains the recommended starting point. |
| 123 | //! |
| 124 | //! **For widget library authors**: Consider depending on [`ratatui-core`] instead of the full |
| 125 | //! `ratatui` crate for better API stability and reduced dependencies. |
| 126 | //! |
| 127 | //! See [ARCHITECTURE.md] for detailed information about the crate organization and design |
| 128 | //! decisions. |
| 129 | //! |
| 130 | //! # Writing Applications |
| 131 | //! |
| 132 | //! Ratatui is based on the principle of immediate rendering with intermediate buffers. This means |
| 133 | //! that for each frame, your app must render all [`widgets`] that are supposed to be part of the |
| 134 | //! UI. This is in contrast to the retained mode style of rendering where widgets are updated and |
| 135 | //! then automatically redrawn on the next frame. See the [Rendering] section of the [Ratatui |
| 136 | //! Website] for more info. |
| 137 | //! |
| 138 | //! Ratatui uses [Crossterm] by default as it works on most platforms. See the [Installation] |
| 139 | //! section of the [Ratatui Website] for more details on how to use other backends ([Termion] / |
| 140 | //! [Termwiz]). |
| 141 | //! |
| 142 | //! Every application built with `ratatui` needs to implement the following steps: |
| 143 | //! |
| 144 | //! - Initialize the terminal (see the [`init` module] for convenient initialization functions) |
| 145 | //! - A main loop that: |
| 146 | //! - Draws the UI |
| 147 | //! - Handles input events |
| 148 | //! - Restore the terminal state |
| 149 | //! |
| 150 | //! ## Initialize and restore the terminal |
| 151 | //! |
| 152 | //! The simplest way to initialize and run a terminal application is to use the [`run()`] function, |
| 153 | //! which handles terminal initialization, restoration, and panic hooks automatically: |
| 154 | //! |
| 155 | //! ```rust,no_run |
| 156 | //! fn main() -> std::io::Result<()> { |
| 157 | //! ratatui::run(|mut terminal| { |
| 158 | //! loop { |
| 159 | //! terminal.draw(render)?; |
| 160 | //! if should_quit()? { |
| 161 | //! break Ok(()); |
| 162 | //! } |
| 163 | //! } |
| 164 | //! }) |
| 165 | //! } |
| 166 | //! |
| 167 | //! fn render(frame: &mut ratatui::Frame) { |
| 168 | //! // ... |
| 169 | //! } |
| 170 | //! |
| 171 | //! fn should_quit() -> std::io::Result<bool> { |
| 172 | //! // ... |
| 173 | //! # Ok(false) |
| 174 | //! } |
| 175 | //! ``` |
| 176 | //! |
| 177 | //! For more control over initialization and restoration, you can use [`init()`] and [`restore()`]: |
| 178 | //! |
| 179 | //! ```rust,no_run |
| 180 | //! fn main() -> std::io::Result<()> { |
| 181 | //! let mut terminal = ratatui::init(); |
| 182 | //! let result = run_app(&mut terminal); |
| 183 | //! ratatui::restore(); |
| 184 | //! result |
| 185 | //! } |
| 186 | //! |
| 187 | //! fn run_app(terminal: &mut ratatui::DefaultTerminal) -> std::io::Result<()> { |
| 188 | //! loop { |
| 189 | //! terminal.draw(render)?; |
| 190 | //! if should_quit()? { |
| 191 | //! break Ok(()); |
| 192 | //! } |
| 193 | //! } |
| 194 | //! } |
| 195 | //! # fn render(_frame: &mut ratatui::Frame) {} |
| 196 | //! # fn should_quit() -> std::io::Result<bool> { Ok(false) } |
| 197 | //! ``` |
| 198 | //! |
| 199 | //! Use [`run()`] as the default. Reach for [`init()`] / [`restore()`] when setup and teardown |
| 200 | //! should surround code outside the application closure, and see the [`init` module] documentation |
| 201 | //! for the full chooser including `try_*` and `*_with_options`. |
| 202 | //! |
| 203 | //! ### Manual Terminal and Backend Construction |
| 204 | //! |
| 205 | //! Before the convenience functions were introduced in version 0.28.1 ([`init()`]/[`restore()`]) |
| 206 | //! and 0.30.0 ([`run()`]), applications constructed [`Terminal`] and [`Backend`] instances |
| 207 | //! manually. This approach is still supported for applications that need fine-grained control over |
| 208 | //! initialization, custom backends, or terminal setup that should happen outside Ratatui's |
| 209 | //! convenience helpers. See the [`Terminal`] and [`backend`] module documentation for details. |
| 210 | //! |
| 211 | //! See the [`backend` module] and the [Backends] section of the [Ratatui Website] for more info on |
| 212 | //! the alternate screen and raw mode. Learn more about different backend options in the [Backend |
| 213 | //! Comparison] guide. |
| 214 | //! |
| 215 | //! ## Drawing the UI |
| 216 | //! |
| 217 | //! Drawing the UI is done by calling the [`Terminal::draw`] method on the terminal instance. This |
| 218 | //! method takes a closure that is called with a [`Frame`] instance. The [`Frame`] provides the size |
| 219 | //! of the area to draw to and allows the app to render any [`Widget`] using the provided |
| 220 | //! [`render_widget`] method. After this closure returns, a diff is performed and only the changes |
| 221 | //! are drawn to the terminal. See the [Widgets] section of the [Ratatui Website] and the [Widget |
| 222 | //! Recipes] for more info on creating effective UIs. |
| 223 | //! |
| 224 | //! The closure passed to the [`Terminal::draw`] method should handle the rendering of a full frame. |
| 225 | //! For guidance on setting up the terminal before drawing, see the [`init` module] documentation. |
| 226 | //! |
| 227 | //! ```rust,no_run |
| 228 | //! use ratatui::Frame; |
| 229 | //! use ratatui::widgets::Paragraph; |
| 230 | //! |
| 231 | //! fn run(terminal: &mut ratatui::DefaultTerminal) -> std::io::Result<()> { |
| 232 | //! loop { |
| 233 | //! terminal.draw(|frame| render(frame))?; |
| 234 | //! if handle_events()? { |
| 235 | //! break Ok(()); |
| 236 | //! } |
| 237 | //! } |
| 238 | //! } |
| 239 | //! |
| 240 | //! fn render(frame: &mut Frame) { |
| 241 | //! let text = Paragraph::new("Hello World!"); |
| 242 | //! frame.render_widget(text, frame.area()); |
| 243 | //! } |
| 244 | //! # fn handle_events() -> std::io::Result<bool> { Ok(false) } |
| 245 | //! ``` |
| 246 | //! |
| 247 | //! ### What happens if... |
| 248 | //! |
| 249 | //! - **If the terminal is resized:**<br> Ratatui does not redraw automatically when a resize event |
| 250 | //! arrives. Your app should continue the event loop and call [`Terminal::draw`] again. During |
| 251 | //! that render pass, Ratatui checks the backend's current size instead of assuming the resize |
| 252 | //! events were complete or up to date. This keeps layout based on the size that actually exists |
| 253 | //! when rendering, even if multiple resize events were coalesced, missed, or delivered before the |
| 254 | //! UI redraws. Fullscreen and inline viewports update their internal size during that render |
| 255 | //! pass; fixed viewports keep their configured rectangle until you call [`Terminal::resize`]. |
| 256 | //! - **If [`Terminal::try_draw`] returns an error:**<br> The render pass stops early and Ratatui |
| 257 | //! does not promise that the terminal, cursor, and internal buffers are still synchronized. In |
| 258 | //! most applications, return the error and let the surrounding setup path restore terminal state |
| 259 | //! on exit. |
| 260 | //! - **If you move the cursor directly:**<br> Cursor changes made through backend-specific APIs or |
| 261 | //! [`Terminal`] cursor methods can be overwritten by the next render pass if that pass sets |
| 262 | //! cursor state through [`Frame`]. Prefer choosing one path and using it consistently. |
| 263 | //! - **If you mutate the backend directly:**<br> Direct backend changes bypass Ratatui's diffing |
| 264 | //! and viewport bookkeeping. After doing that, run a full draw pass or clear the terminal before |
| 265 | //! assuming Ratatui's internal view still matches the screen. |
| 266 | //! |
| 267 | //! ## Handling events |
| 268 | //! |
| 269 | //! Ratatui does not include any input handling. Instead event handling can be implemented by |
| 270 | //! calling backend library methods directly. See the [Handling Events] section of the [Ratatui |
| 271 | //! Website] for conceptual information. For example, if you are using [Crossterm], you can use the |
| 272 | //! [`crossterm::event`] module to handle events. |
| 273 | //! |
| 274 | //! ```rust,no_run |
| 275 | //! use crossterm::event::{self, Event, KeyCode, KeyEvent, KeyEventKind}; |
| 276 | //! |
| 277 | //! fn handle_events() -> std::io::Result<bool> { |
| 278 | //! match event::read()? { |
| 279 | //! Event::Key(key) if key.kind == KeyEventKind::Press => match key.code { |
| 280 | //! KeyCode::Char('q') => return Ok(true), |
| 281 | //! // handle other key events |
| 282 | //! _ => {} |
| 283 | //! }, |
| 284 | //! // handle other events |
| 285 | //! _ => {} |
| 286 | //! } |
| 287 | //! Ok(false) |
| 288 | //! } |
| 289 | //! ``` |
| 290 | //! |
| 291 | //! ## Layout |
| 292 | //! |
| 293 | //! The library comes with a basic yet useful layout management object called [`Layout`] which |
| 294 | //! allows you to split the available space into multiple areas and then render widgets in each |
| 295 | //! area. This lets you describe a responsive terminal UI by nesting layouts. See the [Layout] |
| 296 | //! section of the [Ratatui Website] for more info, and check out the [Layout Recipes] for |
| 297 | //! practical examples. |
| 298 | //! |
| 299 | //! ```rust,no_run |
| 300 | //! use ratatui::Frame; |
| 301 | //! use ratatui::layout::{Constraint, Layout}; |
| 302 | //! use ratatui::widgets::Block; |
| 303 | //! |
| 304 | //! fn draw(frame: &mut Frame) { |
| 305 | //! use Constraint::{Fill, Length, Min}; |
| 306 | //! |
| 307 | //! let vertical = Layout::vertical([Length(1), Min(0), Length(1)]); |
| 308 | //! let [title_area, main_area, status_area] = vertical.areas(frame.area()); |
| 309 | //! let horizontal = Layout::horizontal([Fill(1); 2]); |
| 310 | //! let [left_area, right_area] = horizontal.areas(main_area); |
| 311 | //! |
| 312 | //! frame.render_widget(Block::bordered().title("Title Bar"), title_area); |
| 313 | //! frame.render_widget(Block::bordered().title("Status Bar"), status_area); |
| 314 | //! frame.render_widget(Block::bordered().title("Left"), left_area); |
| 315 | //! frame.render_widget(Block::bordered().title("Right"), right_area); |
| 316 | //! } |
| 317 | //! ``` |
| 318 | //! |
| 319 | //! Running this example produces the following output: |
| 320 | //! |
| 321 | //! ```text |
| 322 | //! Title Bar─────────────────────────────────── |
| 323 | //! ┌Left────────────────┐┌Right───────────────┐ |
| 324 | //! │ ││ │ |
| 325 | //! └────────────────────┘└────────────────────┘ |
| 326 | //! Status Bar────────────────────────────────── |
| 327 | //! ``` |
| 328 | //! |
| 329 | //! ## Text and styling |
| 330 | //! |
| 331 | //! The [`Text`], [`Line`] and [`Span`] types are the building blocks of the library and are used in |
| 332 | //! many places. [`Text`] is a list of [`Line`]s and a [`Line`] is a list of [`Span`]s. A [`Span`] |
| 333 | //! is a string with a specific style. |
| 334 | //! |
| 335 | //! The [`style` module] provides types that represent the various styling options. The most |
| 336 | //! important one is [`Style`] which represents the foreground and background colors and the text |
| 337 | //! attributes of a [`Span`]. The [`style` module] also provides a [`Stylize`] trait that allows |
| 338 | //! short-hand syntax to apply a style to widgets and text. See the [Styling Text] section of the |
| 339 | //! [Ratatui Website] for more info, and explore the [Styling Recipes] for creative examples. |
| 340 | //! |
| 341 | //! ```rust,no_run |
| 342 | //! use ratatui::Frame; |
| 343 | //! use ratatui::layout::{Constraint, Layout}; |
| 344 | //! use ratatui::style::{Color, Modifier, Style, Stylize}; |
| 345 | //! use ratatui::text::{Line, Span}; |
| 346 | //! use ratatui::widgets::{Block, Paragraph}; |
| 347 | //! |
| 348 | //! fn draw(frame: &mut Frame) { |
| 349 | //! let areas = Layout::vertical([Constraint::Length(1); 4]).split(frame.area()); |
| 350 | //! |
| 351 | //! let line = Line::from(vec![ |
| 352 | //! Span::raw("Hello "), |
| 353 | //! Span::styled( |
| 354 | //! "World", |
| 355 | //! Style::new() |
| 356 | //! .fg(Color::Green) |
| 357 | //! .bg(Color::White) |
| 358 | //! .add_modifier(Modifier::BOLD), |
| 359 | //! ), |
| 360 | //! "!".red().on_light_yellow().italic(), |
| 361 | //! ]); |
| 362 | //! frame.render_widget(line, areas[0]); |
| 363 | //! |
| 364 | //! // using the short-hand syntax and implicit conversions |
| 365 | //! let paragraph = Paragraph::new("Hello World!".red().on_white().bold()); |
| 366 | //! frame.render_widget(paragraph, areas[1]); |
| 367 | //! |
| 368 | //! // style the whole widget instead of just the text |
| 369 | //! let paragraph = Paragraph::new("Hello World!").style(Style::new().red().on_white()); |
| 370 | //! frame.render_widget(paragraph, areas[2]); |
| 371 | //! |
| 372 | //! // use the simpler short-hand syntax |
| 373 | //! let paragraph = Paragraph::new("Hello World!").blue().on_yellow(); |
| 374 | //! frame.render_widget(paragraph, areas[3]); |
| 375 | //! } |
| 376 | //! ``` |
| 377 | #![cfg_attr(feature = "document-features", doc = "\n## Features")] |
| 378 | #![cfg_attr(feature = "document-features", doc = document_features::document_features!())] |
| 379 | //! |
| 380 | //! [Ratatui Website]: https://ratatui.rs/ |
| 381 | //! [Installation]: https://ratatui.rs/installation/ |
| 382 | //! [Tutorials]: https://ratatui.rs/tutorials/ |
| 383 | //! [Hello Ratatui tutorial]: https://ratatui.rs/tutorials/hello-ratatui/ |
| 384 | //! [Counter App]: https://ratatui.rs/tutorials/counter-app/ |
| 385 | //! [Recipes]: https://ratatui.rs/recipes/ |
| 386 | //! [FAQ]: https://ratatui.rs/faq/ |
| 387 | //! [Templates]: https://ratatui.rs/templates/ |
| 388 | //! [Cargo Generate]: https://cargo-generate.github.io/cargo-generate/ |
| 389 | //! [Showcase]: https://ratatui.rs/showcase/ |
| 390 | //! [Rendering]: https://ratatui.rs/concepts/rendering/ |
| 391 | //! [Application Patterns]: https://ratatui.rs/concepts/application-patterns/ |
| 392 | //! [Hello World tutorial]: https://ratatui.rs/tutorials/hello-world/ |
| 393 | //! [Backends]: https://ratatui.rs/concepts/backends/ |
| 394 | //! [Backend Comparison]: https://ratatui.rs/concepts/backends/comparison/ |
| 395 | //! [Widgets]: https://ratatui.rs/recipes/widgets/ |
| 396 | //! [Widget Recipes]: https://ratatui.rs/recipes/widgets/ |
| 397 | //! [Handling Events]: https://ratatui.rs/concepts/event-handling/ |
| 398 | //! [Layout]: https://ratatui.rs/recipes/layout/ |
| 399 | //! [Layout Recipes]: https://ratatui.rs/recipes/layout/ |
| 400 | //! [Styling Text]: https://ratatui.rs/recipes/render/style-text/ |
| 401 | //! [Styling Recipes]: https://ratatui.rs/recipes/render/ |
| 402 | //! [templates]: https://github.com/ratatui/templates/ |
| 403 | //! [Examples]: https://github.com/ratatui/ratatui/tree/main/ratatui/examples/README.md |
| 404 | //! [Report a bug]: https://github.com/ratatui/ratatui/issues/new?labels=bug&projects=&template=bug_report.md |
| 405 | //! [Request a Feature]: https://github.com/ratatui/ratatui/issues/new?labels=enhancement&projects=&template=feature_request.md |
| 406 | //! [Create a Pull Request]: https://github.com/ratatui/ratatui/compare |
| 407 | //! [git-cliff]: https://git-cliff.org |
| 408 | //! [Conventional Commits]: https://www.conventionalcommits.org |
| 409 | //! [API Docs]: https://docs.rs/ratatui |
| 410 | //! [Changelog]: https://github.com/ratatui/ratatui/blob/main/CHANGELOG.md |
| 411 | //! [Contributing]: https://github.com/ratatui/ratatui/blob/main/CONTRIBUTING.md |
| 412 | //! [Breaking Changes]: https://github.com/ratatui/ratatui/blob/main/BREAKING-CHANGES.md |
| 413 | //! [FOSDEM 2024 talk]: https://www.youtube.com/watch?v=NU0q6NOLJ20 |
| 414 | //! [`render_widget`]: Frame::render_widget |
| 415 | //! [`Widget`]: widgets::Widget |
| 416 | //! [`Layout`]: layout::Layout |
| 417 | //! [`Text`]: text::Text |
| 418 | //! [`Line`]: text::Line |
| 419 | //! [`Span`]: text::Span |
| 420 | //! [`Style`]: style::Style |
| 421 | //! [`style` module]: style |
| 422 | //! [`Stylize`]: style::Stylize |
| 423 | //! [`Backend`]: backend::Backend |
| 424 | //! [`Terminal`]: Terminal |
| 425 | //! [`backend` module]: backend |
| 426 | //! [`init` module]: mod@init |
| 427 | //! [`crossterm::event`]: https://docs.rs/crossterm/latest/crossterm/event/index.html |
| 428 | //! [Crate]: https://crates.io/crates/ratatui |
| 429 | //! [Crossterm]: https://crates.io/crates/crossterm |
| 430 | //! [Termion]: https://crates.io/crates/termion |
| 431 | //! [Termwiz]: https://crates.io/crates/termwiz |
| 432 | //! [tui-rs]: https://crates.io/crates/tui |
| 433 | //! [`ratatui-core`]: https://crates.io/crates/ratatui-core |
| 434 | //! [`ratatui-widgets`]: https://crates.io/crates/ratatui-widgets |
| 435 | //! [`ratatui-crossterm`]: https://crates.io/crates/ratatui-crossterm |
| 436 | //! [`ratatui-termion`]: https://crates.io/crates/ratatui-termion |
| 437 | //! [`ratatui-termwiz`]: https://crates.io/crates/ratatui-termwiz |
| 438 | //! [`ratatui-macros`]: https://crates.io/crates/ratatui-macros |
| 439 | //! [ARCHITECTURE.md]: https://github.com/ratatui/ratatui/blob/main/ARCHITECTURE.md |
| 440 | //! [GitHub Sponsors]: https://github.com/sponsors/ratatui |
| 441 | //! [Crate Badge]: https://img.shields.io/crates/v/ratatui?logo=rust&style=flat-square&logoColor=E05D44&color=E05D44 |
| 442 | //! [License Badge]: https://img.shields.io/crates/l/ratatui?style=flat-square&color=1370D3 |
| 443 | //! [CI Badge]: https://img.shields.io/github/actions/workflow/status/ratatui/ratatui/ci.yml?style=flat-square&logo=github |
| 444 | //! [CI Workflow]: https://github.com/ratatui/ratatui/actions/workflows/ci.yml |
| 445 | //! [Codecov Badge]: https://img.shields.io/codecov/c/github/ratatui/ratatui?logo=codecov&style=flat-square&token=BAQ8SOKEST&color=C43AC3&logoColor=C43AC3 |
| 446 | //! [Codecov]: https://app.codecov.io/gh/ratatui/ratatui |
| 447 | //! [Deps.rs Badge]: https://deps.rs/repo/github/ratatui/ratatui/status.svg?style=flat-square |
| 448 | //! [Deps.rs]: https://deps.rs/repo/github/ratatui/ratatui |
| 449 | //! [Discord Badge]: https://img.shields.io/discord/1070692720437383208?label=discord&logo=discord&style=flat-square&color=1370D3&logoColor=1370D3 |
| 450 | //! [Discord Server]: https://discord.gg/pMCEU9hNEj |
| 451 | //! [Docs Badge]: https://img.shields.io/docsrs/ratatui?logo=rust&style=flat-square&logoColor=E05D44 |
| 452 | //! [Matrix Badge]: https://img.shields.io/matrix/ratatui-general%3Amatrix.org?style=flat-square&logo=matrix&label=Matrix&color=C43AC3 |
| 453 | //! [Matrix]: https://matrix.to/#/#ratatui:matrix.org |
| 454 | //! [Forum Badge]: https://img.shields.io/discourse/likes?server=https%3A%2F%2Fforum.ratatui.rs&style=flat-square&logo=discourse&label=forum&color=C43AC3 |
| 455 | //! [Forum]: https://forum.ratatui.rs |
| 456 | //! [Sponsors Badge]: https://img.shields.io/github/sponsors/ratatui?logo=github&style=flat-square&color=1370D3 |
| 457 | //! [`ratatui-core`]: https://crates.io/crates/ratatui-core |
| 458 | //! [`ratatui-widgets`]: https://crates.io/crates/ratatui-widgets |
| 459 | //! [`ratatui-crossterm`]: https://crates.io/crates/ratatui-crossterm |
| 460 | //! [`ratatui-termion`]: https://crates.io/crates/ratatui-termion |
| 461 | //! [`ratatui-termwiz`]: https://crates.io/crates/ratatui-termwiz |
| 462 | //! [`ratatui-macros`]: https://crates.io/crates/ratatui-macros |
| 463 | //! [ARCHITECTURE.md]: https://github.com/ratatui/ratatui/blob/main/ARCHITECTURE.md |
| 464 | |
| 465 | #![warn(clippy::std_instead_of_core)] |
| 466 | #![warn(clippy::std_instead_of_alloc)] |
| 467 | #![warn(clippy::alloc_instead_of_core)] |
| 468 | |
| 469 | extern crate alloc; |
| 470 | #[cfg(feature = "std")] |
| 471 | extern crate std; |
| 472 | |
| 473 | /// re-export the `palette` crate so that users don't have to add it as a dependency |
| 474 | #[cfg(feature = "palette")] |
| 475 | pub use palette; |
| 476 | pub use ratatui_core::terminal::{CompletedFrame, Frame, Terminal, TerminalOptions, Viewport}; |
| 477 | pub use ratatui_core::{buffer, layout}; |
| 478 | /// re-export the `crossterm` crate so that users don't have to add it as a dependency |
| 479 | #[cfg(feature = "crossterm")] |
| 480 | pub use ratatui_crossterm::crossterm; |
| 481 | #[cfg(feature = "macros")] |
| 482 | pub use ratatui_macros as macros; |
| 483 | /// re-export the `termion` crate so that users don't have to add it as a dependency |
| 484 | #[cfg(all(not(windows), feature = "termion"))] |
| 485 | pub use ratatui_termion::termion; |
| 486 | /// re-export the `termwiz` crate so that users don't have to add it as a dependency |
| 487 | #[cfg(feature = "termwiz")] |
| 488 | pub use ratatui_termwiz::termwiz; |
| 489 | |
| 490 | #[cfg(feature = "crossterm")] |
| 491 | #[doc(inline)] |
| 492 | pub use crate::init::{ |
| 493 | DefaultTerminal, init, init_with_options, restore, run, try_init, try_init_with_options, |
| 494 | try_restore, |
| 495 | }; |
| 496 | |
| 497 | /// Re-exports for the backend implementations. |
| 498 | pub mod backend { |
| 499 | pub use ratatui_core::backend::{Backend, ClearType, TestBackend, WindowSize}; |
| 500 | #[cfg(feature = "crossterm")] |
| 501 | pub use ratatui_crossterm::{CrosstermBackend, FromCrossterm, IntoCrossterm}; |
| 502 | #[cfg(all(not(windows), feature = "termion"))] |
| 503 | pub use ratatui_termion::{FromTermion, IntoTermion, TermionBackend}; |
| 504 | #[cfg(feature = "termwiz")] |
| 505 | pub use ratatui_termwiz::{FromTermwiz, IntoTermwiz, TermwizBackend}; |
| 506 | } |
| 507 | |
| 508 | pub mod prelude; |
| 509 | pub use ratatui_core::{style, symbols, text}; |
| 510 | pub mod widgets; |
| 511 | pub use ratatui_widgets::border; |
| 512 | #[cfg(feature = "crossterm")] |
| 513 | pub mod init; |