Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change from "tui" to "ratatui" #62

Merged
merged 1 commit into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
230 changes: 207 additions & 23 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ path = "src/main.rs"

[dependencies]
serialport = "4.3.0"
tui = "0.19.0"
ratatui = "0.26.1"
crossterm = "0.25.0"
chrono = "0.4.23"
serde = "1.0"
Expand Down
17 changes: 8 additions & 9 deletions src/command_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ use crate::messages::{SerialRxData, UserTxData};
use crate::plugin_manager::PluginManager;
use crate::serial::SerialIF;
use crate::text::TextView;
use crate::ConcreteBackend;
use chrono::Local;
use crossterm::event::{Event, KeyCode, KeyEvent, KeyModifiers, MouseEventKind};
use rand::seq::SliceRandom;
use ratatui::layout::{Constraint, Direction, Layout, Rect};
use ratatui::style::{Color, Style};
use ratatui::text::{Line, Span};
use ratatui::widgets::{Block, BorderType, Borders, Clear, Paragraph};
use ratatui::Frame;
use std::cmp::{max, min};
use std::collections::btree_map::BTreeMap;
use std::collections::HashMap;
Expand All @@ -17,11 +21,6 @@ use std::sync::{Arc, Mutex};
use std::thread;
use std::thread::sleep;
use std::time::Duration;
use tui::layout::{Constraint, Direction, Layout, Rect};
use tui::style::{Color, Style};
use tui::text::{Span, Spans};
use tui::widgets::{Block, BorderType, Borders, Clear, Paragraph};
use tui::Frame;

pub struct CommandBar {
interface: Arc<Mutex<SerialIF>>,
Expand Down Expand Up @@ -103,7 +102,7 @@ impl CommandBar {
}
}

pub fn draw(&self, f: &mut Frame<ConcreteBackend>) {
pub fn draw(&self, f: &mut Frame) {
let chunks = Layout::default()
.direction(Direction::Vertical)
.constraints(
Expand Down Expand Up @@ -567,7 +566,7 @@ impl CommandList {
self.pattern = pattern;
}

pub fn draw(&self, f: &mut Frame<ConcreteBackend>, command_bar_y: u16, color: Color) {
pub fn draw(&self, f: &mut Frame, command_bar_y: u16, color: Color) {
if self.commands.is_empty() {
return;
}
Expand Down Expand Up @@ -598,7 +597,7 @@ impl CommandList {
let is_last =
(x == commands.last().unwrap()) && (commands.len() < self.commands.len());

Spans::from(vec![
Line::from(vec![
Span::styled(
format!(" {}", if !is_last { &self.pattern } else { "" }),
Style::default().fg(color),
Expand Down
13 changes: 6 additions & 7 deletions src/error_pop_up.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use crate::ConcreteBackend;
use ratatui::layout::{Alignment, Rect};
use ratatui::style::{Color, Style};
use ratatui::text::Span;
use ratatui::widgets::{Block, Borders, Clear, Paragraph};
use ratatui::Frame;
use std::time::{Duration, Instant};
use tui::layout::{Alignment, Rect};
use tui::style::{Color, Style};
use tui::text::Span;
use tui::widgets::{Block, Borders, Clear, Paragraph};
use tui::Frame;

pub struct ErrorPopUp {
message: String,
Expand All @@ -21,7 +20,7 @@ impl ErrorPopUp {
}
}

pub fn draw(&self, f: &mut Frame<ConcreteBackend>, command_bar_y: u16) {
pub fn draw(&self, f: &mut Frame, command_bar_y: u16) {
let area_size = (self.message.chars().count() as u16 + 4, 3);
let area = Rect::new(
(f.size().width - area_size.0) / 2,
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ use crossterm::execute;
use crossterm::terminal::{
disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen,
};
use ratatui::backend::{Backend, CrosstermBackend};
use ratatui::Terminal;
use std::io;
use std::io::Stdout;
use std::path::PathBuf;
use tui::backend::{Backend, CrosstermBackend};
use tui::Terminal;

mod command_bar;
mod error_pop_up;
Expand Down
2 changes: 1 addition & 1 deletion src/messages.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::rich_string::RichText;
use crate::text::ViewData;
use chrono::{DateTime, Local};
use tui::style::Color;
use ratatui::style::Color;

pub enum UserTxData {
Exit,
Expand Down
4 changes: 2 additions & 2 deletions src/rich_string.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::text::ViewData;
use chrono::{DateTime, Local};
use ratatui::style::{Color, Style};
use ratatui::text::Span;
use std::collections::HashMap;
use tui::style::{Color, Style};
use tui::text::Span;

pub struct RichText {
content: Vec<u8>,
Expand Down
15 changes: 7 additions & 8 deletions src/text.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use crate::messages::SerialRxData;
use crate::rich_string::RichText;
use crate::ConcreteBackend;
use chrono::{DateTime, Local};
use tui::layout::Rect;
use tui::style::{Color, Modifier, Style};
use tui::text::{Span, Spans};
use tui::widgets::{Block, BorderType, Borders, Paragraph};
use tui::Frame;
use ratatui::layout::Rect;
use ratatui::style::{Color, Modifier, Style};
use ratatui::text::{Line, Span};
use ratatui::widgets::{Block, BorderType, Borders, Paragraph};
use ratatui::Frame;

pub struct TextView {
history: Vec<ViewData>,
Expand Down Expand Up @@ -38,7 +37,7 @@ impl TextView {
}
}

pub fn draw(&self, f: &mut Frame<ConcreteBackend>, rect: Rect) {
pub fn draw(&self, f: &mut Frame, rect: Rect) {
let scroll = if self.auto_scroll {
(self.max_main_axis(), self.scroll.1)
} else {
Expand Down Expand Up @@ -87,7 +86,7 @@ impl TextView {
}))
.collect::<Vec<_>>();

Spans::from(content)
Line::from(content)
})
.collect::<Vec<_>>();
let paragraph = Paragraph::new(text).block(block);
Expand Down
Loading