mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-21 23:01:05 +00:00
feat: custom styles for the confirm component (#1789)
Co-authored-by: sxyazi <sxyazi@gmail.com>
This commit is contained in:
parent
a6c9c93d58
commit
53043313ba
6 changed files with 51 additions and 11 deletions
|
|
@ -98,6 +98,20 @@ selected = { reversed = true }
|
|||
# : }}}
|
||||
|
||||
|
||||
# : Confirm {{{
|
||||
|
||||
[confirm]
|
||||
border = { fg = "blue" }
|
||||
title = { fg = "blue" }
|
||||
content = {}
|
||||
list = {}
|
||||
btn_yes = { reversed = true }
|
||||
btn_no = {}
|
||||
btn_labels = [ " [Y]es ", " (N)o " ]
|
||||
|
||||
# : }}}
|
||||
|
||||
|
||||
# : Completion {{{
|
||||
|
||||
[completion]
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ pub struct Theme {
|
|||
pub manager: Manager,
|
||||
status: Status,
|
||||
pub input: Input,
|
||||
pub confirm: Confirm,
|
||||
pub pick: Pick,
|
||||
pub completion: Completion,
|
||||
pub tasks: Tasks,
|
||||
|
|
@ -114,6 +115,17 @@ pub struct Input {
|
|||
pub selected: Style,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub struct Confirm {
|
||||
pub border: Style,
|
||||
pub title: Style,
|
||||
pub content: Style,
|
||||
pub list: Style,
|
||||
pub btn_yes: Style,
|
||||
pub btn_no: Style,
|
||||
pub btn_labels: [String; 2],
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub struct Pick {
|
||||
pub border: Style,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
use ratatui::{buffer::Buffer, layout::{Constraint, Rect}, style::Stylize, text::Span, widgets::{Paragraph, Widget}};
|
||||
use ratatui::{buffer::Buffer, layout::{Constraint, Rect}, text::Span, widgets::{Paragraph, Widget}};
|
||||
use yazi_config::THEME;
|
||||
|
||||
pub(crate) struct Buttons;
|
||||
|
||||
|
|
@ -7,7 +8,11 @@ impl Widget for Buttons {
|
|||
let chunks =
|
||||
ratatui::layout::Layout::horizontal([Constraint::Fill(1), Constraint::Fill(1)]).split(area);
|
||||
|
||||
Paragraph::new(Span::raw(" [Y]es ").reversed()).centered().render(chunks[0], buf);
|
||||
Paragraph::new(Span::raw(" (N)o ")).centered().render(chunks[1], buf);
|
||||
Paragraph::new(Span::raw(&THEME.confirm.btn_labels[0]).style(THEME.confirm.btn_yes))
|
||||
.centered()
|
||||
.render(chunks[0], buf);
|
||||
Paragraph::new(Span::raw(&THEME.confirm.btn_labels[1]).style(THEME.confirm.btn_no))
|
||||
.centered()
|
||||
.render(chunks[1], buf);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
use ratatui::{buffer::Buffer, layout::{Alignment, Constraint, Layout, Margin, Rect}, style::{Style, Stylize}, text::Line, widgets::{Block, BorderType, Widget}};
|
||||
use ratatui::{buffer::Buffer, layout::{Alignment, Constraint, Layout, Margin, Rect}, text::Line, widgets::{Block, BorderType, Widget}};
|
||||
use yazi_config::THEME;
|
||||
|
||||
use crate::Ctx;
|
||||
|
||||
|
|
@ -19,8 +20,8 @@ impl<'a> Widget for Confirm<'a> {
|
|||
|
||||
Block::bordered()
|
||||
.border_type(BorderType::Rounded)
|
||||
.border_style(Style::new().blue())
|
||||
.title(Line::styled(&confirm.title, Style::new().blue()))
|
||||
.border_style(THEME.confirm.border)
|
||||
.title(Line::styled(&confirm.title, THEME.confirm.title))
|
||||
.title_alignment(Alignment::Center)
|
||||
.render(area, buf);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
use ratatui::{buffer::Buffer, layout::{Margin, Rect}, style::{Style, Stylize}, widgets::{Block, Borders, Paragraph, Widget}};
|
||||
use ratatui::{buffer::Buffer, layout::{Margin, Rect}, widgets::{Block, Borders, Paragraph, Widget}};
|
||||
use yazi_config::THEME;
|
||||
|
||||
pub(crate) struct Content<'a> {
|
||||
p: Paragraph<'a>,
|
||||
|
|
@ -14,9 +15,14 @@ impl<'a> Widget for Content<'a> {
|
|||
let inner = area.inner(Margin::new(1, 0));
|
||||
|
||||
// Bottom border
|
||||
let block = Block::new().borders(Borders::BOTTOM).border_style(Style::new().blue());
|
||||
let block = Block::new().borders(Borders::BOTTOM).border_style(THEME.confirm.border);
|
||||
block.clone().render(area.inner(Margin::new(1, 0)), buf);
|
||||
|
||||
self.p.alignment(ratatui::layout::Alignment::Center).block(block).render(inner, buf);
|
||||
self
|
||||
.p
|
||||
.alignment(ratatui::layout::Alignment::Center)
|
||||
.block(block)
|
||||
.style(THEME.confirm.content)
|
||||
.render(inner, buf);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
use ratatui::{buffer::Buffer, layout::{Margin, Rect}, style::{Style, Stylize}, widgets::{Block, Borders, Scrollbar, ScrollbarOrientation, ScrollbarState, StatefulWidget, Widget, Wrap}};
|
||||
use ratatui::{buffer::Buffer, layout::{Margin, Rect}, widgets::{Block, Borders, Scrollbar, ScrollbarOrientation, ScrollbarState, StatefulWidget, Widget, Wrap}};
|
||||
use yazi_config::THEME;
|
||||
|
||||
use crate::Ctx;
|
||||
|
||||
|
|
@ -16,7 +17,7 @@ impl<'a> Widget for List<'a> {
|
|||
let inner = area.inner(Margin::new(2, 0));
|
||||
|
||||
// Bottom border
|
||||
let block = Block::new().borders(Borders::BOTTOM).border_style(Style::new().blue());
|
||||
let block = Block::new().borders(Borders::BOTTOM).border_style(THEME.confirm.border);
|
||||
block.clone().render(area.inner(Margin::new(1, 0)), buf);
|
||||
|
||||
let list = self
|
||||
|
|
@ -26,6 +27,7 @@ impl<'a> Widget for List<'a> {
|
|||
.clone()
|
||||
.scroll((self.cx.confirm.offset as u16, 0))
|
||||
.block(block)
|
||||
.style(THEME.confirm.list)
|
||||
.wrap(Wrap { trim: false });
|
||||
|
||||
// Vertical scrollbar
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue