Merge branch 'sxyazi:main' into main

This commit is contained in:
Yifan Song 2023-08-12 16:38:08 +08:00 committed by GitHub
commit eccc1a3f95
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 108 additions and 30 deletions

1
Cargo.lock generated
View file

@ -134,6 +134,7 @@ dependencies = [
"tracing",
"tracing-appender",
"tracing-subscriber",
"unicode-width",
]
[[package]]

View file

@ -10,17 +10,19 @@ https://github.com/sxyazi/yazi/assets/17523360/740a41f4-3d24-4287-952c-3aec51520
Before getting started, ensure that the following dependencies are installed on your system:
- nerd-fonts (required, for icons)
- ffmpegthumbnailer (optional, for video thumbnails)
- unar (optional, for archive preview)
- jq (optional, for JSON preview)
- poppler (optional, for PDF preview)
- fd (optional, for file searching)
- rg (optional, for file content searching)
- fzf (optional, for directory jumping)
- zoxide (optional, for directory jumping)
- nerd-fonts (_required_, for icons)
- ffmpegthumbnailer (_optional_, for video thumbnails)
- unar (_optional_, for archive preview)
- jq (_optional_, for JSON preview)
- poppler (_optional_, for PDF preview)
- fd (_optional_, for file searching)
- rg (_optional_, for file content searching)
- fzf (_optional_, for directory jumping)
- zoxide (_optional_, for directory jumping)
### Arch Linux
<details>
<summary>Arch Linux</summary>
Install with paru or your favorite AUR helper:
@ -30,7 +32,11 @@ paru -S yazi ffmpegthumbnailer unarchiver jq poppler fd ripgrep fzf zoxide
Or, you can replace `yazi` with `yazi-bin` package if you want pre-built binary instead of compiling by yourself.
### macOS
</details>
<details>
<summary>macOS</summary>
Install the dependencies with Homebrew:
@ -45,7 +51,11 @@ And download the latest release [from here](https://github.com/sxyazi/yazi/relea
cargo install --git https://github.com/sxyazi/yazi.git
```
### Nix
</details>
<details>
<summary>Nix</summary>
Nix users can install Yazi from [the NUR](https://github.com/nix-community/nur-combined/blob/master/repos/xyenon/pkgs/yazi/default.nix):
@ -64,7 +74,11 @@ environment.systemPackages = with pkgs; [
If you prefer to use the most recent code, use `nur.repos.xyenon.yazi-unstable` instead.
### Build from source
</details>
<details>
<summary>Build from source</summary>
Execute the following commands to clone the project and build Yazi:
@ -80,6 +94,8 @@ Then, you can run:
./target/release/yazi
```
</details>
## Usage
```bash
@ -88,11 +104,11 @@ yazi
If you want to use your own config, copy the [config folder](https://github.com/sxyazi/yazi/tree/main/config/preset) to `~/.config/yazi`, and modify it as you like.
There is a wrapper of yazi that provides the ability to change the current shell's working directory when yazi exited, feel free to use it:
There is a wrapper of yazi, that provides the ability to change the current working directory when yazi exiting, feel free to use it:
```bash
function ya() {
tmp="$(mktemp -t "yazi-cwd")"
tmp="$(mktemp -t "yazi-cwd.XXXXX")"
yazi --cwd-file="$tmp"
if cwd="$(cat -- "$tmp")" && [ -n "$cwd" ] && [ "$cwd" != "$PWD" ]; then
cd -- "$cwd"
@ -101,6 +117,11 @@ function ya() {
}
```
## Discussion
- Discord Server (English mainly): https://discord.gg/qfADduSdJu
- Telegram Group (Chinese mainly): https://t.me/yazi_rs
## Image Preview
| Platform | Protocol | Support |
@ -120,11 +141,6 @@ That's relying on the `$TERM`, `$TERM_PROGRAM`, and `$XDG_SESSION_TYPE` variable
For instance, if your terminal is Alacritty, which doesn't support displaying images itself, but you are running on an X11/Wayland environment,
it will automatically use the "Window system protocol" to display images -- this requires you to have [Überzug++](https://github.com/jstkdng/ueberzugpp) installed.
## Discussion
- Discord Server (English mainly): https://discord.gg/qfADduSdJu
- Telegram Group (Chinese mainly): https://t.me/yazi_rs
## TODO
- [x] Add example config for general usage, currently please see my [another repo](https://github.com/sxyazi/dotfiles/tree/main/yazi) instead

View file

@ -18,6 +18,7 @@ libc = "^0"
ratatui = "^0"
signal-hook-tokio = { version = "^0", features = [ "futures-v0_3" ] }
tokio = { version = "^1", features = [ "parking_lot" ] }
unicode-width = "^0"
# Logging
tracing = "^0"

View file

@ -67,8 +67,12 @@ impl Executor {
"forward" => cx.manager.active_mut().forward(),
"cd" => {
let path = exec.args.get(0).map(PathBuf::from).unwrap_or_default();
emit!(Cd(path));
false
if exec.named.contains_key("interactive") {
cx.manager.active_mut().cd_interactive(path)
} else {
emit!(Cd(path));
false
}
}
// Selection

View file

@ -1,5 +1,8 @@
use std::ops::ControlFlow;
use config::THEME;
use ratatui::{buffer::Buffer, layout::{Alignment, Rect}, text::{Line, Span}, widgets::{Paragraph, Widget}};
use unicode_width::UnicodeWidthStr;
use crate::Ctx;
@ -19,11 +22,31 @@ impl<'a> Widget for Tabs<'a> {
tabs
.iter()
.enumerate()
.map(|(i, _)| {
.map(|(i, tab)| {
let mut text = format!("{}", i + 1);
if let Some(dir_name) = tab.current_name() {
text.push(' ');
text.push_str(dir_name);
}
let threshold = THEME.tab.max_width.max(1);
let truncated = text.chars().try_fold(String::with_capacity(threshold), |mut text, c| {
if text.width() > threshold {
ControlFlow::Break(text)
} else {
text.push(c);
ControlFlow::Continue(text)
}
});
let text = match truncated {
ControlFlow::Break(text) => text,
ControlFlow::Continue(text) => text,
};
if i == tabs.idx() {
Span::styled(format!(" {} ", i + 1), THEME.tab.active.get())
Span::styled(format!(" {text} "), THEME.tab.active.get())
} else {
Span::styled(format!(" {} ", i + 1), THEME.tab.inactive.get())
Span::styled(format!(" {text} "), THEME.tab.inactive.get())
}
})
.collect::<Vec<_>>(),

View file

@ -97,6 +97,7 @@ keymap = [
{ on = [ "g", "c" ], exec = "cd ~/.config" },
{ on = [ "g", "d" ], exec = "cd ~/Downloads" },
{ on = [ "g", "t" ], exec = "cd /tmp" },
{ on = [ "g", "<Space>" ], exec = "cd --interactive" },
]
[tasks]

View file

@ -1,6 +1,7 @@
[tab]
active = { fg = "#1E2031", bg = "#80AEFA" }
inactive = { fg = "#C8D3F8", bg = "#484D66" }
active = { fg = "#1E2031", bg = "#80AEFA" }
inactive = { fg = "#C8D3F8", bg = "#484D66" }
max_width = 1
[status]
primary = { normal = "#80AEFA", select = "#CD9EFC", unset = "#FFA577" }

View file

@ -8,8 +8,9 @@ use crate::MERGED_THEME;
#[derive(Deserialize)]
pub struct Tab {
pub active: Style,
pub inactive: Style,
pub active: Style,
pub inactive: Style,
pub max_width: usize,
}
#[derive(Deserialize)]

View file

@ -7,13 +7,22 @@ use tokio::fs;
use super::File;
#[derive(Default)]
pub struct Files {
items: IndexMap<PathBuf, File>,
pub sort: FilesSort,
pub show_hidden: bool,
}
impl Default for Files {
fn default() -> Self {
Self {
items: Default::default(),
sort: Default::default(),
show_hidden: MANAGER.show_hidden,
}
}
}
impl Files {
pub async fn read(paths: Vec<PathBuf>) -> BTreeMap<PathBuf, File> {
let mut items = BTreeMap::new();

View file

@ -115,6 +115,18 @@ impl Tab {
true
}
pub fn cd_interactive(&mut self, target: PathBuf) -> bool {
tokio::spawn(async move {
let result =
emit!(Input(InputOpt::top("Change directory:").with_value(target.to_string_lossy())));
if let Ok(target) = result.await {
emit!(Cd(PathBuf::from(target)));
}
});
false
}
pub fn enter(&mut self) -> bool {
let hovered = if let Some(ref h) = self.current.hovered {
h.clone()
@ -258,6 +270,15 @@ impl Tab {
};
true
}
pub fn current_name(&self) -> Option<&str> {
self
.current
.cwd
.file_name()
.and_then(|name| name.to_str())
.or_else(|| self.current.cwd.to_str())
}
}
impl Tab {