Skip to content

Commit

Permalink
..
Browse files Browse the repository at this point in the history
  • Loading branch information
sxyazi committed Oct 5, 2023
1 parent f5b9e46 commit 61c633e
Show file tree
Hide file tree
Showing 26 changed files with 175 additions and 139 deletions.
2 changes: 1 addition & 1 deletion app/src/executor.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use core::{emit, files::FilesSorter, input::InputMode, manager::FinderCase};
use core::{emit, files::FilesSorter, input::InputMode, manager::FinderCase, Ctx};

use config::{keymap::{Control, Exec, Key, KeymapLayer}, manager::SortBy, KEYMAP};
use shared::{optional_bool, Url};
Expand Down
2 changes: 1 addition & 1 deletion app/src/header/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl<'a> Widget for Layout<'a> {
fn render(self, area: Rect, buf: &mut Buffer) {
let chunks = layout::Layout::new()
.direction(Direction::Horizontal)
.constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref())
.constraints([Constraint::Percentage(50), Constraint::Percentage(50)])
.split(area);

let cwd = &self.cx.manager.current().cwd;
Expand Down
2 changes: 1 addition & 1 deletion app/src/help/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl<'a> Widget for Layout<'a> {
fn render(self, area: Rect, buf: &mut Buffer) {
let chunks = layout::Layout::new()
.direction(Direction::Vertical)
.constraints([Constraint::Min(0), Constraint::Length(1)].as_ref())
.constraints([Constraint::Min(0), Constraint::Length(1)])
.split(area);

Clear.render(area, buf);
Expand Down
28 changes: 5 additions & 23 deletions app/src/manager/folder.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use core::Ctx;

use ratatui::{buffer::Buffer, layout::Rect, widgets::Widget};
use tracing::info;

pub(super) struct Folder<'a> {
cx: &'a Ctx,
pub(super) struct Folder {
kind: FolderKind,
}

Expand All @@ -14,11 +11,11 @@ pub(super) enum FolderKind {
Preview = 2,
}

impl<'a> Folder<'a> {
pub(super) fn new(cx: &'a Ctx, kind: FolderKind) -> Self { Self { cx, kind } }
impl Folder {
pub(super) fn new(kind: FolderKind) -> Self { Self { kind } }
}

impl<'a> Folder<'a> {
impl Folder {
// fn highlighted_item<'b>(&'b self, file: &'b File) -> Vec<Span> {
// let short = short_path(file.url(), &self.folder.cwd);
//
Expand All @@ -39,7 +36,7 @@ impl<'a> Folder<'a> {
// }
}

impl<'a> Widget for Folder<'a> {
impl Widget for Folder {
fn render(self, area: Rect, buf: &mut Buffer) {
let x = plugin::Folder { kind: self.kind as u8 }.render(area);
if x.is_err() {
Expand All @@ -55,21 +52,6 @@ impl<'a> Widget for Folder<'a> {
// .iter()
// .enumerate()
// .map(|(i, f)| {
// let is_selected = self.folder.files.is_selected(f.url());
// if (!self.is_selection && is_selected)
// || (self.is_selection && mode.pending(self.folder.offset() + i, is_selected))
// {
// buf.set_style(
// Rect { x: area.x.saturating_sub(1), y: i as u16 + 1, width: 1, height: 1
// }, if self.is_selection {
// THEME.marker.selecting.get()
// } else {
// THEME.marker.selected.get()
// },
// );
// }
//
//
// if let Some(idx) = active
// .finder()
// .filter(|&f| hovered && self.is_find && f.has_matched())
Expand Down
17 changes: 7 additions & 10 deletions app/src/manager/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,22 @@ impl<'a> Widget for Layout<'a> {

let chunks = layout::Layout::new()
.direction(Direction::Horizontal)
.constraints(
[
Constraint::Ratio(layout.parent, layout.all),
Constraint::Ratio(layout.current, layout.all),
Constraint::Ratio(layout.preview, layout.all),
]
.as_ref(),
)
.constraints([
Constraint::Ratio(layout.parent, layout.all),
Constraint::Ratio(layout.current, layout.all),
Constraint::Ratio(layout.preview, layout.all),
])
.split(area);

// Parent
let block = Block::new().borders(Borders::RIGHT).padding(Padding::new(1, 0, 0, 0));
if manager.parent().is_some() {
Folder::new(self.cx, FolderKind::Parent).render(block.inner(chunks[0]), buf);
Folder::new(FolderKind::Parent).render(block.inner(chunks[0]), buf);
}
block.render(chunks[0], buf);

// Current
Folder::new(self.cx, FolderKind::Current).render(chunks[1], buf);
Folder::new(FolderKind::Current).render(chunks[1], buf);

// Preview
let block = Block::new().borders(Borders::LEFT).padding(Padding::new(0, 1, 0, 0));
Expand Down
2 changes: 1 addition & 1 deletion app/src/manager/preview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl<'a> Widget for Preview<'a> {

match &preview.lock.as_ref().unwrap().data {
PreviewData::Folder => {
Folder::new(self.cx, FolderKind::Preview).render(area, buf);
Folder::new(FolderKind::Preview).render(area, buf);
}
PreviewData::Text(s) => {
let p = Paragraph::new(s.as_bytes().into_text().unwrap());
Expand Down
4 changes: 2 additions & 2 deletions app/src/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ impl<'a> Widget for Root<'a> {
fn render(self, area: Rect, buf: &mut Buffer) {
let chunks = Layout::new()
.direction(Direction::Vertical)
.constraints([Constraint::Length(1), Constraint::Min(0), Constraint::Length(1)].as_ref())
.constraints([Constraint::Length(1), Constraint::Min(0), Constraint::Length(1)])
.split(area);

header::Layout::new(self.cx).render(chunks[0], buf);
manager::Layout::new(self.cx).render(chunks[1], buf);
status::Layout::new(self.cx).render(chunks[2], buf);
status::Layout.render(chunks[2], buf);

if self.cx.tasks.visible {
tasks::Layout::new(self.cx).render(area, buf);
Expand Down
12 changes: 2 additions & 10 deletions app/src/status/layout.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
use core::Ctx;

use ratatui::{buffer::Buffer, prelude::Rect, widgets::Widget};
use tracing::info;

pub(crate) struct Layout<'a> {
cx: &'a Ctx,
}

impl<'a> Layout<'a> {
pub(crate) fn new(cx: &'a Ctx) -> Self { Self { cx } }
}
pub(crate) struct Layout;

impl<'a> Widget for Layout<'a> {
impl Widget for Layout {
fn render(self, area: Rect, buf: &mut Buffer) {
let x = plugin::Status::render(area);
if x.is_err() {
Expand Down
32 changes: 12 additions & 20 deletions app/src/tasks/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,21 @@ impl<'a> Layout<'a> {
pub(super) fn area(area: Rect) -> Rect {
let chunk = layout::Layout::new()
.direction(Direction::Vertical)
.constraints(
[
Constraint::Percentage((100 - TASKS_PERCENT) / 2),
Constraint::Percentage(TASKS_PERCENT),
Constraint::Percentage((100 - TASKS_PERCENT) / 2),
]
.as_ref(),
)
.constraints([
Constraint::Percentage((100 - TASKS_PERCENT) / 2),
Constraint::Percentage(TASKS_PERCENT),
Constraint::Percentage((100 - TASKS_PERCENT) / 2),
])
.split(area)[1];

let chunk = layout::Layout::new()
layout::Layout::new()
.direction(Direction::Horizontal)
.constraints(
[
Constraint::Percentage((100 - TASKS_PERCENT) / 2),
Constraint::Percentage(TASKS_PERCENT),
Constraint::Percentage((100 - TASKS_PERCENT) / 2),
]
.as_ref(),
)
.split(chunk)[1];

chunk
.constraints([
Constraint::Percentage((100 - TASKS_PERCENT) / 2),
Constraint::Percentage(TASKS_PERCENT),
Constraint::Percentage((100 - TASKS_PERCENT) / 2),
])
.split(chunk)[1]
}
}

Expand Down
4 changes: 1 addition & 3 deletions app/src/which/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ impl Widget for Which<'_> {

let chunks = layout::Layout::new()
.direction(Direction::Horizontal)
.constraints(
[Constraint::Ratio(1, 3), Constraint::Ratio(1, 3), Constraint::Ratio(1, 3)].as_ref(),
)
.constraints([Constraint::Ratio(1, 3), Constraint::Ratio(1, 3), Constraint::Ratio(1, 3)])
.split(area);

Clear.render(area, buf);
Expand Down
7 changes: 4 additions & 3 deletions config/preset/theme.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ permissions_r = { fg = "#F3D398" }
permissions_w = { fg = "#FA7F94" }
permissions_x = { fg = "#7AD9E5" }

[selection]
[files]
hovered = { fg = "#1E2031", bg = "#80AEFA" }

[marker]
selecting = { fg = "#97DC8D", bg = "#97DC8D" }
selected = { fg = "#F3D398", bg = "#F3D398" }
selected = { fg = "#97DC8D", bg = "#97DC8D" }
copied = { fg = "#F3D398", bg = "#F3D398" }
cut = { fg = "#FF84A9", bg = "#FF84A9" }

[preview]
hovered = { underline = true }
Expand Down
7 changes: 4 additions & 3 deletions config/src/theme/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ use serde::{Deserialize, Serialize};
use super::Style;

#[derive(Deserialize, Serialize)]
pub struct Selection {
pub struct Files {
pub hovered: Style,
}

#[derive(Deserialize, Serialize)]
pub struct Marker {
pub selecting: Style,
pub selected: Style,
pub selected: Style,
pub copied: Style,
pub cut: Style,
}
4 changes: 2 additions & 2 deletions config/src/theme/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};
use shared::expand_path;
use validator::Validate;

use super::{Filetype, Icon, Marker, Selection, Status, Style};
use super::{Files, Filetype, Icon, Marker, Status, Style};
use crate::{validation::check_validation, MERGED_THEME};

#[derive(Deserialize, Serialize, Validate)]
Expand All @@ -25,7 +25,7 @@ pub struct Preview {
pub struct Theme {
pub tab: Tab,
pub status: Status,
pub selection: Selection,
pub files: Files,
pub marker: Marker,
pub preview: Preview,
#[serde(rename = "filetype", deserialize_with = "Filetype::deserialize", skip_serializing)]
Expand Down
19 changes: 7 additions & 12 deletions core/src/manager/tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ use super::{Backstack, Finder, FinderCase, Folder, Mode, Preview, PreviewLock};
use crate::{emit, external::{self, FzfOpt, ZoxideOpt}, files::{File, FilesOp, FilesSorter}, input::InputOpt, Event, Step, BLOCKER};

pub struct Tab {
pub(super) mode: Mode,
pub(super) current: Folder,
pub(super) parent: Option<Folder>,
pub mode: Mode,
pub current: Folder,
pub parent: Option<Folder>,

pub(super) backstack: Backstack<Url>,
pub(super) history: BTreeMap<Url, Folder>,
Expand Down Expand Up @@ -453,14 +453,10 @@ impl Tab {
impl Tab {
// --- Mode
#[inline]
pub fn mode(&self) -> &Mode { &self.mode }

#[inline]
pub fn in_selecting(&self) -> bool {
self.mode().is_visual() || self.current.files.has_selected()
}
pub fn in_selecting(&self) -> bool { self.mode.is_visual() || self.current.files.has_selected() }

// --- Current
// TODO: remove this
#[inline]
pub fn name(&self) -> &str {
self
Expand All @@ -473,10 +469,9 @@ impl Tab {
}

pub fn selected(&self) -> Vec<&File> {
let mode = self.mode();
let pending = mode.visual().map(|(_, p)| Cow::Borrowed(p)).unwrap_or_default();
let pending = self.mode.visual().map(|(_, p)| Cow::Borrowed(p)).unwrap_or_default();
let selected = self.current.files.selected(&pending, self.mode.is_unset());

let selected = self.current.files.selected(&pending, mode.is_unset());
if selected.is_empty() {
self.current.hovered.as_ref().map(|h| vec![h]).unwrap_or_default()
} else {
Expand Down
2 changes: 1 addition & 1 deletion cspell.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"language":"en","version":"0.2","flagWords":[],"words":["Punct","KEYMAP","splitn","crossterm","YAZI","unar","peekable","ratatui","syntect","pbpaste","pbcopy","ffmpegthumbnailer","oneshot","Posix","Lsar","XADDOS","zoxide","cands","Deque","precache","imageops","IFBLK","IFCHR","IFDIR","IFIFO","IFLNK","IFMT","IFSOCK","IRGRP","IROTH","IRUSR","ISGID","ISUID","ISVTX","IWGRP","IWOTH","IWUSR","IXGRP","IXOTH","IXUSR","libc","winsize","TIOCGWINSZ","xpixel","ypixel","ioerr","appender","Catppuccin","macchiato","gitmodules","Dotfiles","bashprofile","vimrc","flac","webp","exiftool","mediainfo","ripgrep","nvim","indexmap","indexmap","unwatch","canonicalize","serde","fsevent","Ueberzug","iterm","wezterm","sixel","chafa","ueberzugpp","️ Überzug","️ Überzug","Konsole","Alacritty","Überzug","pkgs","paru","unarchiver","pdftoppm","poppler","prebuild","singlefile","jpegopt","EXIF","rustfmt","mktemp","nanos","xclip","xsel","natord","Mintty","nixos","nixpkgs","SIGTSTP","SIGCONT","SIGCONT","mlua","nonstatic","userdata","metatable","natsort"]}
{"flagWords":[],"words":["Punct","KEYMAP","splitn","crossterm","YAZI","unar","peekable","ratatui","syntect","pbpaste","pbcopy","ffmpegthumbnailer","oneshot","Posix","Lsar","XADDOS","zoxide","cands","Deque","precache","imageops","IFBLK","IFCHR","IFDIR","IFIFO","IFLNK","IFMT","IFSOCK","IRGRP","IROTH","IRUSR","ISGID","ISUID","ISVTX","IWGRP","IWOTH","IWUSR","IXGRP","IXOTH","IXUSR","libc","winsize","TIOCGWINSZ","xpixel","ypixel","ioerr","appender","Catppuccin","macchiato","gitmodules","Dotfiles","bashprofile","vimrc","flac","webp","exiftool","mediainfo","ripgrep","nvim","indexmap","indexmap","unwatch","canonicalize","serde","fsevent","Ueberzug","iterm","wezterm","sixel","chafa","ueberzugpp","️ Überzug","️ Überzug","Konsole","Alacritty","Überzug","pkgs","paru","unarchiver","pdftoppm","poppler","prebuild","singlefile","jpegopt","EXIF","rustfmt","mktemp","nanos","xclip","xsel","natord","Mintty","nixos","nixpkgs","SIGTSTP","SIGCONT","SIGCONT","mlua","nonstatic","userdata","metatable","natsort","backstack","luajit"],"language":"en","version":"0.2"}
2 changes: 1 addition & 1 deletion plugin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ shared = { path = "../shared" }

# External dependencies
anyhow = "^1"
mlua = { version = "^0", features = [ "lua54", "vendored", "serialize" ] }
mlua = { version = "^0", features = [ "luajit52", "vendored", "serialize" ] }
tracing = "^0"
ratatui = "^0"
Loading

0 comments on commit 61c633e

Please sign in to comment.