Fix everything @sayanarijit fed back.

pull/395/head
Tom van Dijk 3 years ago committed by Arijit Basu
parent cbb244f9a0
commit 3c8de699ca

1
Cargo.lock generated

@ -1107,7 +1107,6 @@ dependencies = [
"ansi-to-tui",
"anyhow",
"assert_cmd",
"atty",
"chrono",
"criterion",
"crossterm 0.22.1",

@ -34,7 +34,6 @@ humansize = "1.1.1"
mlua = { version = "0.6.6", features = ["luajit", "vendored", "serialize", "send"] }
ansi-to-tui = "0.4.1"
libc = "0.2.105"
atty = "0.2.14"
[dev-dependencies]
criterion = "0.3.5"
@ -50,3 +49,5 @@ path = "./benches/criterion.rs"
lto = true
codegen-units = 1
panic = 'abort'
[features]

@ -2058,14 +2058,14 @@ impl App {
Ok(self)
}
fn select(mut self) -> Result<Self> {
pub fn select(mut self) -> Result<Self> {
if let Some(n) = self.focused_node().map(|n| n.to_owned()) {
self.selection.insert(n);
}
Ok(self)
}
fn select_path(mut self, path: String) -> Result<Self> {
pub fn select_path(mut self, path: String) -> Result<Self> {
let mut path = PathBuf::from(path);
if path.is_relative() {
path = PathBuf::from(self.pwd.clone()).join(path);
@ -2078,7 +2078,7 @@ impl App {
Ok(self)
}
fn select_all(mut self) -> Result<Self> {
pub fn select_all(mut self) -> Result<Self> {
if let Some(d) = self.directory_buffer.as_ref() {
d.nodes.clone().into_iter().for_each(|n| {
self.selection.insert(n);
@ -2088,14 +2088,14 @@ impl App {
Ok(self)
}
fn un_select(mut self) -> Result<Self> {
pub fn un_select(mut self) -> Result<Self> {
if let Some(n) = self.focused_node().map(|n| n.to_owned()) {
self.selection.retain(|s| s != &n);
}
Ok(self)
}
fn un_select_path(mut self, path: String) -> Result<Self> {
pub fn un_select_path(mut self, path: String) -> Result<Self> {
let mut pathbuf = PathBuf::from(path);
if pathbuf.is_relative() {
pathbuf = PathBuf::from(self.pwd.clone()).join(pathbuf);
@ -2105,7 +2105,7 @@ impl App {
Ok(self)
}
fn un_select_all(mut self) -> Result<Self> {
pub fn un_select_all(mut self) -> Result<Self> {
if let Some(d) = self.directory_buffer.as_ref() {
d.nodes.clone().into_iter().for_each(|n| {
self.selection.retain(|s| s != &n);

@ -27,7 +27,7 @@ fn main() {
"$HOME/.config/xplr/init.lua")
-C, --extra-config <PATH>... Specifies extra config files to load
--on-load <MESSAGE>... Sends messages when xplr loads
--select <FILE> Selects all entries in a given file."###;
--select <FILE> Selects the given paths."###;
let args = r###"
<PATH> Path to focus on, or enter if directory"###;

@ -15,7 +15,7 @@ pub struct Cli {
pub config: Option<PathBuf>,
pub extra_config: Vec<PathBuf>,
pub on_load: Vec<app::ExternalMsg>,
pub select_file: Option<PathBuf>,
pub select: Vec<PathBuf>,
}
impl Cli {
@ -77,8 +77,13 @@ impl Cli {
}
}
"--select" => {
if cli.select_file.is_none() {
cli.select_file = args.pop_front().map(PathBuf::from);
while let Some(path) = args.pop_front() {
if path.starts_with('-') && path != "-" {
args.push_front(path);
break;
} else {
cli.select.push(PathBuf::from(path));
}
}
}

@ -14,7 +14,6 @@ use crossterm::execute;
use crossterm::terminal as term;
use mlua::LuaSerdeExt;
use std::fs;
use std::fs::File;
use std::io;
use std::io::BufRead;
use std::io::BufReader;
@ -105,20 +104,6 @@ fn start_fifo(path: &str, focus_path: &str) -> Result<fs::File> {
}
}
fn process_lines<R: std::io::Read>(
lines: BufReader<R>,
tx_msg_in: &mpsc::Sender<app::Task>,
) -> Result<()> {
for line in lines.lines() {
let line = line?;
tx_msg_in.send(app::Task::new(
app::MsgIn::External(app::ExternalMsg::SelectPath(line)),
None,
))?;
}
Ok(())
}
pub struct Runner {
pwd: PathBuf,
focused_path: Option<PathBuf>,
@ -126,7 +111,7 @@ pub struct Runner {
extra_config_files: Vec<PathBuf>,
on_load: Vec<app::ExternalMsg>,
read_only: bool,
select_file: Option<PathBuf>,
select: Vec<PathBuf>,
}
impl Runner {
@ -156,7 +141,7 @@ impl Runner {
extra_config_files: cli.extra_config,
on_load: cli.on_load,
read_only: cli.read_only,
select_file: cli.select_file,
select: cli.select,
})
}
@ -241,24 +226,15 @@ impl Runner {
tx_msg_in.send(app::Task::new(app::MsgIn::External(msg), None))?;
}
// Select all files in the select file
if let Some(f) = self.select_file {
let is_stdin = f.as_os_str() == "-";
if !f.is_file() && !is_stdin {
app = app.log_error(format!(
"Could not find your select file: {}",
f.to_string_lossy()
))?;
}
if is_stdin {
if atty::isnt(atty::Stream::Stdin) {
let lines = BufReader::new(std::io::stdin());
process_lines(lines, &tx_msg_in)?;
// Select all files in our selection vector.
for file in self.select.iter() {
if file.as_os_str() == "-" {
for x in BufReader::new(std::io::stdin()).lines() {
app = app.select_path(x?)?;
}
} else {
let lines = BufReader::new(File::open(f)?);
process_lines(lines, &tx_msg_in)?;
};
app = app.select_path(file.to_string_lossy().to_string())?;
}
}
'outer: for task in rx_msg_in {

Loading…
Cancel
Save