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
//! # Getting Started
//! Check out the [examples](https://github.com/Jesterhearts/ratatui-wgpu/tree/main/examples)
//! for a number of programs using`winit` for both native and web.
//!
//! A [`WgpuBackend`] can be constructed using a [`Builder`] and then provided
//! to a [`Terminal`](ratatui::Terminal). After that, rendering can be done as
//! normal using the ratatui library. If you need custom shader post-processing,
//! see the [`PostProcessor`] trait or the
//! [`DefaultPostProcessor`](shaders::DefaultPostProcessor) implementation for
//! guidance.
//!
//! Here's a short example using winit on native with the defaut post processor
//! implementation:
//! ```
//! # use std::{
//! # num::NonZeroU32,
//! # sync::Arc,
//! # };
//! #
//! # use chrono::Local;
//! # use ratatui::{
//! # prelude::*,
//! # widgets::*,
//! # };
//! # use ratatui_wgpu::{
//! # Builder,
//! # Font,
//! # WgpuBackend,
//! # };
//! # use winit::{
//! # application::ApplicationHandler,
//! # event::WindowEvent,
//! # event_loop::EventLoop,
//! # window::{
//! # Window,
//! # WindowAttributes,
//! # },
//! # };
//! #
//! pub struct App {
//! window: Option<Arc<Window>>,
//! backend: Option<Terminal<WgpuBackend<'static, 'static>>>,
//! }
//!
//! impl ApplicationHandler for App {
//! fn resumed(&mut self, event_loop: &winit::event_loop::ActiveEventLoop) {
//! self.window = Some(Arc::new(
//! event_loop
//! .create_window(WindowAttributes::default())
//! .unwrap(),
//! ));
//!
//! let size = self.window.as_ref().unwrap().inner_size();
//!
//! self.backend = Some(
//! Terminal::new(
//! futures_lite::future::block_on(
//! Builder::from_font(
//! Font::new(include_bytes!(concat!(
//! "backend/fonts/CascadiaMono-Regular.ttf"
//! )))
//! .unwrap(),
//! )
//! .with_dimensions(
//! NonZeroU32::new(size.width).unwrap(),
//! NonZeroU32::new(size.height).unwrap(),
//! )
//! .build_with_target(self.window.as_ref().unwrap().clone()),
//! )
//! .unwrap(),
//! )
//! .unwrap(),
//! );
//!
//! self.window.as_ref().unwrap().request_redraw();
//! }
//!
//! fn window_event(
//! &mut self,
//! event_loop: &winit::event_loop::ActiveEventLoop,
//! _window_id: winit::window::WindowId,
//! event: winit::event::WindowEvent,
//! ) {
//! if let WindowEvent::CloseRequested = event {
//! event_loop.exit();
//! return;
//! }
//!
//! let Some(terminal) = self.backend.as_mut() else {
//! return;
//! };
//!
//! if let WindowEvent::Resized(size) = event {
//! terminal.backend_mut().resize(size.width, size.height);
//! }
//!
//! terminal
//! .draw(|f| {
//! f.render_widget(
//! Paragraph::new(Line::from("Hello World!")).block(Block::bordered()),
//! f.area(),
//! );
//! })
//! .unwrap();
//!
//! self.window.as_ref().unwrap().request_redraw();
//! }
//! }
//! ```
//!
//! # Limitations
//! 1. No cursor rendering.
//! - The location of the cursor is tracked, and operations using it should
//! behave as expected, but the cursor is not rendered to the screen.
//! 2. Attempting to render more unique (utf8 character *
//! BOLD|ITALIC|UNDERLINED) characters than can fit in the cache in a single
//! draw call will cause incorrect rendering. This is ~3750 characters at the
//! default font size with most fonts. If you need more than this, file a bug
//! and I'll do the work to make rendering handle an unbounded number of
//! unique characters. To put that in perspective, rendering every printable
//! ascii character in every combination of styles would take (95 * 8) 760
//! cache entries or ~20% of the cache.
pub
pub
pub
pub
pub use ratatui;
use Error;
pub use wgpu;
extern crate log;
/// Represents the various errors that can occur during operation.
pub type Result<T> = Result;
type RandomState = RandomState;
type RandomState = RandomState;
pub use ;
pub use ;