Rename selected -> selection

pull/3/head
Arijit Basu 3 years ago
parent b70682ecb5
commit 8a6da63936
No known key found for this signature in database
GPG Key ID: 7D7BF809E7378863

2
Cargo.lock generated

@ -1117,7 +1117,7 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]] [[package]]
name = "xplr" name = "xplr"
version = "0.2.5" version = "0.2.6"
dependencies = [ dependencies = [
"criterion", "criterion",
"crossterm", "crossterm",

@ -1,6 +1,6 @@
[package] [package]
name = "xplr" name = "xplr"
version = "0.2.5" # Update app.rs version = "0.2.6" # Update app.rs
authors = ["Arijit Basu <sayanarijit@gmail.com>"] authors = ["Arijit Basu <sayanarijit@gmail.com>"]
edition = "2018" edition = "2018"
description = "An experimental, minimal, configurable TUI file explorer, stealing ideas from nnn and fzf." description = "An experimental, minimal, configurable TUI file explorer, stealing ideas from nnn and fzf."

@ -11,7 +11,7 @@ use std::collections::VecDeque;
use std::fs; use std::fs;
use std::path::PathBuf; use std::path::PathBuf;
pub const VERSION: &str = "v0.2.5"; // Update Cargo.toml pub const VERSION: &str = "v0.2.6"; // Update Cargo.toml
pub const TEMPLATE_TABLE_ROW: &str = "TEMPLATE_TABLE_ROW"; pub const TEMPLATE_TABLE_ROW: &str = "TEMPLATE_TABLE_ROW";
@ -21,7 +21,7 @@ pub const UNSUPPORTED_STR: &str = "???";
pub struct PipesConfig { pub struct PipesConfig {
pub msg_in: String, pub msg_in: String,
pub focus_out: String, pub focus_out: String,
pub selected_out: String, pub selection_out: String,
pub mode_out: String, pub mode_out: String,
} }
@ -35,19 +35,19 @@ impl PipesConfig {
let focus_out = pipesdir.join("focus_out").to_string_lossy().to_string(); let focus_out = pipesdir.join("focus_out").to_string_lossy().to_string();
let selected_out = pipesdir.join("selected_out").to_string_lossy().to_string(); let selection_out = pipesdir.join("selection_out").to_string_lossy().to_string();
let mode_out = pipesdir.join("mode_out").to_string_lossy().to_string(); let mode_out = pipesdir.join("mode_out").to_string_lossy().to_string();
fs::write(&msg_in, "").unwrap(); fs::write(&msg_in, "").unwrap();
fs::write(&focus_out, "").unwrap(); fs::write(&focus_out, "").unwrap();
fs::write(&selected_out, "").unwrap(); fs::write(&selection_out, "").unwrap();
fs::write(&mode_out, "").unwrap(); fs::write(&mode_out, "").unwrap();
Self { Self {
msg_in, msg_in,
focus_out, focus_out,
selected_out, selection_out,
mode_out, mode_out,
} }
} }
@ -248,7 +248,7 @@ pub struct App {
pwd: String, pwd: String,
directory_buffers: HashMap<String, DirectoryBuffer>, directory_buffers: HashMap<String, DirectoryBuffer>,
tasks: BinaryHeap<Task>, tasks: BinaryHeap<Task>,
selected: Vec<Node>, selection: Vec<Node>,
msg_out: VecDeque<MsgOut>, msg_out: VecDeque<MsgOut>,
mode: Mode, mode: Mode,
input_buffer: Option<String>, input_buffer: Option<String>,
@ -284,7 +284,7 @@ impl App {
pwd, pwd,
directory_buffers: Default::default(), directory_buffers: Default::default(),
tasks: Default::default(), tasks: Default::default(),
selected: Default::default(), selection: Default::default(),
msg_out: Default::default(), msg_out: Default::default(),
mode, mode,
input_buffer: Default::default(), input_buffer: Default::default(),
@ -582,16 +582,16 @@ impl App {
self.clone() self.clone()
.focused_node() .focused_node()
.map(|n| { .map(|n| {
if self.selected().contains(n) { if self.selection().contains(n) {
self.selected = self self.selection = self
.clone() .clone()
.selected .selection
.into_iter() .into_iter()
.filter(|s| s != n) .filter(|s| s != n)
.collect(); .collect();
Ok(self.clone()) Ok(self.clone())
} else { } else {
self.selected.push(n.to_owned()); self.selection.push(n.to_owned());
Ok(self.clone()) Ok(self.clone())
} }
}) })
@ -632,9 +632,9 @@ impl App {
&self.config &self.config
} }
/// Get a reference to the app's selected. /// Get a reference to the app's selection.
pub fn selected(&self) -> &Vec<Node> { pub fn selection(&self) -> &Vec<Node> {
&self.selected &self.selection
} }
pub fn pop_msg_out(&mut self) -> Option<MsgOut> { pub fn pop_msg_out(&mut self) -> Option<MsgOut> {

@ -138,12 +138,12 @@ fn main() -> Result<(), Error> {
} }
app::MsgOut::PrintResultAndQuit => { app::MsgOut::PrintResultAndQuit => {
let out = if app.selected().is_empty() { let out = if app.selection().is_empty() {
app.focused_node() app.focused_node()
.map(|n| n.absolute_path.clone()) .map(|n| n.absolute_path.clone())
.unwrap_or_default() .unwrap_or_default()
} else { } else {
app.selected() app.selection()
.into_iter() .into_iter()
.map(|n| n.absolute_path.clone()) .map(|n| n.absolute_path.clone())
.collect::<Vec<String>>() .collect::<Vec<String>>()
@ -184,14 +184,14 @@ fn main() -> Result<(), Error> {
fs::write(&app.pipes().focus_out, focused).unwrap(); fs::write(&app.pipes().focus_out, focused).unwrap();
let selected = app let selection = app
.selected() .selection()
.iter() .iter()
.map(|n| n.absolute_path.clone()) .map(|n| n.absolute_path.clone())
.collect::<Vec<String>>() .collect::<Vec<String>>()
.join("\n"); .join("\n");
fs::write(&app.pipes().selected_out, selected).unwrap(); fs::write(&app.pipes().selection_out, selection).unwrap();
fs::write(&app.pipes().mode_out, &app.mode().name).unwrap(); fs::write(&app.pipes().mode_out, &app.mode().name).unwrap();
} }
@ -217,8 +217,8 @@ fn main() -> Result<(), Error> {
.unwrap_or_default() .unwrap_or_default()
.to_string(); .to_string();
let selected = app let selection = app
.selected() .selection()
.iter() .iter()
.map(|n| n.absolute_path.clone()) .map(|n| n.absolute_path.clone())
.collect::<Vec<String>>() .collect::<Vec<String>>()
@ -237,7 +237,7 @@ fn main() -> Result<(), Error> {
let pipe_msg_in = app.pipes().msg_in.clone(); let pipe_msg_in = app.pipes().msg_in.clone();
let pipe_focus_out = app.pipes().focus_out.clone(); let pipe_focus_out = app.pipes().focus_out.clone();
let pipe_selected_out = app.pipes().selected_out.clone(); let pipe_selection_out = app.pipes().selection_out.clone();
let app_yaml = serde_yaml::to_string(&app).unwrap_or_default(); let app_yaml = serde_yaml::to_string(&app).unwrap_or_default();
@ -247,10 +247,10 @@ fn main() -> Result<(), Error> {
.env("XPLR_INPUT_BUFFER", input_buffer) .env("XPLR_INPUT_BUFFER", input_buffer)
.env("XPLR_FOCUS_PATH", focus_path) .env("XPLR_FOCUS_PATH", focus_path)
.env("XPLR_FOCUS_INDEX", focus_index) .env("XPLR_FOCUS_INDEX", focus_index)
.env("XPLR_SELECTED", selected) .env("XPLR_SELECTION", selection)
.env("XPLR_RUNTIME_PATH", app.runtime_path()) .env("XPLR_RUNTIME_PATH", app.runtime_path())
.env("XPLR_PIPE_MSG_IN", pipe_msg_in) .env("XPLR_PIPE_MSG_IN", pipe_msg_in)
.env("XPLR_PIPE_SELECTED_OUT", pipe_selected_out) .env("XPLR_PIPE_SELECTION_OUT", pipe_selection_out)
.env("XPLR_PIPE_FOCUS_OUT", pipe_focus_out) .env("XPLR_PIPE_FOCUS_OUT", pipe_focus_out)
.env("XPLR_APP_YAML", app_yaml) .env("XPLR_APP_YAML", app_yaml)
.env("XPLR_DIRECTORY_NODES", directory_nodes) .env("XPLR_DIRECTORY_NODES", directory_nodes)

@ -100,7 +100,7 @@ fn draw_table<B: Backend>(f: &mut Frame<B>, rect: Rect, app: &app::App, hb: &Han
let is_focused = dir.focus == index; let is_focused = dir.focus == index;
// TODO : Optimize // TODO : Optimize
let is_selected = app.selected().contains(&node); let is_selected = app.selection().contains(&node);
let ui = if is_focused { let ui = if is_focused {
&config.general.focused_ui &config.general.focused_ui
@ -250,9 +250,9 @@ fn draw_table<B: Backend>(f: &mut Frame<B>, rect: Rect, app: &app::App, hb: &Han
f.render_stateful_widget(table, rect, &mut table_state); f.render_stateful_widget(table, rect, &mut table_state);
} }
fn draw_selected<B: Backend>(f: &mut Frame<B>, rect: Rect, app: &app::App, _: &Handlebars) { fn draw_selection<B: Backend>(f: &mut Frame<B>, rect: Rect, app: &app::App, _: &Handlebars) {
let selected: Vec<ListItem> = app let selected: Vec<ListItem> = app
.selected() .selection()
.iter() .iter()
.map(|n| n.absolute_path.clone()) .map(|n| n.absolute_path.clone())
.map(ListItem::new) .map(ListItem::new)
@ -384,6 +384,6 @@ pub fn draw<B: Backend>(f: &mut Frame<B>, app: &app::App, hb: &Handlebars) {
draw_table(f, left_chunks[0], app, hb); draw_table(f, left_chunks[0], app, hb);
draw_input_buffer(f, left_chunks[1], app, hb); draw_input_buffer(f, left_chunks[1], app, hb);
draw_selected(f, right_chunks[0], app, hb); draw_selection(f, right_chunks[0], app, hb);
draw_help_menu(f, right_chunks[1], app, hb); draw_help_menu(f, right_chunks[1], app, hb);
} }

Loading…
Cancel
Save