Skip to content

Commit

Permalink
chore: bump ratatui to v0.27.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Beastwick18 committed Jun 25, 2024
1 parent fcd17f0 commit 59cf71f
Show file tree
Hide file tree
Showing 17 changed files with 164 additions and 34 deletions.
48 changes: 33 additions & 15 deletions Cargo.lock

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

7 changes: 3 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ lto = true
reqwest = { version = "0.11.27", features = ["cookies", "gzip"], default-features = false }
tokio = { version = "1.38.0", features = ["macros", "rt-multi-thread"], default-features = false }
urlencoding = "2.1.3"
ratatui = { version = "0.26.3", features = ["crossterm"], default-features = false }
ratatui = { version = "0.27.0", features = ["crossterm"], default-features = false }
textwrap = { version = "0.16.1", default-features = false }
crossterm = { version = "0.27.0", default-features = false }
unicode-width = "0.1.13"
Expand All @@ -41,13 +41,12 @@ arboard = { version = "3.4", default-features = false }
dirs = "5.0.1"
shellexpand = "3.1.0"
indexmap = { version = "2.2.6", default-features = false }
color-to-tui = { version = "0.3.0", default-features = false }
human_bytes = { version = "0.4.3", default-features = false }
strum = { version = "0.26.2", default-features = false }
ratatui-image = { version = "1.0.1", optional = true , default-features = false }
image = { version = "0.25.1", optional = true, features = ["png"], default-features = false }
base64 = { version = "0.22.1", features = ["alloc"], default-features = false }
lexopt = "0.3.0"
ratatui-image = { version = "1.0.1", optional = true , default-features = false }
image = { version = "0.25.1", optional = true, features = ["png"], default-features = false }

[lib]
name = "nyaa"
Expand Down
4 changes: 2 additions & 2 deletions src/results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ pub struct ResultRow {
}

impl<'a> Stylize<'a, ResultRow> for ResultRow {
fn bg(self, color: ratatui::prelude::Color) -> Self {
fn bg<S: Into<ratatui::prelude::Color>>(self, color: S) -> Self {
let mut newself = self;
newself.style = newself.style.bg(color);
newself.style = newself.style.bg(color.into());
newself
}

Expand Down
2 changes: 1 addition & 1 deletion src/source/nyaa_html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::{
sync::SearchQuery,
theme::Theme,
util::{
conv::{shorten_number, to_bytes},
conv::{color_to_tui, shorten_number, to_bytes},
html::{as_type, attr, inner},
},
widget::sort::{SelectedSort, SortDir},
Expand Down
2 changes: 1 addition & 1 deletion src/source/sukebei_nyaa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{
sync::SearchQuery,
theme::Theme,
util::{
conv::to_bytes,
conv::{color_to_tui, to_bytes},
html::{attr, inner},
},
widget::sort::{SelectedSort, SortDir},
Expand Down
2 changes: 1 addition & 1 deletion src/source/torrent_galaxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::{
sync::SearchQuery,
theme::Theme,
util::{
conv::{shorten_number, to_bytes},
conv::{color_to_tui, shorten_number, to_bytes},
html::{as_type, attr, inner},
},
widget::sort::{SelectedSort, SortDir},
Expand Down
4 changes: 2 additions & 2 deletions src/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ use std::{
};

use indexmap::IndexMap;
use ratatui::{style::Color, widgets::BorderType};
use ratatui::{prelude::Color, widgets::BorderType};
use serde::{Deserialize, Deserializer, Serialize, Serializer};

use crate::{app::Context, collection, config, source::SourceTheme};
use crate::{app::Context, collection, config, source::SourceTheme, util::conv::color_to_tui};

pub static THEMES_PATH: &str = "themes";

Expand Down
1 change: 1 addition & 0 deletions src/util.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod cmd;
pub mod conv;
pub mod html;
pub mod strings;
pub mod term;
pub mod types;
112 changes: 112 additions & 0 deletions src/util/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,115 @@ pub fn key_to_string(key: KeyCode, modifier: KeyModifiers) -> String {
};
format!("<{}{}>", modifier, key)
}

// From https://github.com/uttarayan21/color-to-tui
pub mod color_to_tui {
use ratatui::style::Color;
use serde::{Deserialize as _, Deserializer, Serializer};

pub fn serialize<S: Serializer>(color: &Color, serializer: S) -> Result<S::Ok, S::Error> {
serializer.serialize_str(&match color {
Color::Reset => "Reset".to_string(),
Color::Red => "Red".to_string(),
Color::Green => "Green".to_string(),
Color::Black => "Black".to_string(),
Color::Yellow => "Yellow".to_string(),
Color::Blue => "Blue".to_string(),
Color::Magenta => "Magenta".to_string(),
Color::Cyan => "Cyan".to_string(),
Color::Gray => "Gray".to_string(),
Color::White => "White".to_string(),

Color::DarkGray => "DarkGray".to_string(),
Color::LightBlue => "LightBlue".to_string(),
Color::LightCyan => "LightCyan".to_string(),
Color::LightGreen => "LightGreen".to_string(),
Color::LightMagenta => "LightMagenta".to_string(),
Color::LightRed => "LightRed".to_string(),
Color::LightYellow => "LightYellow".to_string(),
Color::Indexed(index) => format!("{:03}", index),
Color::Rgb(r, g, b) => format!("#{:02X}{:02X}{:02X}", r, g, b),
})
}

pub fn deserialize<'de, D: Deserializer<'de>>(deserializer: D) -> Result<Color, D::Error> {
use serde::de::{Error, Unexpected};

let color_string = String::deserialize(deserializer)?;
Ok(match color_string.to_lowercase().as_str() {
"reset" => Color::Reset,
"red" => Color::Red,
"green" => Color::Green,
"black" => Color::Black,
"yellow" => Color::Yellow,
"blue" => Color::Blue,
"magenta" => Color::Magenta,
"cyan" => Color::Cyan,
"gray" => Color::Gray,
"white" => Color::White,

"darkgray" => Color::DarkGray,
"lightblue" => Color::LightBlue,
"lightcyan" => Color::LightCyan,
"lightgreen" => Color::LightGreen,
"lightmagenta" => Color::LightMagenta,
"lightred" => Color::LightRed,
"lightyellow" => Color::LightYellow,
_ => match color_string.len() {
3 => {
let index = color_string.parse::<u8>();
if let Ok(index) = index {
Color::Indexed(index)
} else {
return Err(Error::invalid_type(
Unexpected::Bytes(color_string.as_bytes()),
&"u8 index color",
));
}
}
4 | 7 => {
if !color_string.starts_with('#') {
return Err(Error::invalid_value(
Unexpected::Char(color_string.chars().next().unwrap()),
&"# at the start",
));
}

let color_string = color_string.trim_start_matches('#');

let (r, g, b);

match color_string.len() {
6 => {
r = u8::from_str_radix(&color_string[0..2], 16);
g = u8::from_str_radix(&color_string[2..4], 16);
b = u8::from_str_radix(&color_string[4..6], 16);
}
3 => {
r = u8::from_str_radix(&color_string[0..1], 16).map(|r| r * 17);
g = u8::from_str_radix(&color_string[1..2], 16).map(|g| g * 17);
b = u8::from_str_radix(&color_string[2..3], 16).map(|b| b * 17);
}
_ => unreachable!("Can't be reached since already checked"),
}

match (r, g, b) {
(Ok(r), Ok(g), Ok(b)) => Color::Rgb(r, g, b),
(_, _, _) => {
return Err(Error::invalid_value(
Unexpected::Bytes(color_string.as_bytes()),
&"hex color string",
));
}
}
}
_ => {
return Err(serde::de::Error::invalid_length(
color_string.len(),
&"color string with length 4 or 7",
))
}
},
})
}
}
2 changes: 1 addition & 1 deletion src/widget/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl super::Widget for BatchWidget {
StatefulWidget::render(table, area, buf, &mut self.table.state);
if ctx.batch.len() + 2 > area.height as usize {
let sb = super::scrollbar(ctx, ScrollbarOrientation::VerticalRight);
let sb_area = area.inner(&Margin {
let sb_area = area.inner(Margin {
vertical: 1,
horizontal: 0,
});
Expand Down
2 changes: 1 addition & 1 deletion src/widget/category.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ impl Widget for CategoryPopup {
StatefulWidget::render(table, center, f.buffer_mut(), &mut self.table.state);

let sb = super::scrollbar(ctx, ScrollbarOrientation::VerticalRight);
let sb_area = center.inner(&Margin {
let sb_area = center.inner(Margin {
vertical: 1,
horizontal: 0,
});
Expand Down
2 changes: 1 addition & 1 deletion src/widget/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl Widget for HelpPopup {
if self.table.items.len() as u16 + 2 >= center.height {
let sb =
super::scrollbar(ctx, ScrollbarOrientation::VerticalRight).begin_symbol(Some(""));
let sb_area = center.inner(&Margin {
let sb_area = center.inner(Margin {
vertical: 1,
horizontal: 0,
});
Expand Down
2 changes: 1 addition & 1 deletion src/widget/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl Widget for PagePopup {
super::clear(center, buf, ctx.theme.bg);
indicator.render(center, buf);

let input_area = center.inner(&Margin {
let input_area = center.inner(Margin {
vertical: 1,
horizontal: 1,
});
Expand Down
2 changes: 1 addition & 1 deletion src/widget/results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ impl super::Widget for ResultsWidget {
};

let sb = super::scrollbar(ctx, ScrollbarOrientation::VerticalRight).begin_symbol(Some(""));
let sb_area = area.inner(&Margin {
let sb_area = area.inner(Margin {
vertical: 1,
horizontal: 0,
});
Expand Down
2 changes: 1 addition & 1 deletion src/widget/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl super::Widget for SearchWidget {
let block = border_block(&ctx.theme, ctx.mode == Mode::Search).title(title!("Search"));
Clear.render(area, buf);
block.render(area, buf);
let input_area = area.inner(&Margin {
let input_area = area.inner(Margin {
vertical: 1,
horizontal: 1,
});
Expand Down
2 changes: 1 addition & 1 deletion src/widget/themes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl Widget for ThemePopup {
// Only show scrollbar if content overflows
if ctx.themes.len() as u16 + 1 >= center.height {
let sb = super::scrollbar(ctx, ScrollbarOrientation::VerticalRight);
let sb_area = center.inner(&Margin {
let sb_area = center.inner(Margin {
vertical: 1,
horizontal: 0,
});
Expand Down
2 changes: 1 addition & 1 deletion src/widget/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl Widget for UserPopup {
super::clear(center, buf, ctx.theme.bg);
indicator.render(center, buf);

let input_area = center.inner(&Margin {
let input_area = center.inner(Margin {
vertical: 1,
horizontal: 1,
});
Expand Down

0 comments on commit 59cf71f

Please sign in to comment.