Skip to content

Commit

Permalink
migrate tui-rs to ratatui
Browse files Browse the repository at this point in the history
  • Loading branch information
irishmaestro committed Dec 7, 2023
1 parent 33a7e0f commit 09d86bc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ path = "src/main.rs"
arboard = "3.2.0"
crossterm = "0.26.1"
lazy_static = "1.4.0"
tui = "0.19.0"
ratatui = "0.24.0"
# tui-textarea = "0.2.0" # may use this for customizing payloads
4 changes: 2 additions & 2 deletions src/code.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use tui::{
use ratatui::{
style::{Color, Modifier, Style},
text::{Span, Spans, Text},
text::{Line, Span, Text},
widgets::{Block, BorderType, Borders, Paragraph, Wrap},
};

Expand Down
36 changes: 15 additions & 21 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ use crossterm::{
execute,
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
};
use std::{
error::Error,
io,
time::{Duration, Instant},
};
use tui::{
use ratatui::{
backend::{Backend, CrosstermBackend},
layout::{Constraint, Direction, Layout, Rect},
style::{Color, Modifier, Style},
text::{Span, Spans, Text},
text::{Line, Span, Text},
widgets::{Block, BorderType, Borders, List, ListItem, ListState, Paragraph, Tabs, Wrap},
Frame, Terminal,
};
use std::{
error::Error,
io,
time::{Duration, Instant},
};
mod bins;
use bins::{bin_list, get_code, get_tags};
mod code;
Expand Down Expand Up @@ -236,10 +236,7 @@ fn constraint_len(payload: &str) -> Constraint {
Constraint::Length(payload.lines().count() as u16)
}

fn render_bin<B>(f: &mut Frame<B>, app: &App, area: Rect)
where
B: Backend,
{
fn render_bin(f: &mut Frame, app: &App, area: Rect) {
let chunks = Layout::default()
.direction(Direction::Vertical)
.horizontal_margin(4)
Expand All @@ -262,7 +259,7 @@ where
.iter()
.map(|t| {
let (first, rest) = t.split_at(1);
Spans::from(vec![
Line::from(vec![
Span::styled(first, Style::default().fg(Color::Yellow)),
Span::styled(rest, Style::default().fg(Color::Green)),
])
Expand Down Expand Up @@ -428,7 +425,7 @@ fn run_app<B: Backend>(
}
}

fn client<B: Backend>(f: &mut Frame<B>, app: &mut App) {
fn client(f: &mut Frame, app: &mut App) {
let main_layout = Layout::default()
.direction(Direction::Horizontal)
.constraints([Constraint::Percentage(18), Constraint::Percentage(82)].as_ref())
Expand All @@ -438,7 +435,7 @@ fn client<B: Backend>(f: &mut Frame<B>, app: &mut App) {
.bins
.iter()
.map(|i| {
let lines = vec![Spans::from(*i)];
let lines = vec![Line::from(*i)];
ListItem::new(lines).style(
Style::default()
.fg(Color::Green)
Expand Down Expand Up @@ -467,10 +464,7 @@ fn client<B: Backend>(f: &mut Frame<B>, app: &mut App) {
}
}

fn render_root<B>(f: &mut Frame<B>, area: Rect)
where
B: Backend,
{
fn render_root(f: &mut Frame, area: Rect) {
let chunks = Layout::default()
.direction(Direction::Vertical)
.constraints(
Expand All @@ -489,7 +483,7 @@ where
let create_block = |title| {
Block::default()
.borders(Borders::ALL)
.border_type(tui::widgets::BorderType::Rounded)
.border_type(ratatui::widgets::BorderType::Rounded)
.style(Style::default().fg(Color::White))
.title(Span::styled(
title,
Expand Down Expand Up @@ -542,15 +536,15 @@ where
];
let mut desc_vec = vec![];
for x in descriptions {
let d = Spans::from(vec![
let d = Line::from(vec![
Span::styled(x.0, name_style),
Span::styled(format!(" {}", x.1), style),
]);
desc_vec.push(d);
// desc_vec.push(Spans::from(vec![Span::raw("")]));
}
let root = Paragraph::new(desc_vec)
.alignment(tui::layout::Alignment::Left)
.alignment(ratatui::layout::Alignment::Left)
.wrap(Wrap { trim: false })
.block(
Block::default()
Expand Down

0 comments on commit 09d86bc

Please sign in to comment.