Skip to content

Commit db166be

Browse files
committed
Update to use ratatui as tui is abandoned
1 parent 77f942a commit db166be

File tree

5 files changed

+36
-54
lines changed

5 files changed

+36
-54
lines changed

Cargo.lock

Lines changed: 15 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@ crossterm = "^0.26"
1616
rust-embed = "^6.4"
1717
toml = "^0.7"
1818

19-
[dependencies.tui]
20-
version = "^0.19"
21-
default-features = false
22-
features = ["crossterm"]
19+
[dependencies.ratatui]
20+
version = "^0.21"
2321

2422
[dependencies.rand]
2523
version = "^0.8"

src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use serde::{
22
de::{self, IntoDeserializer},
33
Deserialize,
44
};
5-
use tui::style::{Color, Modifier, Style};
5+
use ratatui::style::{Color, Modifier, Style};
66

77
#[derive(Debug, Deserialize)]
88
#[serde(default)]

src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use std::{
2121
str,
2222
};
2323
use structopt::StructOpt;
24-
use tui::{backend::CrosstermBackend, terminal::Terminal};
24+
use ratatui::{backend::CrosstermBackend, terminal::Terminal};
2525

2626
#[derive(RustEmbed)]
2727
#[folder = "resources/runtime"]
@@ -156,7 +156,7 @@ enum State {
156156
}
157157

158158
impl State {
159-
fn render_into<B: tui::backend::Backend>(
159+
fn render_into<B: ratatui::backend::Backend>(
160160
&self,
161161
terminal: &mut Terminal<B>,
162162
config: &Config,

src/ui.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ use crossterm::event::KeyCode;
66
use crossterm::event::KeyEvent;
77
use results::Fraction;
88
use std::iter;
9-
use tui::{
9+
use ratatui::{
1010
buffer::Buffer,
1111
layout::{Constraint, Direction, Layout, Rect},
1212
symbols::Marker,
13-
text::{Span, Spans, Text},
13+
text::{Span, Line, Text},
1414
widgets::{Axis, Block, BorderType, Borders, Chart, Dataset, GraphType, Paragraph, Widget},
1515
};
1616

@@ -39,10 +39,10 @@ trait DrawInner<T> {
3939
fn draw_inner(&self, content: T, buf: &mut Buffer);
4040
}
4141

42-
impl DrawInner<&Spans<'_>> for SizedBlock<'_> {
43-
fn draw_inner(&self, content: &Spans, buf: &mut Buffer) {
42+
impl DrawInner<&Line<'_>> for SizedBlock<'_> {
43+
fn draw_inner(&self, content: &Line, buf: &mut Buffer) {
4444
let inner = self.block.inner(self.area);
45-
buf.set_spans(inner.x, inner.y, content, inner.width);
45+
buf.set_line(inner.x, inner.y, content, inner.width);
4646
}
4747
}
4848

@@ -88,19 +88,19 @@ impl ThemedWidget for &Test {
8888
// Sections
8989
let input = SizedBlock {
9090
block: Block::default()
91-
.title(Spans::from(vec![Span::styled("Input", theme.title)]))
91+
.title(Line::from(vec![Span::styled("Input", theme.title)]))
9292
.borders(Borders::ALL)
9393
.border_type(BorderType::Rounded)
9494
.border_style(theme.input_border),
9595
area: chunks[0],
9696
};
9797
input.draw_inner(
98-
&Spans::from(self.words[self.current_word].progress.clone()),
98+
&Line::from(self.words[self.current_word].progress.clone()),
9999
buf,
100100
);
101101
input.render(buf);
102102

103-
let target_lines: Vec<Spans> = {
103+
let target_lines: Vec<Line> = {
104104
let words = iter::empty::<Vec<Span>>()
105105
// already typed words
106106
.chain(self.words[..self.current_word].iter().map(|w| {
@@ -158,23 +158,23 @@ impl ThemedWidget for &Test {
158158
.map(|w| vec![Span::styled(w.text.clone() + " ", theme.prompt_untyped)]),
159159
);
160160

161-
let mut lines: Vec<Spans> = Vec::new();
161+
let mut lines: Vec<Line> = Vec::new();
162162
let mut current_line: Vec<Span> = Vec::new();
163163
let mut current_width = 0;
164164
for word in words {
165165
let word_width: usize = word.iter().map(|s| s.width()).sum();
166166

167167
if current_width + word_width > chunks[1].width as usize - 2 {
168168
current_line.push(Span::raw("\n"));
169-
lines.push(Spans::from(current_line.clone()));
169+
lines.push(Line::from(current_line.clone()));
170170
current_line.clear();
171171
current_width = 0;
172172
}
173173

174174
current_line.extend(word);
175175
current_width += word_width;
176176
}
177-
lines.push(Spans::from(current_line));
177+
lines.push(Line::from(current_line));
178178

179179
lines
180180
};
@@ -217,19 +217,19 @@ impl ThemedWidget for &results::Results {
217217
// Sections
218218
let mut overview_text = Text::styled("", theme.results_overview);
219219
overview_text.extend([
220-
Spans::from(format!(
220+
Line::from(format!(
221221
"Adjusted WPM: {:.1}",
222222
self.timing.overall_cps * WPM_PER_CPS * f64::from(self.accuracy.overall)
223223
)),
224-
Spans::from(format!(
224+
Line::from(format!(
225225
"Accuracy: {:.1}%",
226226
f64::from(self.accuracy.overall) * 100f64
227227
)),
228-
Spans::from(format!(
228+
Line::from(format!(
229229
"Raw WPM: {:.1}",
230230
self.timing.overall_cps * WPM_PER_CPS
231231
)),
232-
Spans::from(format!("Correct Keypresses: {}", self.accuracy.overall)),
232+
Line::from(format!("Correct Keypresses: {}", self.accuracy.overall)),
233233
]);
234234
let overview = Paragraph::new(overview_text).block(
235235
Block::default()
@@ -264,7 +264,7 @@ impl ThemedWidget for &results::Results {
264264
None
265265
}
266266
})
267-
.map(Spans::from),
267+
.map(Line::from),
268268
);
269269
let worst = Paragraph::new(worst_text).block(
270270
Block::default()

0 commit comments

Comments
 (0)