Skip to content
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ phf = "0.13.1"
phf_codegen = "0.13.0"
prettytable-rs = "0.10.0"
rand = { version = "0.9.0", features = ["small_rng"] }
ratatui = "0.29.0"
ratatui = "0.30.0"
regex = "1.10.4"
rustix = { version = "1.1.2", features = ["fs"] }
sysinfo = "0.37.0"
Expand Down
2 changes: 1 addition & 1 deletion src/uu/tload/src/tui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use ratatui::{
buffer::Buffer,
layout::{Constraint, Direction, Layout, Rect},
style::{Style, Stylize},
style::Style,
symbols::Marker,
text::{Line, Text},
widgets::{Axis, Block, Borders, Chart, Dataset, GraphType, Paragraph, Widget},
Expand Down
54 changes: 24 additions & 30 deletions src/uu/top/src/tui/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,63 +3,57 @@
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

use ratatui::prelude::Stylize;
use ratatui::style::{Color, Styled};
use ratatui::style::{Color, Style};

pub(crate) trait TuiColor<'a, T>: Sized {
fn primary(self, colorful: bool) -> T;
fn bg_primary(self, colorful: bool) -> T;
fn secondary(self, colorful: bool) -> T;
fn bg_secondary(self, colorful: bool) -> T;
fn error(self, colorful: bool) -> T;
/// This is the trait used to adjust the TUI color options
pub(crate) trait TuiColorHelper: Sized {
fn primary(self, colorful: bool) -> Style;
fn bg_primary(self, colorful: bool) -> Style;
fn secondary(self, colorful: bool) -> Style;
fn bg_secondary(self, colorful: bool) -> Style;
fn error(self, colorful: bool) -> Style;
}

impl<'a, T, U> TuiColor<'a, T> for U
where
U: Styled<Item = T>,
{
fn primary(self, colorful: bool) -> T {
let style = self.style();
impl TuiColorHelper for Style {
fn primary(self, colorful: bool) -> Style {
if colorful {
self.red()
} else {
self.set_style(style)
self
}
}

fn bg_primary(self, colorful: bool) -> T {
let style = self.style().fg(Color::Black);
fn bg_primary(self, colorful: bool) -> Style {
let style = self.fg(Color::Black);
if colorful {
self.set_style(style.bg(Color::Red))
style.bg(Color::Red)
} else {
self.set_style(style.bg(Color::White))
style.bg(Color::White)
}
}

fn secondary(self, colorful: bool) -> T {
let style = self.style();
fn secondary(self, colorful: bool) -> Style {
if colorful {
self.yellow()
} else {
self.set_style(style)
self
}
}

fn bg_secondary(self, colorful: bool) -> T {
let style = self.style().fg(Color::Black);
fn bg_secondary(self, colorful: bool) -> Style {
let style = self.fg(Color::Black);
if colorful {
self.set_style(style.bg(Color::Yellow))
style.bg(Color::Yellow)
} else {
self.set_style(style.bg(Color::White))
style.bg(Color::White)
}
}

fn error(self, colorful: bool) -> T {
let style = self.style();
fn error(self, colorful: bool) -> Style {
if colorful {
self.set_style(style.fg(Color::Black).bg(Color::Red))
self.fg(Color::Black).bg(Color::Red)
} else {
self.set_style(style)
self
}
}
}
2 changes: 1 addition & 1 deletion src/uu/top/src/tui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub use input::*;
use std::borrow::Cow;

use crate::header::{format_memory, Header};
use crate::tui::color::TuiColor;
use crate::tui::color::TuiColorHelper;
use crate::tui::stat::{CpuGraphMode, MemoryGraphMode, TuiStat};
use crate::{InfoBar, ProcList};
use ratatui::prelude::*;
Expand Down
Loading