Skip to content

Commit

Permalink
refactor: use ratatui instead of tui
Browse files Browse the repository at this point in the history
  • Loading branch information
vicanso committed Nov 29, 2023
1 parent 04862b8 commit ef5f279
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 99 deletions.
110 changes: 74 additions & 36 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "diving"
version = "0.5.10"
version = "0.6.0"
authors = ["Tree Xie <[email protected]>"]
edition = "2021"
keywords = ["diving", "image", "dive"]
Expand Down Expand Up @@ -29,6 +29,7 @@ mime_guess = "2.0.4"
nanoid = "0.4.0"
once_cell = "1.18.0"
pad = "0.1.6"
ratatui = "0.24.0"
regex = "1.10.2"
reqwest = { version = "0.11.22", default-features = false, features = ["rustls-tls", "json"] }
rust-embed = { version = "8.0.0", features = ["compression", "mime-guess"] }
Expand All @@ -47,7 +48,6 @@ tokio-cron-scheduler = "0.9.4"
tower = { version = "0.4.13", features = ["timeout"] }
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = [ "local-time"] }
tui = "0.19.0"
unicode-width = "0.1.11"
unix_mode = "0.1.4"
zstd = "0.13.0"
Expand Down
13 changes: 4 additions & 9 deletions src/ui/files.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
use bytesize::ByteSize;
use pad::PadStr;
use tui::{
layout::{Constraint, Direction, Layout, Rect},
style::{Color, Modifier, Style},
text::{Span, Spans},
widgets::{Block, List, ListItem, Paragraph},
};
use ratatui::{prelude::*, widgets::*};

use crate::image::{FileTreeItem, Op};

Expand Down Expand Up @@ -112,7 +107,7 @@ fn add_to_file_tree_view(
if !item.link.is_empty() {
name = format!("{name} → {}", item.link);
}
list.push(ListItem::new(Spans::from(vec![
list.push(ListItem::new(Line::from(vec![
Span::styled(get_file_mode_str(&item.mode), style),
space_span.clone(),
Span::styled(get_id_str(&id), style),
Expand Down Expand Up @@ -163,11 +158,11 @@ pub fn new_files_widget(
opt.mode
);
let content = Paragraph::new(vec![
Spans::from(vec![Span::styled(
Line::from(vec![Span::styled(
mode_tips,
Style::default().add_modifier(Modifier::BOLD),
)]),
Spans::from(vec![
Line::from(vec![
Span::from(name_list[0]),
space_span.clone(),
Span::from(name_list[1]),
Expand Down
20 changes: 8 additions & 12 deletions src/ui/image_detail.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
use bytesize::ByteSize;
use pad::PadStr;
use tui::{
style::{Modifier, Style},
text::{Span, Spans},
widgets::Paragraph,
};
use ratatui::{prelude::*, widgets::*};

use super::util;
use crate::image::ImageFileSummary;
Expand Down Expand Up @@ -70,36 +66,36 @@ pub fn new_image_detail_widget<'a>(opt: ImageDetailWidgetOption) -> ImageDetailW
name += &format!("({}/{})", opt.os, opt.arch);
}
let mut spans_list = vec![
Spans::from(vec![
Line::from(vec![
Span::styled(
"Image name: ",
Style::default().add_modifier(Modifier::BOLD),
),
Span::from(name),
]),
Spans::from(vec![
Line::from(vec![
Span::styled(
"Total Image size: ",
Style::default().add_modifier(Modifier::BOLD),
),
Span::from(format!("{} / {}", ByteSize(total_size), ByteSize(size),)),
]),
Spans::from(vec![
Line::from(vec![
Span::styled(
"Potential wasted space: ",
Style::default().add_modifier(Modifier::BOLD),
),
Span::from(ByteSize(wasted_size).to_string()),
]),
Spans::from(vec![
Line::from(vec![
Span::styled(
"Image efficiency score: ",
Style::default().add_modifier(Modifier::BOLD),
),
Span::from(format!("{score} %")),
]),
Spans::from(vec![]),
Spans::from(vec![
Line::from(vec![]),
Line::from(vec![
Span::styled(headers[0], Style::default().add_modifier(Modifier::BOLD)),
space_span.clone(),
Span::styled(headers[1], Style::default().add_modifier(Modifier::BOLD)),
Expand All @@ -117,7 +113,7 @@ pub fn new_image_detail_widget<'a>(opt: ImageDetailWidgetOption) -> ImageDetailW
let size_str = ByteSize(wasted.total_size)
.to_string()
.pad_to_width_with_alignment(size_pad_width, pad::Alignment::Right);
spans_list.push(Spans::from(vec![
spans_list.push(Line::from(vec![
Span::from(count_str),
space_span.clone(),
Span::from(size_str),
Expand Down
26 changes: 7 additions & 19 deletions src/ui/layer_detail.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
use chrono::{DateTime, Local, TimeZone};

use tui::{
layout::Alignment,
style::{Modifier, Style},
text::{Span, Spans},
widgets::{Paragraph, Wrap},
};
use ratatui::{prelude::*, widgets::*};

use super::util;
use crate::image::ImageLayer;
Expand All @@ -32,18 +26,12 @@ pub fn new_layer_detail_widget(layer: &ImageLayer, opt: DetailWidgetOption) -> D
.to_rfc3339();
};

let paragraph = Paragraph::new(vec![
Spans::from(Span::styled(
"Created:",
Style::default().add_modifier(Modifier::BOLD),
)),
Spans::from(create_at),
Spans::from(Span::styled(
"Command:",
Style::default().add_modifier(Modifier::BOLD),
)),
Spans::from(cmd),
])
let paragraph = Paragraph::new(Line::from(vec![
Span::styled("Created:", Style::default().add_modifier(Modifier::BOLD)),
Span::from(create_at),
Span::styled("Command:", Style::default().add_modifier(Modifier::BOLD)),
Span::from(cmd),
]))
.block(util::create_block(" Layer Details "))
.alignment(Alignment::Left)
.wrap(Wrap { trim: true });
Expand Down
10 changes: 2 additions & 8 deletions src/ui/layers.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
use bytesize::ByteSize;

use pad::PadStr;

use tui::{
layout::Constraint,
style::{Color, Modifier, Style},
text::Spans,
widgets::{Cell, Row, Table},
};
use ratatui::{prelude::*, widgets::*};

use super::util;
use crate::image::ImageLayer;
Expand Down Expand Up @@ -50,7 +44,7 @@ pub fn new_layers_widget<'a>(layers: &[ImageLayer], opt: LayersWidgetOption) ->
pad::Alignment::Right,
)));
} else {
cells.push(Cell::from(Spans::from(value)));
cells.push(Cell::from(value));
}
}
let mut style = Style::default();
Expand Down
Loading

0 comments on commit ef5f279

Please sign in to comment.