This commit is contained in:
sxyazi 2023-10-12 09:21:31 +08:00
parent ca9d77b6a2
commit faa3281322
No known key found for this signature in database
13 changed files with 129 additions and 26 deletions

View file

@ -1,8 +1,8 @@
use core::Ctx;
use config::THEME; use config::THEME;
use ratatui::{layout::{self, Constraint}, prelude::{Buffer, Direction, Rect}, widgets::{List, ListItem, Widget}}; use ratatui::{layout::{self, Constraint}, prelude::{Buffer, Direction, Rect}, widgets::{List, ListItem, Widget}};
use crate::context::Ctx;
pub(super) struct Bindings<'a> { pub(super) struct Bindings<'a> {
cx: &'a Ctx, cx: &'a Ctx,
} }
@ -21,13 +21,13 @@ impl Widget for Bindings<'_> {
// Key // Key
let col1 = bindings let col1 = bindings
.iter() .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<_>>(); .collect::<Vec<_>>();
// Execution // Execution
let col2 = bindings let col2 = bindings
.iter() .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<_>>(); .collect::<Vec<_>>();
// Description // Description
@ -35,7 +35,7 @@ impl Widget for Bindings<'_> {
.iter() .iter()
.map(|c| { .map(|c| {
ListItem::new(if let Some(ref desc) = c.desc { desc } else { "-" }) ListItem::new(if let Some(ref desc) = c.desc { desc } else { "-" })
.style(THEME.help.desc.get()) .style(THEME.help.desc.into())
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();
@ -47,7 +47,7 @@ impl Widget for Bindings<'_> {
let cursor = self.cx.help.rel_cursor() as u16; let cursor = self.cx.help.rel_cursor() as u16;
buf.set_style( buf.set_style(
Rect { x: area.x, y: area.y + cursor, width: area.width, height: 1 }, 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); List::new(col1).render(chunks[0], buf);

View file

@ -1,8 +1,9 @@
use core::Ctx;
use config::THEME; use config::THEME;
use ratatui::{buffer::Buffer, layout::{self, Rect}, prelude::{Constraint, Direction}, widgets::{Clear, Paragraph, Widget}}; use ratatui::{buffer::Buffer, layout::{self, Rect}, prelude::{Constraint, Direction}, widgets::{Clear, Paragraph, Widget}};
use super::Bindings; use super::Bindings;
use crate::Ctx;
pub(crate) struct Layout<'a> { pub(crate) struct Layout<'a> {
cx: &'a Ctx, cx: &'a Ctx,
@ -23,7 +24,7 @@ impl<'a> Widget for Layout<'a> {
let help = &self.cx.help; let help = &self.cx.help;
Paragraph::new(help.keyword().unwrap_or_else(|| format!("{}.help", help.layer()))) 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); .render(chunks[1], buf);
Bindings::new(self.cx).render(chunks[0], buf); Bindings::new(self.cx).render(chunks[0], buf);

View file

@ -31,14 +31,14 @@ impl<'a> Widget for Input<'a> {
Block::new() Block::new()
.borders(Borders::ALL) .borders(Borders::ALL)
.border_type(BorderType::Rounded) .border_type(BorderType::Rounded)
.border_style(THEME.input.border.get()) .border_style(THEME.input.border.into())
.title({ .title({
let mut line = Line::from(input.title()); let mut line = Line::from(input.title());
line.patch_style(THEME.input.title.get()); line.patch_style(THEME.input.title.into());
line line
}), }),
) )
.style(THEME.input.text.get()) .style(THEME.input.text.into())
.render(area, buf); .render(area, buf);
if let Some(Range { start, end }) = input.selected() { if let Some(Range { start, end }) = input.selected() {
@ -47,7 +47,7 @@ impl<'a> Widget for Input<'a> {
buf.set_style( buf.set_style(
Rect { x, y, width: (end - start).min(win.width - x), height: 1.min(win.height - y) }, Rect { x, y, width: (end - start).min(win.width - x), height: 1.min(win.height - y) },
THEME.input.visual.get(), THEME.input.visual.into(),
) )
} }

View file

@ -1,8 +1,8 @@
use core::Ctx;
use config::THEME; use config::THEME;
use ratatui::{buffer::Buffer, layout::Rect, widgets::{Block, BorderType, Borders, Clear, List, ListItem, Widget}}; use ratatui::{buffer::Buffer, layout::Rect, widgets::{Block, BorderType, Borders, Clear, List, ListItem, Widget}};
use crate::Ctx;
pub(crate) struct Select<'a> { pub(crate) struct Select<'a> {
cx: &'a Ctx, cx: &'a Ctx,
} }
@ -22,10 +22,10 @@ impl<'a> Widget for Select<'a> {
.enumerate() .enumerate()
.map(|(i, v)| { .map(|(i, v)| {
if i != select.rel_cursor() { 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<_>>(); .collect::<Vec<_>>();
@ -36,7 +36,7 @@ impl<'a> Widget for Select<'a> {
.title(select.title()) .title(select.title())
.borders(Borders::ALL) .borders(Borders::ALL)
.border_type(BorderType::Rounded) .border_type(BorderType::Rounded)
.border_style(THEME.opener.border.get()), .border_style(THEME.select.border.into()),
) )
.render(area, buf); .render(area, buf);
} }

View file

@ -41,7 +41,7 @@ impl<'a> Widget for Layout<'a> {
let block = Block::new() let block = Block::new()
.title({ .title({
let mut line = Line::from("Tasks".to_string()); let mut line = Line::from("Tasks".to_string());
line.patch_style(THEME.tasks.title.get()); line.patch_style(THEME.tasks.title.into());
line line
}) })
.title_alignment(Alignment::Center) .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 // Maybe also add these border type in to the later theme system
.borders(Borders::ALL) .borders(Borders::ALL)
.border_type(BorderType::Rounded) .border_type(BorderType::Rounded)
.border_style(THEME.tasks.border.get()); .border_style(THEME.tasks.border.into());
block.clone().render(area, buf); block.clone().render(area, buf);
let tasks = &self.cx.tasks; let tasks = &self.cx.tasks;
@ -60,7 +60,7 @@ impl<'a> Widget for Layout<'a> {
.map(|(i, v)| { .map(|(i, v)| {
let mut item = ListItem::new(v.name.clone()); let mut item = ListItem::new(v.name.clone());
if i == tasks.cursor { if i == tasks.cursor {
item = item.style(THEME.tasks.items.get()); item = item.style(THEME.tasks.items.into());
} }
item item
}) })

View file

@ -1,8 +1,9 @@
use core::Ctx;
use config::THEME; use config::THEME;
use ratatui::{layout, prelude::{Buffer, Constraint, Direction, Rect}, widgets::{Block, Clear, Widget}}; use ratatui::{layout, prelude::{Buffer, Constraint, Direction, Rect}, widgets::{Block, Clear, Widget}};
use super::Side; use super::Side;
use crate::Ctx;
pub(crate) struct Which<'a> { pub(crate) struct Which<'a> {
cx: &'a Ctx, cx: &'a Ctx,
@ -41,7 +42,7 @@ impl Widget for Which<'_> {
.split(area); .split(area);
Clear.render(area, buf); 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.0).render(chunks[0], buf);
Side::new(which.times, cands.1).render(chunks[1], buf); Side::new(which.times, cands.1).render(chunks[1], buf);
Side::new(which.times, cands.2).render(chunks[2], buf); Side::new(which.times, cands.2).render(chunks[2], buf);

View file

@ -21,19 +21,19 @@ impl Widget for Side<'_> {
// Keys // Keys
let keys = c.on[self.times..].iter().map(ToString::to_string).collect::<Vec<_>>(); 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::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( 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 // Separator
spans.push(Span::styled( spans.push(Span::styled(
THEME.which.separator.separator.to_string(), THEME.which.separator.separator.to_string(),
Style::new().fg(*THEME.which.separator.color), Style::new().fg(THEME.which.separator.color.into()),
)); ));
// Exec, // 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)) ListItem::new(Line::from(spans))
}) })

12
config/src/theme/help.rs Normal file
View 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
View 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,
}

View 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,
}

View 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
View 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
View 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,
}