mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
Merge branch 'main' of https://github.com/sxyazi/yazi
This commit is contained in:
commit
ecb21c14fa
4 changed files with 18 additions and 8 deletions
|
|
@ -19,11 +19,11 @@ impl<'a> Widget for Layout<'a> {
|
||||||
.constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref())
|
.constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref())
|
||||||
.split(area);
|
.split(area);
|
||||||
|
|
||||||
let current = &self.cx.manager.current();
|
let cwd = &self.cx.manager.current().cwd;
|
||||||
let location = if current.cwd.is_search() {
|
let location = if cwd.is_search() {
|
||||||
format!("{} (search)", readable_path(¤t.cwd))
|
format!("{} (search: {})", readable_path(cwd), cwd.frag().unwrap())
|
||||||
} else {
|
} else {
|
||||||
readable_path(¤t.cwd)
|
readable_path(cwd)
|
||||||
};
|
};
|
||||||
|
|
||||||
Paragraph::new(location).style(Style::new().fg(Color::Cyan)).render(chunks[0], buf);
|
Paragraph::new(location).style(Style::new().fg(Color::Cyan)).render(chunks[0], buf);
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ use std::{io::BufRead, path::Path, sync::atomic::{AtomicUsize, Ordering}};
|
||||||
use adaptor::ADAPTOR;
|
use adaptor::ADAPTOR;
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use config::{MANAGER, PREVIEW};
|
use config::{MANAGER, PREVIEW};
|
||||||
|
use futures::TryFutureExt;
|
||||||
use shared::{MimeKind, PeekError};
|
use shared::{MimeKind, PeekError};
|
||||||
use syntect::{easy::HighlightFile, util::as_24_bit_terminal_escaped};
|
use syntect::{easy::HighlightFile, util::as_24_bit_terminal_escaped};
|
||||||
use tokio::fs;
|
use tokio::fs;
|
||||||
|
|
@ -69,7 +70,9 @@ impl Provider {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn json(path: &Path, skip: usize) -> Result<String, PeekError> {
|
pub(super) async fn json(path: &Path, skip: usize) -> Result<String, PeekError> {
|
||||||
external::jq(path, skip, MANAGER.layout.preview_height()).await
|
external::jq(path, skip, MANAGER.layout.preview_height())
|
||||||
|
.or_else(|_| Provider::highlight(path, skip))
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn archive(path: &Path, skip: usize) -> Result<String, PeekError> {
|
pub(super) async fn archive(path: &Path, skip: usize) -> Result<String, PeekError> {
|
||||||
|
|
|
||||||
|
|
@ -289,7 +289,7 @@ impl Tab {
|
||||||
handle.abort();
|
handle.abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
let cwd = self.current.cwd.to_search();
|
let mut cwd = self.current.cwd.clone();
|
||||||
let hidden = self.show_hidden;
|
let hidden = self.show_hidden;
|
||||||
|
|
||||||
self.search = Some(tokio::spawn(async move {
|
self.search = Some(tokio::spawn(async move {
|
||||||
|
|
@ -297,6 +297,7 @@ impl Tab {
|
||||||
bail!("canceled")
|
bail!("canceled")
|
||||||
};
|
};
|
||||||
|
|
||||||
|
cwd = cwd.into_search(subject.clone());
|
||||||
let rx = if grep {
|
let rx = if grep {
|
||||||
external::rg(external::RgOpt { cwd: cwd.clone(), hidden, subject })
|
external::rg(external::RgOpt { cwd: cwd.clone(), hidden, subject })
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ use std::{ffi::{OsStr, OsString}, fmt::{Debug, Formatter}, ops::{Deref, DerefMut
|
||||||
pub struct Url {
|
pub struct Url {
|
||||||
scheme: UrlScheme,
|
scheme: UrlScheme,
|
||||||
path: PathBuf,
|
path: PathBuf,
|
||||||
|
frag: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
|
#[derive(Clone, Copy, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
|
||||||
|
|
@ -114,11 +115,12 @@ impl Url {
|
||||||
pub fn is_search(&self) -> bool { self.scheme == UrlScheme::Search }
|
pub fn is_search(&self) -> bool { self.scheme == UrlScheme::Search }
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn to_search(&self) -> Self { self.clone().into_search() }
|
pub fn to_search(&self, frag: String) -> Self { self.clone().into_search(frag) }
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn into_search(mut self) -> Self {
|
pub fn into_search(mut self, frag: String) -> Self {
|
||||||
self.scheme = UrlScheme::Search;
|
self.scheme = UrlScheme::Search;
|
||||||
|
self.frag = Some(frag);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -137,4 +139,8 @@ impl Url {
|
||||||
// --- Path
|
// --- Path
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn set_path(&mut self, path: PathBuf) { self.path = path; }
|
pub fn set_path(&mut self, path: PathBuf) { self.path = path; }
|
||||||
|
|
||||||
|
// --- Frag
|
||||||
|
#[inline]
|
||||||
|
pub fn frag(&self) -> Option<&str> { self.frag.as_deref() }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue