mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
..
This commit is contained in:
parent
ca9d77b6a2
commit
faa3281322
13 changed files with 129 additions and 26 deletions
|
|
@ -1,8 +1,8 @@
|
|||
use core::Ctx;
|
||||
|
||||
use config::THEME;
|
||||
use ratatui::{layout::{self, Constraint}, prelude::{Buffer, Direction, Rect}, widgets::{List, ListItem, Widget}};
|
||||
|
||||
use crate::context::Ctx;
|
||||
|
||||
pub(super) struct Bindings<'a> {
|
||||
cx: &'a Ctx,
|
||||
}
|
||||
|
|
@ -21,13 +21,13 @@ impl Widget for Bindings<'_> {
|
|||
// Key
|
||||
let col1 = bindings
|
||||
.iter()
|
||||
.map(|c| ListItem::new(c.on()).style(THEME.help.key.get()))
|
||||
.map(|c| ListItem::new(c.on()).style(THEME.help.key.into()))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
// Execution
|
||||
let col2 = bindings
|
||||
.iter()
|
||||
.map(|c| ListItem::new(c.exec()).style(THEME.help.exec.get()))
|
||||
.map(|c| ListItem::new(c.exec()).style(THEME.help.exec.into()))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
// Description
|
||||
|
|
@ -35,7 +35,7 @@ impl Widget for Bindings<'_> {
|
|||
.iter()
|
||||
.map(|c| {
|
||||
ListItem::new(if let Some(ref desc) = c.desc { desc } else { "-" })
|
||||
.style(THEME.help.desc.get())
|
||||
.style(THEME.help.desc.into())
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
|
|
@ -47,7 +47,7 @@ impl Widget for Bindings<'_> {
|
|||
let cursor = self.cx.help.rel_cursor() as u16;
|
||||
buf.set_style(
|
||||
Rect { x: area.x, y: area.y + cursor, width: area.width, height: 1 },
|
||||
THEME.help.curr.get(),
|
||||
THEME.help.curr.into(),
|
||||
);
|
||||
|
||||
List::new(col1).render(chunks[0], buf);
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
use core::Ctx;
|
||||
|
||||
use config::THEME;
|
||||
use ratatui::{buffer::Buffer, layout::{self, Rect}, prelude::{Constraint, Direction}, widgets::{Clear, Paragraph, Widget}};
|
||||
|
||||
use super::Bindings;
|
||||
use crate::Ctx;
|
||||
|
||||
pub(crate) struct Layout<'a> {
|
||||
cx: &'a Ctx,
|
||||
|
|
@ -23,7 +24,7 @@ impl<'a> Widget for Layout<'a> {
|
|||
|
||||
let help = &self.cx.help;
|
||||
Paragraph::new(help.keyword().unwrap_or_else(|| format!("{}.help", help.layer())))
|
||||
.style(THEME.help.btm.get())
|
||||
.style(THEME.help.btm.into())
|
||||
.render(chunks[1], buf);
|
||||
|
||||
Bindings::new(self.cx).render(chunks[0], buf);
|
||||
|
|
|
|||
|
|
@ -31,14 +31,14 @@ impl<'a> Widget for Input<'a> {
|
|||
Block::new()
|
||||
.borders(Borders::ALL)
|
||||
.border_type(BorderType::Rounded)
|
||||
.border_style(THEME.input.border.get())
|
||||
.border_style(THEME.input.border.into())
|
||||
.title({
|
||||
let mut line = Line::from(input.title());
|
||||
line.patch_style(THEME.input.title.get());
|
||||
line.patch_style(THEME.input.title.into());
|
||||
line
|
||||
}),
|
||||
)
|
||||
.style(THEME.input.text.get())
|
||||
.style(THEME.input.text.into())
|
||||
.render(area, buf);
|
||||
|
||||
if let Some(Range { start, end }) = input.selected() {
|
||||
|
|
@ -47,7 +47,7 @@ impl<'a> Widget for Input<'a> {
|
|||
|
||||
buf.set_style(
|
||||
Rect { x, y, width: (end - start).min(win.width - x), height: 1.min(win.height - y) },
|
||||
THEME.input.visual.get(),
|
||||
THEME.input.visual.into(),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use core::Ctx;
|
||||
|
||||
use config::THEME;
|
||||
use ratatui::{buffer::Buffer, layout::Rect, widgets::{Block, BorderType, Borders, Clear, List, ListItem, Widget}};
|
||||
|
||||
use crate::Ctx;
|
||||
|
||||
pub(crate) struct Select<'a> {
|
||||
cx: &'a Ctx,
|
||||
}
|
||||
|
|
@ -22,10 +22,10 @@ impl<'a> Widget for Select<'a> {
|
|||
.enumerate()
|
||||
.map(|(i, v)| {
|
||||
if i != select.rel_cursor() {
|
||||
return ListItem::new(format!(" {v}")).style(THEME.opener.inactive.get());
|
||||
return ListItem::new(format!(" {v}")).style(THEME.select.inactive.into());
|
||||
}
|
||||
|
||||
ListItem::new(format!(" {v}")).style(THEME.opener.active.get())
|
||||
ListItem::new(format!(" {v}")).style(THEME.select.active.into())
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
|
|
@ -36,7 +36,7 @@ impl<'a> Widget for Select<'a> {
|
|||
.title(select.title())
|
||||
.borders(Borders::ALL)
|
||||
.border_type(BorderType::Rounded)
|
||||
.border_style(THEME.opener.border.get()),
|
||||
.border_style(THEME.select.border.into()),
|
||||
)
|
||||
.render(area, buf);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ impl<'a> Widget for Layout<'a> {
|
|||
let block = Block::new()
|
||||
.title({
|
||||
let mut line = Line::from("Tasks".to_string());
|
||||
line.patch_style(THEME.tasks.title.get());
|
||||
line.patch_style(THEME.tasks.title.into());
|
||||
line
|
||||
})
|
||||
.title_alignment(Alignment::Center)
|
||||
|
|
@ -49,7 +49,7 @@ impl<'a> Widget for Layout<'a> {
|
|||
// Maybe also add these border type in to the later theme system
|
||||
.borders(Borders::ALL)
|
||||
.border_type(BorderType::Rounded)
|
||||
.border_style(THEME.tasks.border.get());
|
||||
.border_style(THEME.tasks.border.into());
|
||||
block.clone().render(area, buf);
|
||||
|
||||
let tasks = &self.cx.tasks;
|
||||
|
|
@ -60,7 +60,7 @@ impl<'a> Widget for Layout<'a> {
|
|||
.map(|(i, v)| {
|
||||
let mut item = ListItem::new(v.name.clone());
|
||||
if i == tasks.cursor {
|
||||
item = item.style(THEME.tasks.items.get());
|
||||
item = item.style(THEME.tasks.items.into());
|
||||
}
|
||||
item
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
use core::Ctx;
|
||||
|
||||
use config::THEME;
|
||||
use ratatui::{layout, prelude::{Buffer, Constraint, Direction, Rect}, widgets::{Block, Clear, Widget}};
|
||||
|
||||
use super::Side;
|
||||
use crate::Ctx;
|
||||
|
||||
pub(crate) struct Which<'a> {
|
||||
cx: &'a Ctx,
|
||||
|
|
@ -41,7 +42,7 @@ impl Widget for Which<'_> {
|
|||
.split(area);
|
||||
|
||||
Clear.render(area, buf);
|
||||
Block::new().style(THEME.which.block.get()).render(area, buf);
|
||||
Block::new().style(THEME.which.block.into()).render(area, buf);
|
||||
Side::new(which.times, cands.0).render(chunks[0], buf);
|
||||
Side::new(which.times, cands.1).render(chunks[1], buf);
|
||||
Side::new(which.times, cands.2).render(chunks[2], buf);
|
||||
|
|
|
|||
|
|
@ -21,19 +21,19 @@ impl Widget for Side<'_> {
|
|||
// Keys
|
||||
let keys = c.on[self.times..].iter().map(ToString::to_string).collect::<Vec<_>>();
|
||||
spans.push(Span::raw(" ".repeat(10usize.saturating_sub(keys.join("").len()))));
|
||||
spans.push(Span::styled(keys[0].clone(), THEME.which.key.get()));
|
||||
spans.push(Span::styled(keys[0].clone(), THEME.which.key.into()));
|
||||
spans.extend(
|
||||
keys.iter().skip(1).map(|k| Span::styled(k.to_string(), THEME.which.extend.get())),
|
||||
keys.iter().skip(1).map(|k| Span::styled(k.to_string(), THEME.which.extend.into())),
|
||||
);
|
||||
|
||||
// Separator
|
||||
spans.push(Span::styled(
|
||||
THEME.which.separator.separator.to_string(),
|
||||
Style::new().fg(*THEME.which.separator.color),
|
||||
Style::new().fg(THEME.which.separator.color.into()),
|
||||
));
|
||||
|
||||
// Exec,
|
||||
spans.push(Span::styled(c.desc_or_exec(), THEME.which.desc.get()));
|
||||
spans.push(Span::styled(c.desc_or_exec(), THEME.which.desc.into()));
|
||||
|
||||
ListItem::new(Line::from(spans))
|
||||
})
|
||||
|
|
|
|||
12
config/src/theme/help.rs
Normal file
12
config/src/theme/help.rs
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::Style;
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub struct Help {
|
||||
pub key: Style,
|
||||
pub exec: Style,
|
||||
pub desc: Style,
|
||||
pub curr: Style,
|
||||
pub btm: Style,
|
||||
}
|
||||
11
config/src/theme/input.rs
Normal file
11
config/src/theme/input.rs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::Style;
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub struct Input {
|
||||
pub border: Style,
|
||||
pub title: Style,
|
||||
pub value: Style,
|
||||
pub selected: Style,
|
||||
}
|
||||
33
config/src/theme/manager.rs
Normal file
33
config/src/theme/manager.rs
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
use std::path::PathBuf;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use validator::Validate;
|
||||
|
||||
use super::Style;
|
||||
|
||||
#[derive(Deserialize, Serialize, Validate)]
|
||||
pub struct Tabs {
|
||||
pub active: Style,
|
||||
pub inactive: Style,
|
||||
pub header: Style,
|
||||
#[validate(range(min = 1, message = "Must be greater than 0"))]
|
||||
pub max_width: u8,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub struct Files {
|
||||
pub hovered: Style,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub struct Marker {
|
||||
pub selected: Style,
|
||||
pub copied: Style,
|
||||
pub cut: Style,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub struct Preview {
|
||||
pub hovered: Style,
|
||||
pub syntect_theme: PathBuf,
|
||||
}
|
||||
10
config/src/theme/select.rs
Normal file
10
config/src/theme/select.rs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::Style;
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub struct Select {
|
||||
pub border: Style,
|
||||
pub active: Style,
|
||||
pub inactive: Style,
|
||||
}
|
||||
10
config/src/theme/tasks.rs
Normal file
10
config/src/theme/tasks.rs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::Style;
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub struct Tasks {
|
||||
pub border: Style,
|
||||
pub title: Style,
|
||||
pub hovered: Style,
|
||||
}
|
||||
25
config/src/theme/which.rs
Normal file
25
config/src/theme/which.rs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::{Color, Style};
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub struct Which {
|
||||
pub block: Style,
|
||||
pub key: Style,
|
||||
pub separator: WhichSeparator,
|
||||
pub extend: Style,
|
||||
pub desc: Style,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub struct WhichItem {
|
||||
pub key: Color,
|
||||
pub extend: Color,
|
||||
pub description: Color,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub struct WhichSeparator {
|
||||
pub separator: String,
|
||||
pub color: Color,
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue