aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh McKinney <[email protected]>2023-12-27 22:58:27 +0000
committerJosh McKinney <[email protected]>2023-12-27 22:58:27 +0000
commit9b6d449dd1697f9241b471bc91feeb00bb40f904 (patch)
tree9314ce59bdcee1efb75be6d75f4e1b6d4742de5f
parentdocs(readme): add video (diff)
downloadsydney-9b6d449dd1697f9241b471bc91feeb00bb40f904.tar.xz
sydney-9b6d449dd1697f9241b471bc91feeb00bb40f904.zip
feat(ratatui): migrate from tui-rs to ratatui
Ratatui is an actively maintained fork of tui-rs. See https://ratatui.rs
-rw-r--r--Cargo.toml4
-rw-r--r--src/app.rs4
-rw-r--r--src/main.rs2
-rw-r--r--src/stateful_list.rs2
-rw-r--r--src/ui.rs61
5 files changed, 29 insertions, 44 deletions
diff --git a/Cargo.toml b/Cargo.toml
index f86faf1..732bb6e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -21,5 +21,5 @@ opt-level = 3
[dependencies]
germ = { version = "0.3.7", default-features = false, features = ["request", "ast"] } # Gemini
url = "2.2.2" # URL
-tui = "0.18.0" # Terminal User Interface
-crossterm = "0.24.0" # Cross-platform Terminal
+ratatui = "0.25.0" # Terminal User Interface
+crossterm = "0.27.0" # Cross-platform Terminal
diff --git a/src/app.rs b/src/app.rs
index 6094f9a..82df7e3 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -182,8 +182,8 @@ impl App {
});
}
- pub fn run<B: tui::backend::Backend>(
- terminal: &mut tui::Terminal<B>,
+ pub fn run<B: ratatui::backend::Backend>(
+ terminal: &mut ratatui::Terminal<B>,
mut app: Self,
tick_rate: Duration,
) -> std::io::Result<()> {
diff --git a/src/main.rs b/src/main.rs
index 625f402..64eb7e4 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -117,7 +117,7 @@ Report bugs to https://github.com/gemrest/sydney/issues"#,
)?;
let mut terminal =
- tui::Terminal::new(tui::backend::CrosstermBackend::new(stdout))?;
+ ratatui::Terminal::new(ratatui::backend::CrosstermBackend::new(stdout))?;
let result =
App::run(&mut terminal, app, std::time::Duration::from_millis(250));
diff --git a/src/stateful_list.rs b/src/stateful_list.rs
index f7ec279..65c8a79 100644
--- a/src/stateful_list.rs
+++ b/src/stateful_list.rs
@@ -17,7 +17,7 @@
//! <https://github.com/fdehau/tui-rs/blob/master/examples/list.rs>
-use tui::widgets::ListState;
+use ratatui::widgets::ListState;
pub struct StatefulList<T> {
pub state: ListState,
diff --git a/src/ui.rs b/src/ui.rs
index 5267eb6..b34d844 100644
--- a/src/ui.rs
+++ b/src/ui.rs
@@ -16,19 +16,16 @@
// SPDX-License-Identifier: GPL-3.0-only
use germ::ast::Node;
-use tui::{
+use ratatui::{
layout::{Constraint, Direction, Layout, Rect},
style::{Color, Modifier, Style},
- text::{Span, Spans},
+ text::{Line, Span},
widgets,
widgets::{ListItem, Paragraph},
};
#[allow(clippy::too_many_lines)]
-pub fn ui<B: tui::backend::Backend>(
- f: &mut tui::Frame<'_, B>,
- app: &mut crate::App,
-) {
+pub fn ui(f: &mut ratatui::Frame<'_>, app: &mut crate::App) {
let chunks = Layout::default()
.direction(Direction::Vertical)
.constraints(
@@ -46,7 +43,7 @@ pub fn ui<B: tui::backend::Backend>(
.items
.iter()
.map(|(text_lines, _link, pre)| {
- let mut spans = vec![];
+ let mut lines = vec![];
for line in text_lines {
let mut line = line.clone();
@@ -55,13 +52,13 @@ pub fn ui<B: tui::backend::Backend>(
if let Node::Text(text) = line {
line = Node::PreformattedText {
alt_text: None,
- text: text.to_string(),
+ text: text.to_string(),
}
}
}
macro_rules! wrap_split {
- ($text:ident, $spans:ident) => {
+ ($text:ident, $lines:ident) => {
let wrappeds = $text
.as_bytes()
.chunks((app.wrap_at as usize) - 5)
@@ -72,7 +69,7 @@ pub fn ui<B: tui::backend::Backend>(
.collect::<Vec<_>>();
for (i, wrapped) in wrappeds.iter().enumerate() {
- $spans.push(Spans::from(format!(" {}{}", wrapped, {
+ $lines.push(Line::from(format!(" {}{}", wrapped, {
if i < wrappeds.len() - 1 && wrappeds.len() != 1 {
"-"
} else {
@@ -84,10 +81,11 @@ pub fn ui<B: tui::backend::Backend>(
}
match line {
- germ::ast::Node::Text(text) =>
+ germ::ast::Node::Text(text) => {
if text != "sydney_abc_123" {
- wrap_split!(text, spans);
- },
+ wrap_split!(text, lines);
+ }
+ }
germ::ast::Node::Blockquote(text) => {
let wrappeds = text
.as_bytes()
@@ -99,7 +97,7 @@ pub fn ui<B: tui::backend::Backend>(
.collect::<Vec<_>>();
for (i, wrapped) in wrappeds.iter().enumerate() {
- spans.push(Spans::from(vec![
+ lines.push(Line::from(vec![
Span::styled(" > ", Style::default().fg(Color::LightBlue)),
Span::styled(
format!("{}{}", wrapped.clone(), {
@@ -114,10 +112,7 @@ pub fn ui<B: tui::backend::Backend>(
]));
}
}
- germ::ast::Node::Link {
- to,
- text,
- } => {
+ germ::ast::Node::Link { to, text } => {
let mut span_list =
vec![Span::styled(" => ", Style::default().fg(Color::LightBlue))];
@@ -129,13 +124,10 @@ pub fn ui<B: tui::backend::Backend>(
span_list
.push(Span::styled(to, Style::default().fg(Color::LightBlue)));
- spans.push(Spans::from(span_list));
+ lines.push(Line::from(span_list));
}
- germ::ast::Node::Heading {
- text,
- level,
- } => {
- spans.push(Spans::from(vec![
+ germ::ast::Node::Heading { text, level } => {
+ lines.push(Line::from(vec![
Span::styled(
match level {
1 => " # ",
@@ -173,12 +165,9 @@ pub fn ui<B: tui::backend::Backend>(
span_list.push(Span::from(format!("{}\n", list_item)));
}
- spans.push(Spans::from(span_list));
+ lines.push(Line::from(span_list));
}
- germ::ast::Node::PreformattedText {
- text,
- alt_text,
- } => {
+ germ::ast::Node::PreformattedText { text, alt_text } => {
let mut span_list = vec![
Span::styled("``` ", Style::default().fg(Color::LightBlue)),
Span::from(alt_text.unwrap_or_else(|| "".to_string())),
@@ -188,15 +177,15 @@ pub fn ui<B: tui::backend::Backend>(
span_list.push(Span::from(text));
}
- spans.push(Spans::from(span_list));
+ lines.push(Line::from(span_list));
}
germ::ast::Node::Whitespace => {
- spans.push(Spans::from("".to_string()));
+ lines.push(Line::from("".to_string()));
}
};
}
- ListItem::new(spans)
+ ListItem::new(lines)
})
.collect();
@@ -241,9 +230,7 @@ pub fn ui<B: tui::backend::Backend>(
app.response_input_text.trim(),
app.response_input
))
- .wrap(widgets::Wrap {
- trim: false
- }),
+ .wrap(widgets::Wrap { trim: false }),
block.inner(area),
);
}
@@ -258,9 +245,7 @@ pub fn ui<B: tui::backend::Backend>(
f.render_widget(widgets::Clear, area);
f.render_widget(block.clone(), area);
f.render_widget(
- Paragraph::new(error.to_string()).wrap(widgets::Wrap {
- trim: false
- }),
+ Paragraph::new(error.to_string()).wrap(widgets::Wrap { trim: false }),
block.inner(area),
);
}