Use success and fail colors and reorder imports

Use theme color instead of using ratatui::Color for running_command success and fail + search preview text color + min tui warning color, add colors for confirmation prompt, fix inverted success and fail colors
This commit is contained in:
Jeevitha Kannan K S 2024-11-10 16:29:14 +05:30
parent 8639da3855
commit 1aa1dfe382
No known key found for this signature in database
GPG Key ID: 5904C34A2F7CE333
9 changed files with 50 additions and 45 deletions

View File

@ -1,13 +1,11 @@
use std::borrow::Cow;
use crate::{float::FloatContent, hint::Shortcut};
use crate::{float::FloatContent, hint::Shortcut, theme};
use ratatui::{
crossterm::event::{KeyCode, KeyEvent},
layout::Alignment,
prelude::*,
widgets::{Block, Borders, Clear, List},
};
use std::borrow::Cow;
pub enum ConfirmStatus {
Confirm,
@ -57,12 +55,19 @@ impl ConfirmPrompt {
}
impl FloatContent for ConfirmPrompt {
fn draw(&mut self, frame: &mut Frame, area: Rect) {
fn draw(&mut self, frame: &mut Frame, area: Rect, theme: &theme::Theme) {
let block = Block::default()
.borders(Borders::ALL)
.border_set(ratatui::symbols::border::ROUNDED)
.title(" Confirm selections ")
.title_bottom(" [y] to continue, [n] to abort ")
.title_bottom(Line::from(vec![
Span::styled(" [", Style::default()),
Span::styled("y", Style::default().fg(theme.success_color())),
Span::styled("] to continue ", Style::default()),
Span::styled("[", Style::default()),
Span::styled("n", Style::default().fg(theme.fail_color())),
Span::styled("] to abort ", Style::default()),
]))
.title_alignment(Alignment::Center)
.title_style(Style::default().bold())
.style(Style::default());

View File

@ -3,7 +3,7 @@ use linutil_core::{ego_tree::NodeId, Tab};
use ratatui::{
crossterm::event::{KeyCode, KeyEvent, KeyModifiers},
layout::{Position, Rect},
style::{Color, Style},
style::Style,
text::Span,
widgets::{Block, Borders, Paragraph},
Frame,
@ -144,7 +144,8 @@ impl Filter {
frame.set_cursor_position(Position::new(x, y));
if let Some(preview) = &self.completion_preview {
let preview_span = Span::styled(preview, Style::default().fg(Color::DarkGray));
let preview_span =
Span::styled(preview, Style::default().fg(theme.search_preview_color()));
let preview_paragraph = Paragraph::new(preview_span).style(Style::default());
let preview_area = Rect::new(
x,

View File

@ -1,13 +1,12 @@
use crate::{hint::Shortcut, theme::Theme};
use ratatui::{
crossterm::event::{KeyCode, KeyEvent},
layout::{Constraint, Direction, Layout, Rect},
Frame,
};
use crate::hint::Shortcut;
pub trait FloatContent {
fn draw(&mut self, frame: &mut Frame, area: Rect);
fn draw(&mut self, frame: &mut Frame, area: Rect, theme: &Theme);
fn handle_key_event(&mut self, key: &KeyEvent) -> bool;
fn is_finished(&self) -> bool;
fn get_shortcut_list(&self) -> (&str, Box<[Shortcut]>);
@ -48,9 +47,9 @@ impl<Content: FloatContent + ?Sized> Float<Content> {
.split(hor_float)[1]
}
pub fn draw(&mut self, frame: &mut Frame, parent_area: Rect) {
pub fn draw(&mut self, frame: &mut Frame, parent_area: Rect, theme: &Theme) {
let popup_area = self.floating_window(parent_area);
self.content.draw(frame, popup_area);
self.content.draw(frame, popup_area, theme);
}
// Returns true if the floating window is finished.

View File

@ -1,13 +1,6 @@
use std::{
borrow::Cow,
collections::VecDeque,
io::{Cursor, Read as _, Seek, SeekFrom, Write as _},
};
use crate::{float::FloatContent, hint::Shortcut};
use crate::{float::FloatContent, hint::Shortcut, theme::Theme};
use ansi_to_tui::IntoText;
use linutil_core::Command;
use ratatui::{
crossterm::event::{KeyCode, KeyEvent},
layout::Rect,
@ -16,9 +9,11 @@ use ratatui::{
widgets::{Block, Borders, Clear, List},
Frame,
};
use ansi_to_tui::IntoText;
use std::{
borrow::Cow,
collections::VecDeque,
io::{Cursor, Read as _, Seek, SeekFrom, Write as _},
};
use textwrap::wrap;
use tree_sitter_bash as hl_bash;
use tree_sitter_highlight::{self as hl, HighlightEvent};
@ -209,7 +204,7 @@ impl FloatingText {
}
impl FloatContent for FloatingText {
fn draw(&mut self, frame: &mut Frame, area: Rect) {
fn draw(&mut self, frame: &mut Frame, area: Rect, _theme: &Theme) {
self.frame_height = area.height as usize;
// Define the Block with a border and background color

View File

@ -1,9 +1,8 @@
use std::borrow::Cow;
use ratatui::{
style::{Style, Stylize},
text::{Line, Span},
};
use std::borrow::Cow;
pub struct Shortcut {
pub key_sequences: Vec<Span<'static>>,

View File

@ -7,15 +7,8 @@ mod running_command;
pub mod state;
mod theme;
use std::{
io::{self, stdout},
path::PathBuf,
time::Duration,
};
use crate::theme::Theme;
use clap::Parser;
use ratatui::{
backend::CrosstermBackend,
crossterm::{
@ -27,6 +20,11 @@ use ratatui::{
Terminal,
};
use state::AppState;
use std::{
io::{self, stdout},
path::PathBuf,
time::Duration,
};
// Linux utility toolbox
#[derive(Debug, Parser)]

View File

@ -1,4 +1,4 @@
use crate::{float::FloatContent, hint::Shortcut};
use crate::{float::FloatContent, hint::Shortcut, theme::Theme};
use linutil_core::Command;
use oneshot::{channel, Receiver};
use portable_pty::{
@ -7,7 +7,7 @@ use portable_pty::{
use ratatui::{
crossterm::event::{KeyCode, KeyEvent, KeyModifiers},
layout::{Rect, Size},
style::{Color, Style, Stylize},
style::{Style, Stylize},
text::{Line, Span},
widgets::{Block, Borders},
Frame,
@ -22,6 +22,7 @@ use tui_term::{
vt100::{self, Screen},
widget::PseudoTerminal,
};
pub struct RunningCommand {
/// A buffer to save all the command output (accumulates, until the command exits)
buffer: Arc<Mutex<Vec<u8>>>,
@ -42,7 +43,7 @@ pub struct RunningCommand {
}
impl FloatContent for RunningCommand {
fn draw(&mut self, frame: &mut Frame, area: Rect) {
fn draw(&mut self, frame: &mut Frame, area: Rect, theme: &Theme) {
// Calculate the inner size of the terminal area, considering borders
let inner_size = Size {
width: area.width - 2, // Adjust for border width
@ -64,13 +65,13 @@ impl FloatContent for RunningCommand {
Line::from(
Span::default()
.content("SUCCESS!")
.style(Style::default().fg(Color::Green).reversed()),
.style(Style::default().fg(theme.success_color()).reversed()),
)
} else {
Line::from(
Span::default()
.content("FAILED!")
.style(Style::default().fg(Color::Red).reversed()),
.style(Style::default().fg(theme.fail_color()).reversed()),
)
};

View File

@ -229,7 +229,7 @@ impl AppState {
MIN_HEIGHT,
))
.alignment(Alignment::Center)
.style(Style::default().fg(ratatui::style::Color::Red).bold())
.style(Style::default().fg(self.theme.fail_color()).bold())
.wrap(ratatui::widgets::Wrap { trim: true });
let centered_layout = Layout::default()
@ -461,8 +461,8 @@ impl AppState {
frame.render_stateful_widget(disclaimer_list, list_chunks[1], &mut self.selection);
match &mut self.focus {
Focus::FloatingWindow(float) => float.draw(frame, chunks[1]),
Focus::ConfirmationPrompt(prompt) => prompt.draw(frame, chunks[1]),
Focus::FloatingWindow(float) => float.draw(frame, chunks[1], &self.theme),
Focus::ConfirmationPrompt(prompt) => prompt.draw(frame, chunks[1], &self.theme),
_ => {}
}

View File

@ -72,14 +72,14 @@ impl Theme {
pub fn success_color(&self) -> Color {
match self {
Theme::Default => Color::Rgb(199, 55, 44),
Theme::Default => Color::Rgb(5, 255, 55),
Theme::Compatible => Color::Green,
}
}
pub fn fail_color(&self) -> Color {
match self {
Theme::Default => Color::Rgb(5, 255, 55),
Theme::Default => Color::Rgb(199, 55, 44),
Theme::Compatible => Color::Red,
}
}
@ -91,6 +91,13 @@ impl Theme {
}
}
pub fn search_preview_color(&self) -> Color {
match self {
Theme::Default => Color::DarkGray,
Theme::Compatible => Color::DarkGray,
}
}
pub fn unfocused_color(&self) -> Color {
match self {
Theme::Default => Color::Gray,