Skip to content

Commit

Permalink
..
Browse files Browse the repository at this point in the history
  • Loading branch information
sxyazi committed Oct 12, 2023
1 parent 3718473 commit 8b49ef6
Show file tree
Hide file tree
Showing 16 changed files with 279 additions and 216 deletions.
12 changes: 6 additions & 6 deletions app/src/help/bindings.rs
Original file line number Diff line number Diff line change
@@ -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,
}
Expand All @@ -21,21 +21,21 @@ 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
let col3 = 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<_>>();

Expand All @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions app/src/help/layout.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions app/src/input/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,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() {
Expand All @@ -49,7 +49,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(),
)
}

Expand Down
10 changes: 5 additions & 5 deletions app/src/select/select.rs
Original file line number Diff line number Diff line change
@@ -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,
}
Expand All @@ -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<_>>();

Expand All @@ -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);
}
Expand Down
6 changes: 3 additions & 3 deletions app/src/tasks/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ 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)
.padding(Padding::new(0, 0, 1, 1))
// 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;
Expand All @@ -69,7 +69,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
})
Expand Down
5 changes: 3 additions & 2 deletions app/src/which/layout.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions app/src/which/side.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
Expand Down
Loading

0 comments on commit 8b49ef6

Please sign in to comment.