Better behaviour in the presence of symlinks
This commit is contained in:
parent
6a6bcec4ce
commit
3e8dcdfb11
6 changed files with 26 additions and 28 deletions
|
|
@ -1,4 +1,4 @@
|
|||
use std::{ops::Range, path::Path};
|
||||
use std::ops::Range;
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||
pub enum TokenKind {
|
||||
|
|
@ -58,7 +58,7 @@ impl Highlighter {
|
|||
Self { entries, matchers }
|
||||
}
|
||||
|
||||
pub fn with(mut self, token: TokenKind, p: impl AsRef<str>) -> Self {
|
||||
pub fn with(self, token: TokenKind, p: impl AsRef<str>) -> Self {
|
||||
self.with_many([(token, p)])
|
||||
}
|
||||
|
||||
|
|
@ -74,7 +74,7 @@ impl Highlighter {
|
|||
self
|
||||
}
|
||||
|
||||
fn highlight_str(&self, mut s: &[char]) -> Vec<Token> {
|
||||
fn highlight_str(&self, s: &[char]) -> Vec<Token> {
|
||||
let mut tokens = Vec::new();
|
||||
let mut i = 0;
|
||||
loop {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
use super::*;
|
||||
use crate::highlight::{Highlighter, TokenKind};
|
||||
use std::path::Path;
|
||||
|
||||
|
|
|
|||
|
|
@ -80,11 +80,11 @@ impl<'a> Rect<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn with<R>(&mut self, f: impl FnOnce(&mut Rect) -> R) -> R {
|
||||
pub fn with<R>(&mut self, f: impl FnOnce(&mut Rect<'_>) -> R) -> R {
|
||||
f(self)
|
||||
}
|
||||
|
||||
pub fn rect(&mut self, origin: [usize; 2], size: [usize; 2]) -> Rect {
|
||||
pub fn rect(&mut self, origin: [usize; 2], size: [usize; 2]) -> Rect<'_> {
|
||||
Rect {
|
||||
area: Area {
|
||||
origin: [
|
||||
|
|
@ -103,7 +103,7 @@ impl<'a> Rect<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn with_border(&mut self, theme: &theme::BorderTheme, title: Option<&str>) -> Rect {
|
||||
pub fn with_border(&mut self, theme: &theme::BorderTheme, title: Option<&str>) -> Rect<'_> {
|
||||
let edge = self.size().map(|e| e.saturating_sub(1));
|
||||
for col in 0..edge[0] {
|
||||
self.get_mut([col, 0]).map(|c| {
|
||||
|
|
@ -157,7 +157,7 @@ impl<'a> Rect<'a> {
|
|||
self.rect([1, 1], self.size().map(|e| e.saturating_sub(2)))
|
||||
}
|
||||
|
||||
pub fn with_fg(&mut self, fg: Color) -> Rect {
|
||||
pub fn with_fg(&mut self, fg: Color) -> Rect<'_> {
|
||||
Rect {
|
||||
fg,
|
||||
bg: self.bg,
|
||||
|
|
@ -167,7 +167,7 @@ impl<'a> Rect<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn with_bg(&mut self, bg: Color) -> Rect {
|
||||
pub fn with_bg(&mut self, bg: Color) -> Rect<'_> {
|
||||
Rect {
|
||||
fg: self.fg,
|
||||
bg,
|
||||
|
|
@ -177,7 +177,7 @@ impl<'a> Rect<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn with_focus(&mut self, focus: bool) -> Rect {
|
||||
pub fn with_focus(&mut self, focus: bool) -> Rect<'_> {
|
||||
Rect {
|
||||
fg: self.fg,
|
||||
bg: self.bg,
|
||||
|
|
@ -199,7 +199,7 @@ impl<'a> Rect<'a> {
|
|||
self.area.size.map(|e| e as usize)
|
||||
}
|
||||
|
||||
pub fn fill(&mut self, c: char) -> Rect {
|
||||
pub fn fill(&mut self, c: char) -> Rect<'_> {
|
||||
for row in 0..self.size()[1] {
|
||||
for col in 0..self.size()[0] {
|
||||
let cell = Cell {
|
||||
|
|
@ -215,7 +215,7 @@ impl<'a> Rect<'a> {
|
|||
self.rect([0, 0], self.size())
|
||||
}
|
||||
|
||||
pub fn text(&mut self, origin: [isize; 2], text: &str) -> Rect {
|
||||
pub fn text(&mut self, origin: [isize; 2], text: &str) -> Rect<'_> {
|
||||
for (idx, c) in text.chars().enumerate() {
|
||||
if (0..self.size()[0] as isize).contains(&(origin[0] + idx as isize)) && origin[1] >= 0
|
||||
{
|
||||
|
|
@ -234,7 +234,7 @@ impl<'a> Rect<'a> {
|
|||
self.rect([0, 0], self.size())
|
||||
}
|
||||
|
||||
pub fn set_cursor(&mut self, cursor: [isize; 2], style: CursorStyle) -> Rect {
|
||||
pub fn set_cursor(&mut self, cursor: [isize; 2], style: CursorStyle) -> Rect<'_> {
|
||||
if self.has_focus
|
||||
&& (0..=self.size()[0] as isize).contains(&cursor[0])
|
||||
&& (0..self.size()[1] as isize).contains(&cursor[1])
|
||||
|
|
@ -264,7 +264,7 @@ pub struct Framebuffer {
|
|||
}
|
||||
|
||||
impl Framebuffer {
|
||||
pub fn rect(&mut self) -> Rect {
|
||||
pub fn rect(&mut self) -> Rect<'_> {
|
||||
Rect {
|
||||
fg: Color::Reset,
|
||||
bg: Color::Reset,
|
||||
|
|
|
|||
|
|
@ -1,9 +1,6 @@
|
|||
use super::*;
|
||||
use crate::{
|
||||
state::{Buffer, BufferId, Cursor, CursorId},
|
||||
terminal::CursorStyle,
|
||||
};
|
||||
use std::{collections::HashMap, path::PathBuf};
|
||||
use crate::state::{Buffer, BufferId, Cursor, CursorId};
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub struct Doc {
|
||||
buffer: BufferId,
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ mod status;
|
|||
pub use self::{
|
||||
doc::{Doc, Finder},
|
||||
input::Input,
|
||||
panes::{Pane, Panes},
|
||||
panes::Panes,
|
||||
prompt::{Confirm, Opener, Prompt, Show, Switcher},
|
||||
root::Root,
|
||||
search::Searcher,
|
||||
|
|
@ -64,7 +64,7 @@ impl<End> Resp<End> {
|
|||
pub fn is_end(&self) -> bool {
|
||||
self.ended.is_some()
|
||||
}
|
||||
pub fn into_ended(mut self) -> Option<End> {
|
||||
pub fn into_ended(self) -> Option<End> {
|
||||
self.ended
|
||||
}
|
||||
}
|
||||
|
|
@ -131,7 +131,7 @@ impl<T> Options<T> {
|
|||
pub fn set_options<F: FnMut(&T) -> Option<S>, S: Ord + Copy>(
|
||||
&mut self,
|
||||
options: impl IntoIterator<Item = T>,
|
||||
mut f: F,
|
||||
f: F,
|
||||
) {
|
||||
self.options = options.into_iter().collect();
|
||||
self.apply_scoring(f);
|
||||
|
|
|
|||
|
|
@ -325,11 +325,12 @@ impl Opener {
|
|||
let options = entries
|
||||
.filter_map(|e| e.ok())
|
||||
.filter_map(|entry| {
|
||||
let metadata = fs::metadata(entry.path()).ok()?;
|
||||
Some(FileOption {
|
||||
path: entry.path(),
|
||||
kind: if entry.file_type().ok()?.is_dir() {
|
||||
kind: if metadata.file_type().is_dir() {
|
||||
FileKind::Dir
|
||||
} else if entry.file_type().ok()?.is_file() {
|
||||
} else if metadata.file_type().is_file() {
|
||||
FileKind::File
|
||||
} else {
|
||||
FileKind::Unknown
|
||||
|
|
@ -442,11 +443,12 @@ impl Visual for FileOption {
|
|||
Some(name) => format!("{name}"),
|
||||
None => format!("Unknown"),
|
||||
};
|
||||
let is_link = if self.is_link { " (symlink)" } else { "" };
|
||||
let desc = match self.kind {
|
||||
FileKind::Dir => "Directory",
|
||||
FileKind::Unknown => "Unknown filesystem item",
|
||||
FileKind::File => "File",
|
||||
FileKind::New => "Create new file",
|
||||
FileKind::Dir => format!("Directory{is_link}"),
|
||||
FileKind::Unknown => format!("Unknown{is_link}"),
|
||||
FileKind::File => format!("File{is_link}"),
|
||||
FileKind::New => format!("Create new file{is_link}"),
|
||||
};
|
||||
frame
|
||||
.with_fg(match self.kind {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue