Skip to content

Commit

Permalink
Rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
sxyazi committed Aug 10, 2024
1 parent cf5d9d2 commit d3d9cf6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 59 deletions.
2 changes: 1 addition & 1 deletion cspell.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"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","Succ","Succ","cand","fileencoding","foldmethod","lightgreen","darkgray","lightred","lightyellow","lightcyan","nushell","msvc","aarch","linemode","sxyazi","rsplit","ZELLIJ","bitflags","bitflags","USERPROFILE","Neovim","vergen","gitcl","Renderable","preloaders","prec","imagesize","Upserting","prio","Ghostty","Catmull","Lanczos","cmds","unyank","scrolloff","headsup","unsub","uzers","scopeguard","SPDLOG","globset","filetime","magick","magick","prefetcher","Prework","prefetchers","PREWORKERS","conds","translit","rxvt","Urxvt","realpath","realname","REPARSE","hardlink","hardlinking","nlink","nlink","linemodes","SIGSTOP","sevenzip","rsplitn","replacen","DECSET","DECRQM","repeek"],"version":"0.2","language":"en","flagWords":[]}
{"language":"en","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","Succ","Succ","cand","fileencoding","foldmethod","lightgreen","darkgray","lightred","lightyellow","lightcyan","nushell","msvc","aarch","linemode","sxyazi","rsplit","ZELLIJ","bitflags","bitflags","USERPROFILE","Neovim","vergen","gitcl","Renderable","preloaders","prec","imagesize","Upserting","prio","Ghostty","Catmull","Lanczos","cmds","unyank","scrolloff","headsup","unsub","uzers","scopeguard","SPDLOG","globset","filetime","magick","magick","prefetcher","Prework","prefetchers","PREWORKERS","conds","translit","rxvt","Urxvt","realpath","realname","REPARSE","hardlink","hardlinking","nlink","nlink","linemodes","SIGSTOP","sevenzip","rsplitn","replacen","DECSET","DECRQM","repeek","cwds"],"version":"0.2"}
64 changes: 14 additions & 50 deletions yazi-boot/src/boot.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::{collections::HashSet, ffi::OsString, path::{Path, PathBuf}};
use std::{collections::HashSet, ffi::OsString, path::PathBuf};

use serde::Serialize;
use yazi_shared::{fs::{current_cwd, expand_path}, Xdg};

#[derive(Debug, Default, Serialize)]
pub struct Boot {
pub cwds: Vec<PathBuf>,
pub files: Vec<Option<OsString>>,
pub files: Vec<OsString>,

pub local_events: HashSet<String>,
pub remote_events: HashSet<String>,
Expand All @@ -18,22 +18,20 @@ pub struct Boot {
}

impl Boot {
fn parse_entries(entries: Vec<&Path>) -> (Vec<PathBuf>, Vec<Option<OsString>>) {
if entries.len() == 0 {
return (vec![current_cwd().unwrap()], vec![None]);
fn parse_entries(entries: &[PathBuf]) -> (Vec<PathBuf>, Vec<OsString>) {
if entries.is_empty() {
return (vec![current_cwd().unwrap()], vec![OsString::new()]);
}

let mut cwds = vec![];
let mut files = vec![];
for entry in entries {
let _entry = expand_path(entry);
let parent = _entry.parent();
if parent.is_none() || _entry.is_dir() {
cwds.push(_entry);
files.push(None);
let mut cwds = Vec::with_capacity(entries.len());
let mut files = Vec::with_capacity(entries.len());
for entry in entries.iter().map(expand_path) {
if let Some(p) = entry.parent().filter(|_| !entry.is_dir()) {
cwds.push(p.to_owned());
files.push(entry.file_name().unwrap().to_owned());
} else {
cwds.push(parent.unwrap().to_owned());
files.push(Some(_entry.file_name().unwrap().to_owned()));
cwds.push(entry);
files.push(OsString::new());
}
}

Expand All @@ -44,8 +42,7 @@ impl Boot {
impl From<&crate::Args> for Boot {
fn from(args: &crate::Args) -> Self {
let config_dir = Xdg::config_dir();
let entries = args.entries.iter().map(PathBuf::as_path).collect();
let (cwds, files) = Self::parse_entries(entries);
let (cwds, files) = Self::parse_entries(&args.entries);

let local_events = args
.local_events
Expand All @@ -72,36 +69,3 @@ impl From<&crate::Args> for Boot {
}
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_parse_entries() {
use std::{env::temp_dir, fs};

let foo_dir = temp_dir().join(&Path::new("foo"));
let bar_dir = temp_dir().join(&Path::new("bar"));
let poem_path = &foo_dir.join(&Path::new("poem.txt"));

let _ = fs::create_dir_all(&foo_dir);
let _ = fs::create_dir_all(&bar_dir);
let _ =
fs::OpenOptions::new().create(true).write(true).open(foo_dir.join(&Path::new("poem.txt")));

assert_eq!(Boot::parse_entries(vec![]), (vec![current_cwd().unwrap()], vec![None]));
assert_eq!(Boot::parse_entries(vec![&foo_dir]), (vec![foo_dir.clone()], vec![None]));
assert_eq!(
Boot::parse_entries(vec![&poem_path]),
(vec![foo_dir.clone()], vec![Some(OsString::from("poem.txt"))])
);
assert_eq!(
Boot::parse_entries(vec![&foo_dir, &bar_dir]),
(vec![foo_dir.clone(), bar_dir.clone()], vec![None, None])
);

let _ = fs::remove_dir_all(&foo_dir);
let _ = fs::remove_dir_all(&bar_dir);
}
}
17 changes: 9 additions & 8 deletions yazi-core/src/manager/tabs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@ pub struct Tabs {

impl Tabs {
pub fn make() -> Self {
let mut tabs = Self { cursor: 0, items: vec![] };
for (i, file) in BOOT.files.iter().enumerate() {
let mut tab = Tab::default();
if let Some(f) = file {
tab.reveal(Url::from(BOOT.cwds[i].join(f)));
} else {
let mut tabs =
Self { cursor: 0, items: (0..BOOT.cwds.len()).map(|_| Tab::default()).collect() };
tabs.reorder();

for (i, tab) in tabs.iter_mut().enumerate() {
let file = &BOOT.files[i];
if file.is_empty() {
tab.cd(Url::from(&BOOT.cwds[i]));
} else {
tab.reveal(Url::from(BOOT.cwds[i].join(file)));
}
tabs.push(tab);
}

tabs
}

Expand Down

0 comments on commit d3d9cf6

Please sign in to comment.