chore(deps): bump tui dependencies

This commit is contained in:
Orhun Parmaksız 2023-06-17 21:25:13 +03:00
parent ba76721bef
commit 56c9281f3a
No known key found for this signature in database
GPG key ID: F83424824B3E4B90
4 changed files with 26 additions and 101 deletions

15
Cargo.lock generated
View file

@ -147,12 +147,6 @@ dependencies = [
"winapi",
]
[[package]]
name = "colorsys"
version = "0.6.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "54261aba646433cb567ec89844be4c4825ca92a4f8afba52fc4dd88436e31bbd"
[[package]]
name = "const-random"
version = "0.1.15"
@ -891,9 +885,9 @@ dependencies = [
[[package]]
name = "ratatui"
version = "0.20.1"
version = "0.21.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dcc0d032bccba900ee32151ec0265667535c230169f5a011154cdcd984e16829"
checksum = "ce841e0486e7c2412c3740168ede33adeba8e154a15107b879d8162d77c7174e"
dependencies = [
"bitflags",
"cassowary",
@ -1160,7 +1154,6 @@ dependencies = [
name = "systeroid-tui"
version = "0.4.1"
dependencies = [
"colorsys",
"copypasta-ext",
"getopts",
"log",
@ -1234,9 +1227,9 @@ dependencies = [
[[package]]
name = "tui-logger"
version = "0.9.1"
version = "0.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aad9900f2273f4a3c3d78405dfc48fa0197c276a139f4d87a5805a7a50223528"
checksum = "556a427e71dc2dc7193c0ab9d02707cf8a284158d287e60d3b0b384b217438bb"
dependencies = [
"chrono",
"fxhash",

View file

@ -23,7 +23,6 @@ unicode-width = "0.1.10"
thiserror = "1.0.40"
getopts = "0.2.21"
copypasta-ext = { version = "0.4.4", optional = true }
colorsys = "0.6.7"
log.workspace = true
[dependencies.systeroid-core]
@ -32,12 +31,12 @@ path = "../systeroid-core"
[dependencies.tui]
package = "ratatui"
version = "0.20.1"
version = "0.21.0"
default-features = false
features = ["termion"]
[dependencies.tui-logger]
version = "0.9.1"
version = "0.9.2"
default-features = false
features = ["ratatui-support"]

View file

@ -14,7 +14,7 @@ pub enum Error {
ClipboardError(String),
/// Error that may occur while parsing a color.
#[error(transparent)]
ColorParseError(#[from] colorsys::ParseError),
ColorParseError(#[from] tui::style::ParseColorError),
/// Error that may occur if the logger is already set.
#[error(transparent)]
LoggerSetError(#[from] log::SetLoggerError),

View file

@ -1,95 +1,47 @@
use crate::error::Result;
use colorsys::{ParseError, Rgb};
use std::result::Result as StdResult;
use std::str::FromStr;
use tui::style::{Color as TuiColor, Style};
/// Color configuration.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct Colors {
/// Background color.
bg: Color,
bg: TuiColor,
/// Foreground color.
fg: Color,
fg: TuiColor,
}
impl Default for Colors {
fn default() -> Self {
Colors {
bg: TuiColor::Reset,
fg: TuiColor::Reset,
}
}
}
impl Colors {
/// Constructs a new instance.
pub fn new(background: &str, foreground: &str) -> Result<Self> {
Ok(Self {
bg: Color::from_str(background)?,
fg: Color::from_str(foreground)?,
bg: TuiColor::from_str(background)?,
fg: TuiColor::from_str(foreground)?,
})
}
/// Returns the background/foreground colors with default style.
pub fn get_style(&self) -> Style {
Style::default().bg(self.fg.get()).fg(self.bg.get())
Style::default().bg(self.fg).fg(self.bg)
}
/// Returns the background color with default style.
pub fn get_bg_style(&self) -> Style {
Style::default().bg(self.bg.get())
Style::default().bg(self.bg)
}
/// Returns the foreground color with default style.
pub fn get_fg_style(&self) -> Style {
Style::default().fg(self.fg.get())
}
}
/// Wrapper for widget colors.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct Color {
/// Inner type.
inner: TuiColor,
}
impl Default for Color {
fn default() -> Self {
Self {
inner: TuiColor::Reset,
}
}
}
impl Color {
/// Returns the underlying [`Color`] type.
///
/// [`Color`]: tui::style::Color
pub fn get(self) -> TuiColor {
self.inner
}
}
impl FromStr for Color {
type Err = ParseError;
fn from_str(s: &str) -> StdResult<Self, Self::Err> {
Ok(Self {
inner: match s.to_lowercase().as_ref() {
"reset" => TuiColor::Reset,
"black" => TuiColor::Black,
"red" => TuiColor::Red,
"green" => TuiColor::Green,
"yellow" => TuiColor::Yellow,
"blue" => TuiColor::Blue,
"magenta" => TuiColor::Magenta,
"cyan" => TuiColor::Cyan,
"gray" => TuiColor::Gray,
"darkgray" | "dark gray" => TuiColor::DarkGray,
"lightred" | "light red" => TuiColor::LightRed,
"lightgreen" | "light green" => TuiColor::LightGreen,
"lightyellow" | "light yellow" => TuiColor::LightYellow,
"lightblue" | "light blue" => TuiColor::LightBlue,
"lightmagenta" | "light magenta" => TuiColor::LightMagenta,
"lightcyan" | "light cyan" => TuiColor::LightCyan,
"white" => TuiColor::White,
_ => {
let rgb = Rgb::from_hex_str(&format!("#{s}"))?;
TuiColor::Rgb(rgb.red() as u8, rgb.green() as u8, rgb.blue() as u8)
}
},
})
Style::default().fg(self.fg)
}
}
@ -97,30 +49,11 @@ impl FromStr for Color {
mod tests {
use super::*;
#[test]
fn test_color() -> Result<()> {
assert_eq!(TuiColor::Reset, Color::default().get());
assert_eq!(TuiColor::Gray, Color::from_str("gray")?.get());
assert_eq!(TuiColor::Black, Color::from_str("black")?.get());
assert_eq!(TuiColor::Green, Color::from_str("green")?.get());
assert_eq!(TuiColor::LightRed, Color::from_str("light red")?.get());
assert_eq!(TuiColor::LightBlue, Color::from_str("lightblue")?.get());
assert_eq!(
TuiColor::Rgb(152, 157, 69),
Color::from_str("989D45")?.get()
);
assert_eq!(TuiColor::Rgb(18, 49, 47), Color::from_str("12312F")?.get());
assert_eq!(
TuiColor::Rgb(255, 242, 255),
Color::from_str("FFF2FF")?.get()
);
Ok(())
}
#[test]
fn test_style() -> Result<()> {
assert_eq!(
Colors {
bg: Color::from_str("red")?,
fg: Color::from_str("blue")?,
bg: TuiColor::from_str("red")?,
fg: TuiColor::from_str("blue")?,
},
Colors::new("red", "blue")?
);