Skip to content

Commit

Permalink
feat: v0.2.0 API
Browse files Browse the repository at this point in the history
  • Loading branch information
sxyazi committed Dec 30, 2023
1 parent 32aa190 commit ccb98ac
Show file tree
Hide file tree
Showing 37 changed files with 319 additions and 305 deletions.
215 changes: 112 additions & 103 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion yazi-adaptor/src/adaptor.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{env, path::Path, sync::Arc};

use anyhow::{anyhow, Result};
use ratatui::prelude::Rect;
use ratatui::layout::Rect;
use tracing::warn;
use yazi_shared::{env_exists, term::Term};

Expand Down
2 changes: 1 addition & 1 deletion yazi-adaptor/src/iterm2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{io::{stdout, BufWriter, Write}, path::Path};
use anyhow::Result;
use base64::{engine::general_purpose, Engine};
use image::{codecs::jpeg::JpegEncoder, DynamicImage};
use ratatui::prelude::Rect;
use ratatui::layout::Rect;
use yazi_shared::term::Term;

use super::image::Image;
Expand Down
2 changes: 1 addition & 1 deletion yazi-adaptor/src/kitty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{io::{stdout, BufWriter, Write}, path::Path};
use anyhow::Result;
use base64::{engine::general_purpose, Engine};
use image::DynamicImage;
use ratatui::prelude::Rect;
use ratatui::layout::Rect;
use yazi_shared::term::Term;

use super::image::Image;
Expand Down
2 changes: 1 addition & 1 deletion yazi-adaptor/src/kitty_old.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{io::{stdout, Write}, path::Path};
use anyhow::Result;
use base64::{engine::general_purpose, Engine};
use image::DynamicImage;
use ratatui::prelude::Rect;
use ratatui::layout::Rect;
use yazi_shared::term::Term;

use super::image::Image;
Expand Down
2 changes: 1 addition & 1 deletion yazi-adaptor/src/sixel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{io::{stdout, BufWriter, Write}, path::Path};
use anyhow::{bail, Result};
use color_quant::NeuQuant;
use image::DynamicImage;
use ratatui::prelude::Rect;
use ratatui::layout::Rect;
use yazi_shared::term::Term;

use crate::{adaptor::Adaptor, Image, CLOSE, ESCAPE, START};
Expand Down
2 changes: 1 addition & 1 deletion yazi-adaptor/src/ueberzug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{path::{Path, PathBuf}, process::Stdio};

use anyhow::{bail, Result};
use imagesize::ImageSize;
use ratatui::prelude::Rect;
use ratatui::layout::Rect;
use tokio::{io::AsyncWriteExt, process::{Child, Command}, sync::mpsc::{self, UnboundedSender}};
use tracing::debug;
use yazi_config::PREVIEW;
Expand Down
24 changes: 12 additions & 12 deletions yazi-config/preset/keymap.toml
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,18 @@ keymap = [
{ on = [ "N" ], exec = "find_arrow --previous", desc = "Go to previous found file" },

# Sorting
{ on = [ ",", "m" ], exec = "sort modified --dir_first", desc = "Sort by modified time" },
{ on = [ ",", "M" ], exec = "sort modified --reverse --dir_first", desc = "Sort by modified time (reverse)" },
{ on = [ ",", "c" ], exec = "sort created --dir_first", desc = "Sort by created time" },
{ on = [ ",", "C" ], exec = "sort created --reverse --dir_first", desc = "Sort by created time (reverse)" },
{ on = [ ",", "e" ], exec = "sort extension --dir_first", desc = "Sort by extension" },
{ on = [ ",", "E" ], exec = "sort extension --reverse --dir_first", desc = "Sort by extension (reverse)" },
{ on = [ ",", "a" ], exec = "sort alphabetical --dir_first", desc = "Sort alphabetically" },
{ on = [ ",", "A" ], exec = "sort alphabetical --reverse --dir_first", desc = "Sort alphabetically (reverse)" },
{ on = [ ",", "n" ], exec = "sort natural --dir_first", desc = "Sort naturally" },
{ on = [ ",", "N" ], exec = "sort natural --reverse --dir_first", desc = "Sort naturally (reverse)" },
{ on = [ ",", "s" ], exec = "sort size --dir_first", desc = "Sort by size" },
{ on = [ ",", "S" ], exec = "sort size --reverse --dir_first", desc = "Sort by size (reverse)" },
{ on = [ ",", "m" ], exec = "sort modified --dir-first", desc = "Sort by modified time" },
{ on = [ ",", "M" ], exec = "sort modified --reverse --dir-first", desc = "Sort by modified time (reverse)" },
{ on = [ ",", "c" ], exec = "sort created --dir-first", desc = "Sort by created time" },
{ on = [ ",", "C" ], exec = "sort created --reverse --dir-first", desc = "Sort by created time (reverse)" },
{ on = [ ",", "e" ], exec = "sort extension --dir-first", desc = "Sort by extension" },
{ on = [ ",", "E" ], exec = "sort extension --reverse --dir-first", desc = "Sort by extension (reverse)" },
{ on = [ ",", "a" ], exec = "sort alphabetical --dir-first", desc = "Sort alphabetically" },
{ on = [ ",", "A" ], exec = "sort alphabetical --reverse --dir-first", desc = "Sort alphabetically (reverse)" },
{ on = [ ",", "n" ], exec = "sort natural --dir-first", desc = "Sort naturally" },
{ on = [ ",", "N" ], exec = "sort natural --reverse --dir-first", desc = "Sort naturally (reverse)" },
{ on = [ ",", "s" ], exec = "sort size --dir-first", desc = "Sort by size" },
{ on = [ ",", "S" ], exec = "sort size --reverse --dir-first", desc = "Sort by size (reverse)" },

# Tabs
{ on = [ "t" ], exec = "tab_create --current", desc = "Create a new tab using the current path" },
Expand Down
2 changes: 1 addition & 1 deletion yazi-config/preset/yazi.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[manager]
layout = [ 1, 4, 3 ]
ratio = [ 1, 4, 3 ]
sort_by = "modified"
sort_sensitive = true
sort_reverse = true
Expand Down
3 changes: 1 addition & 2 deletions yazi-config/src/manager/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ use crate::{validation::check_validation, MERGED_YAZI};

#[derive(Debug, Deserialize, Serialize, Validate)]
pub struct Manager {
// FIXME: rename this to "ratio"
pub layout: ManagerRatio,
pub ratio: ManagerRatio,

// Sorting
pub sort_by: SortBy,
Expand Down
2 changes: 1 addition & 1 deletion yazi-core/src/tab/commands/sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ impl Tab {
}
self.conf.sort_sensitive = e.named.contains_key("sensitive");
self.conf.sort_reverse = e.named.contains_key("reverse");
self.conf.sort_dir_first = e.named.contains_key("dir_first");
self.conf.sort_dir_first = e.named.contains_key("dir-first");

self.apply_files_attrs(false)
}
Expand Down
2 changes: 1 addition & 1 deletion yazi-fm/src/components/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use yazi_plugin::{bindings::Cast, elements::{render_widgets, Rect}, LUA};
pub(crate) struct Status;

impl Widget for Status {
fn render(self, area: ratatui::layout::Rect, buf: &mut ratatui::prelude::Buffer) {
fn render(self, area: ratatui::layout::Rect, buf: &mut ratatui::buffer::Buffer) {
let mut f = || {
let area = Rect::cast(&LUA, area)?;
let comp: Table = LUA.globals().get("Status")?;
Expand Down
2 changes: 1 addition & 1 deletion yazi-fm/src/context.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ratatui::prelude::Rect;
use ratatui::layout::Rect;
use yazi_config::popup::{Origin, Position};
use yazi_core::{completion::Completion, help::Help, input::Input, manager::Manager, select::Select, tasks::Tasks, which::Which};

Expand Down
10 changes: 6 additions & 4 deletions yazi-fm/src/help/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ impl Widget for Bindings<'_> {
.map(|c| ListItem::new(c.desc.as_deref().unwrap_or("-")).style(THEME.help.desc.into()))
.collect::<Vec<_>>();

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

let cursor = self.cx.help.rel_cursor() as u16;
buf.set_style(
Expand Down
7 changes: 3 additions & 4 deletions yazi-fm/src/help/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ impl<'a> Layout<'a> {

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)])
.split(area);
let chunks =
layout::Layout::new(Direction::Vertical, [Constraint::Min(0), Constraint::Length(1)])
.split(area);

widgets::Clear.render(area, buf);

Expand Down
10 changes: 6 additions & 4 deletions yazi-fm/src/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ impl<'a> Root<'a> {

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)])
.split(area);
let chunks = Layout::new(Direction::Vertical, [
Constraint::Length(1),
Constraint::Min(0),
Constraint::Length(1),
])
.split(area);

components::Header.render(chunks[0], buf);
components::Manager.render(chunks[1], buf);
Expand Down
28 changes: 12 additions & 16 deletions yazi-fm/src/tasks/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,19 @@ impl<'a> Layout<'a> {
pub(crate) fn new(cx: &'a Ctx) -> Self { Self { cx } }

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),
])
.split(area)[1];
let chunk = layout::Layout::new(Direction::Vertical, [
Constraint::Percentage((100 - TASKS_PERCENT) / 2),
Constraint::Percentage(TASKS_PERCENT),
Constraint::Percentage((100 - TASKS_PERCENT) / 2),
])
.split(area)[1];

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

Expand Down
10 changes: 6 additions & 4 deletions yazi-fm/src/which/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ impl Widget for Which<'_> {
height,
};

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

widgets::Clear.render(area, buf);
Block::new().style(THEME.which.mask.into()).render(area, buf);
Expand Down
4 changes: 2 additions & 2 deletions yazi-plugin/preset/components/folder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function Folder:linemode(area)
spans[#spans + 1] = ui.Span(" ")
lines[#lines + 1] = ui.Line(spans)
end
return ui.Paragraph(area, lines):align(ui.Alignment.RIGHT)
return ui.Paragraph(area, lines):align(ui.Paragraph.RIGHT)
end

function Folder:markers(area, markers)
Expand All @@ -84,7 +84,7 @@ function Folder:markers(area, markers)
w = 1,
h = 1 + math.min(last[2] - last[1], area.h - y),
},
ui.Position.LEFT
ui.Bar.LEFT
)

if last[3] == 1 then
Expand Down
4 changes: 2 additions & 2 deletions yazi-plugin/preset/components/header.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ function Header:render(area)
self.area = area

local chunks = ui.Layout()
:direction(ui.Direction.HORIZONTAL)
:direction(ui.Layout.HORIZONTAL)
:constraints({ ui.Constraint.Percentage(50), ui.Constraint.Percentage(50) })
:split(area)

local left = ui.Line { self:cwd() }
local right = ui.Line { self:tabs() }
return {
ui.Paragraph(chunks[1], { left }),
ui.Paragraph(chunks[2], { right }):align(ui.Alignment.RIGHT),
ui.Paragraph(chunks[2], { right }):align(ui.Paragraph.RIGHT),
}
end
12 changes: 6 additions & 6 deletions yazi-plugin/preset/components/manager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ function Manager:render(area)
self.area = area

local chunks = ui.Layout()
:direction(ui.Direction.HORIZONTAL)
:direction(ui.Layout.HORIZONTAL)
:constraints({
ui.Constraint.Ratio(MANAGER.layout.parent, MANAGER.layout.all),
ui.Constraint.Ratio(MANAGER.layout.current, MANAGER.layout.all),
ui.Constraint.Ratio(MANAGER.layout.preview, MANAGER.layout.all),
ui.Constraint.Ratio(MANAGER.ratio.parent, MANAGER.ratio.all),
ui.Constraint.Ratio(MANAGER.ratio.current, MANAGER.ratio.all),
ui.Constraint.Ratio(MANAGER.ratio.preview, MANAGER.ratio.all),
})
:split(area)

return ya.flat {
-- Borders
ui.Bar(chunks[1], ui.Position.RIGHT):symbol(THEME.manager.border_symbol):style(THEME.manager.border_style),
ui.Bar(chunks[3], ui.Position.LEFT):symbol(THEME.manager.border_symbol):style(THEME.manager.border_style),
ui.Bar(chunks[1], ui.Bar.RIGHT):symbol(THEME.manager.border_symbol):style(THEME.manager.border_style),
ui.Bar(chunks[3], ui.Bar.LEFT):symbol(THEME.manager.border_symbol):style(THEME.manager.border_style),

-- Parent
Parent:render(chunks[1]:padding(ui.Padding.x(1))),
Expand Down
2 changes: 1 addition & 1 deletion yazi-plugin/preset/components/status.lua
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ function Status:render(area)
local progress = self:progress(area, right:width())
return {
ui.Paragraph(area, { left }),
ui.Paragraph(area, { right }):align(ui.Alignment.RIGHT),
ui.Paragraph(area, { right }):align(ui.Paragraph.RIGHT),
table.unpack(progress),
}
end
2 changes: 1 addition & 1 deletion yazi-plugin/preset/plugins/json.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ local M = {}

function M:peek()
local limit = self.area.h
local child = Command.new("jq")
local child = Command("jq")
:args({
"-C",
"--tab",
Expand Down
2 changes: 1 addition & 1 deletion yazi-plugin/preset/plugins/mime.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local M = {}

function M:preload()
local command = Command.new("file"):arg("--mime-type"):stdout(Command.PIPED):stderr(Command.PIPED)
local command = Command("file"):arg("--mime-type"):stdout(Command.PIPED):stderr(Command.PIPED)
if ya.target_family() == "windows" then
command:arg("-b")
else
Expand Down
2 changes: 1 addition & 1 deletion yazi-plugin/preset/plugins/pdf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function M:preload()
return 1
end

local output = Command.new("pdftoppm")
local output = Command("pdftoppm")
:args({ "-singlefile", "-jpeg", "-jpegopt", "quality=75", "-f", tostring(self.skip + 1), tostring(self.file.url) })
:stdout(Command.PIPED)
:stderr(Command.PIPED)
Expand Down
2 changes: 1 addition & 1 deletion yazi-plugin/preset/plugins/video.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function M:preload()
return 1
end

local status = Command.new("ffmpegthumbnailer")
local status = Command("ffmpegthumbnailer")
:args({
"-q",
"6",
Expand Down
21 changes: 1 addition & 20 deletions yazi-plugin/preset/ui.lua
Original file line number Diff line number Diff line change
@@ -1,23 +1,4 @@
ui = {
-- FIXME: merge those three into their own modules
Alignment = {
LEFT = 0,
CENTER = 1,
RIGHT = 2,
},
Direction = {
HORIZONTAL = false,
VERTICAL = true,
},
Position = {
NONE = 0,
TOP = 1,
RIGHT = 2,
BOTTOM = 4,
LEFT = 8,
ALL = 15,
},
}
ui = {}

function ui.highlight_ranges(s, ranges)
if ranges == nil or #ranges == 0 then
Expand Down
Loading

0 comments on commit ccb98ac

Please sign in to comment.