Make internals private

pull/109/head
Arijit Basu 3 years ago committed by Arijit Basu
parent 33e500a16d
commit f38398e900

@ -20,15 +20,15 @@ pub const UPGRADE_GUIDE_LINK: &str = "https://github.com/sayanarijit/xplr/wiki/U
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Pipe { pub struct Pipe {
pub msg_in: String, msg_in: String,
pub focus_out: String, focus_out: String,
pub selection_out: String, selection_out: String,
pub result_out: String, result_out: String,
pub mode_out: String, mode_out: String,
pub directory_nodes_out: String, directory_nodes_out: String,
pub global_help_menu_out: String, global_help_menu_out: String,
pub logs_out: String, logs_out: String,
pub history_out: String, history_out: String,
} }
impl Pipe { impl Pipe {
@ -83,17 +83,62 @@ impl Pipe {
history_out, history_out,
}) })
} }
/// Get a reference to the pipe's msg in.
pub fn msg_in(&self) -> &String {
&self.msg_in
}
/// Get a reference to the pipe's focus out.
pub fn focus_out(&self) -> &String {
&self.focus_out
}
/// Get a reference to the pipe's selection out.
pub fn selection_out(&self) -> &String {
&self.selection_out
}
/// Get a reference to the pipe's result out.
pub fn result_out(&self) -> &String {
&self.result_out
}
/// Get a reference to the pipe's mode out.
pub fn mode_out(&self) -> &String {
&self.mode_out
}
/// Get a reference to the pipe's directory nodes out.
pub fn directory_nodes_out(&self) -> &String {
&self.directory_nodes_out
}
/// Get a reference to the pipe's global help menu out.
pub fn global_help_menu_out(&self) -> &String {
&self.global_help_menu_out
}
/// Get a reference to the pipe's logs out.
pub fn logs_out(&self) -> &String {
&self.logs_out
}
/// Get a reference to the pipe's history out.
pub fn history_out(&self) -> &String {
&self.history_out
}
} }
#[derive(Debug, Clone, Eq, Hash, PartialEq, Serialize, Deserialize)] #[derive(Debug, Clone, Eq, Hash, PartialEq, Serialize, Deserialize)]
pub struct ResolvedNode { pub struct ResolvedNode {
pub absolute_path: String, absolute_path: String,
pub extension: String, extension: String,
pub is_dir: bool, is_dir: bool,
pub is_file: bool, is_file: bool,
pub is_readonly: bool, is_readonly: bool,
pub mime_essence: String, mime_essence: String,
pub size: u64, size: u64,
} }
impl ResolvedNode { impl ResolvedNode {
@ -123,23 +168,58 @@ impl ResolvedNode {
size, size,
} }
} }
/// Get a reference to the resolved node's absolute path.
pub fn absolute_path(&self) -> &String {
&self.absolute_path
}
/// Get a reference to the resolved node's extension.
pub fn extension(&self) -> &String {
&self.extension
}
/// Get a reference to the resolved node's is dir.
pub fn is_dir(&self) -> bool {
self.is_dir
}
/// Get a reference to the resolved node's is file.
pub fn is_file(&self) -> bool {
self.is_file
}
/// Get a reference to the resolved node's is readonly.
pub fn is_readonly(&self) -> bool {
self.is_readonly
}
/// Get a reference to the resolved node's mime essence.
pub fn mime_essence(&self) -> &String {
&self.mime_essence
}
/// Get a reference to the resolved node's size.
pub fn size(&self) -> u64 {
self.size
}
} }
#[derive(Debug, Clone, Eq, Hash, PartialEq, Serialize, Deserialize)] #[derive(Debug, Clone, Eq, Hash, PartialEq, Serialize, Deserialize)]
pub struct Node { pub struct Node {
pub parent: String, parent: String,
pub relative_path: String, relative_path: String,
pub absolute_path: String, absolute_path: String,
pub extension: String, extension: String,
pub is_dir: bool, is_dir: bool,
pub is_file: bool, is_file: bool,
pub is_symlink: bool, is_symlink: bool,
pub is_broken: bool, is_broken: bool,
pub is_readonly: bool, is_readonly: bool,
pub mime_essence: String, mime_essence: String,
pub size: u64, size: u64,
pub canonical: Option<ResolvedNode>, canonical: Option<ResolvedNode>,
pub symlink: Option<ResolvedNode>, symlink: Option<ResolvedNode>,
} }
impl Node { impl Node {
@ -199,6 +279,71 @@ impl Node {
}, },
} }
} }
/// Get a reference to the node's parent.
pub fn parent(&self) -> &String {
&self.parent
}
/// Get a reference to the node's relative path.
pub fn relative_path(&self) -> &String {
&self.relative_path
}
/// Get a reference to the node's extension.
pub fn extension(&self) -> &String {
&self.extension
}
/// Get a reference to the node's is dir.
pub fn is_dir(&self) -> bool {
self.is_dir
}
/// Get a reference to the node's is file.
pub fn is_file(&self) -> bool {
self.is_file
}
/// Get a reference to the node's is symlink.
pub fn is_symlink(&self) -> bool {
self.is_symlink
}
/// Get a reference to the node's is broken.
pub fn is_broken(&self) -> bool {
self.is_broken
}
/// Get a reference to the node's is readonly.
pub fn is_readonly(&self) -> bool {
self.is_readonly
}
/// Get a reference to the node's mime essence.
pub fn mime_essence(&self) -> &String {
&self.mime_essence
}
/// Get a reference to the node's size.
pub fn size(&self) -> u64 {
self.size
}
/// Get a reference to the node's canonical.
pub fn canonical(&self) -> &Option<ResolvedNode> {
&self.canonical
}
/// Get a reference to the node's symlink.
pub fn symlink(&self) -> &Option<ResolvedNode> {
&self.symlink
}
/// Get a reference to the node's absolute path.
pub fn absolute_path(&self) -> &String {
&self.absolute_path
}
} }
impl Ord for Node { impl Ord for Node {
@ -217,10 +362,10 @@ impl PartialOrd for Node {
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] #[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
pub struct DirectoryBuffer { pub struct DirectoryBuffer {
pub parent: String, parent: String,
pub nodes: Vec<Node>, nodes: Vec<Node>,
pub total: usize, total: usize,
pub focus: usize, focus: usize,
} }
impl DirectoryBuffer { impl DirectoryBuffer {
@ -237,6 +382,26 @@ impl DirectoryBuffer {
pub fn focused_node(&self) -> Option<&Node> { pub fn focused_node(&self) -> Option<&Node> {
self.nodes.get(self.focus) self.nodes.get(self.focus)
} }
/// Get a reference to the directory buffer's parent.
pub fn parent(&self) -> &String {
&self.parent
}
/// Get a reference to the directory buffer's nodes.
pub fn nodes(&self) -> &Vec<Node> {
&self.nodes
}
/// Get a reference to the directory buffer's total.
pub fn total(&self) -> usize {
self.total
}
/// Get a reference to the directory buffer's focus.
pub fn focus(&self) -> usize {
self.focus
}
} }
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] #[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
@ -281,9 +446,9 @@ pub enum NodeSorter {
#[derive(Debug, Clone, Eq, Serialize, Deserialize)] #[derive(Debug, Clone, Eq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)] #[serde(deny_unknown_fields)]
pub struct NodeSorterApplicable { pub struct NodeSorterApplicable {
pub sorter: NodeSorter, sorter: NodeSorter,
#[serde(default)] #[serde(default)]
pub reverse: bool, reverse: bool,
} }
impl PartialEq for NodeSorterApplicable { impl PartialEq for NodeSorterApplicable {
@ -568,6 +733,16 @@ impl NodeSorterApplicable {
.cmp(&a.symlink.as_ref().map(|s| &s.size)), .cmp(&a.symlink.as_ref().map(|s| &s.size)),
} }
} }
/// Get a reference to the node sorter applicable's sorter.
pub fn sorter(&self) -> &NodeSorter {
&self.sorter
}
/// Get a reference to the node sorter applicable's reverse.
pub fn reverse(&self) -> bool {
self.reverse
}
} }
#[derive(Debug, Clone, Copy, Hash, Eq, PartialEq, Serialize, Deserialize)] #[derive(Debug, Clone, Copy, Hash, Eq, PartialEq, Serialize, Deserialize)]
@ -716,8 +891,8 @@ impl NodeFilter {
#[derive(Debug, Clone, Eq, Hash, PartialEq, Serialize, Deserialize)] #[derive(Debug, Clone, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)] #[serde(deny_unknown_fields)]
pub struct NodeFilterApplicable { pub struct NodeFilterApplicable {
pub filter: NodeFilter, filter: NodeFilter,
pub input: String, input: String,
} }
impl NodeFilterApplicable { impl NodeFilterApplicable {
@ -728,6 +903,16 @@ impl NodeFilterApplicable {
fn apply(&self, node: &Node) -> bool { fn apply(&self, node: &Node) -> bool {
self.filter.apply(node, &self.input) self.filter.apply(node, &self.input)
} }
/// Get a reference to the node filter applicable's filter.
pub fn filter(&self) -> &NodeFilter {
&self.filter
}
/// Get a reference to the node filter applicable's input.
pub fn input(&self) -> &String {
&self.input
}
} }
#[derive(Debug, Default, Clone, Eq, PartialEq, Serialize, Deserialize)] #[derive(Debug, Default, Clone, Eq, PartialEq, Serialize, Deserialize)]
@ -1057,10 +1242,22 @@ pub enum MsgIn {
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] #[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)] #[serde(deny_unknown_fields)]
pub struct Command { pub struct Command {
pub command: String, command: String,
#[serde(default)] #[serde(default)]
pub args: Vec<String>, args: Vec<String>,
}
impl Command {
/// Get a reference to the command's command.
pub fn command(&self) -> &String {
&self.command
}
/// Get a reference to the command's args.
pub fn args(&self) -> &Vec<String> {
&self.args
}
} }
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] #[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
@ -1099,9 +1296,9 @@ pub enum LogLevel {
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] #[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
pub struct Log { pub struct Log {
pub level: LogLevel, level: LogLevel,
pub message: String, message: String,
pub created_at: DateTime<Local>, created_at: DateTime<Local>,
} }
impl Log { impl Log {
@ -1112,6 +1309,21 @@ impl Log {
created_at: Local::now(), created_at: Local::now(),
} }
} }
/// Get a reference to the log's created at.
pub fn created_at(&self) -> &DateTime<Local> {
&self.created_at
}
/// Get a reference to the log's message.
pub fn message(&self) -> &String {
&self.message
}
/// Get a reference to the log's level.
pub fn level(&self) -> &LogLevel {
&self.level
}
} }
impl std::fmt::Display for Log { impl std::fmt::Display for Log {
@ -1138,24 +1350,24 @@ pub struct History {
} }
impl History { impl History {
pub fn push(mut self, path: String) -> Self { fn push(mut self, path: String) -> Self {
self.paths = self.paths.into_iter().take(self.loc + 1).collect(); self.paths = self.paths.into_iter().take(self.loc + 1).collect();
self.paths.push(path); self.paths.push(path);
self.loc = self.paths.len().max(1) - 1; self.loc = self.paths.len().max(1) - 1;
self self
} }
pub fn visit_last(mut self) -> Self { fn visit_last(mut self) -> Self {
self.loc = self.loc.max(1) - 1; self.loc = self.loc.max(1) - 1;
self self
} }
pub fn visit_next(mut self) -> Self { fn visit_next(mut self) -> Self {
self.loc = (self.loc + 1).min(self.paths.len().max(1) - 1); self.loc = (self.loc + 1).min(self.paths.len().max(1) - 1);
self self
} }
pub fn peek(&self) -> Option<&String> { fn peek(&self) -> Option<&String> {
self.paths.get(self.loc) self.paths.get(self.loc)
} }
} }
@ -1285,7 +1497,7 @@ impl App {
.unwrap_or_default() .unwrap_or_default()
} }
pub fn enqueue(mut self, task: Task) -> Self { fn enqueue(mut self, task: Task) -> Self {
self.msg_out.push_back(MsgOut::Enque(task)); self.msg_out.push_back(MsgOut::Enque(task));
self self
} }
@ -2151,7 +2363,7 @@ impl App {
.join("") .join("")
} }
pub fn write_pipes(self, last_app: &Self) -> Result<Self> { fn write_pipes(self, last_app: &Self) -> Result<Self> {
if self.focused_node() != last_app.focused_node() { if self.focused_node() != last_app.focused_node() {
fs::write(&self.pipe().focus_out, self.focused_node_str())?; fs::write(&self.pipe().focus_out, self.focused_node_str())?;
}; };

@ -38,7 +38,7 @@ pub fn explore(
nodes nodes
.iter() .iter()
.enumerate() .enumerate()
.find(|(_, n)| n.relative_path == focus) .find(|(_, n)| n.relative_path() == &focus)
.map(|(i, _)| i) .map(|(i, _)| i)
.unwrap_or(0) .unwrap_or(0)
} else { } else {

@ -24,52 +24,45 @@ use tui::Terminal;
handlebars_helper!(to_humansize: |size: i64| size.file_size(options::CONVENTIONAL).unwrap_or_default()); handlebars_helper!(to_humansize: |size: i64| size.file_size(options::CONVENTIONAL).unwrap_or_default());
fn call(app: &app::App, cmd: app::Command, silent: bool) -> io::Result<ExitStatus> { fn call(app: &app::App, cmd: app::Command, silent: bool) -> io::Result<ExitStatus> {
let input_buffer = app.input_buffer().unwrap_or_default();
let focus_index = app let focus_index = app
.directory_buffer() .directory_buffer()
.map(|d| d.focus) .map(|d| d.focus())
.unwrap_or_default() .unwrap_or_default()
.to_string(); .to_string();
let pipe_msg_in = app.pipe().msg_in.clone();
let pipe_mode_out = app.pipe().mode_out.clone();
let pipe_focus_out = app.pipe().focus_out.clone();
let pipe_selection_out = app.pipe().selection_out.clone();
let pipe_result_out = app.pipe().result_out.clone();
let pipe_directory_nodes_out = app.pipe().directory_nodes_out.clone();
let pipe_global_help_menu_out = app.pipe().global_help_menu_out.clone();
let pipe_logs_out = app.pipe().logs_out.clone();
let pipe_history_out = app.pipe().history_out.clone();
let session_path = app.session_path();
let (stdin, stdout, stderr) = if silent { let (stdin, stdout, stderr) = if silent {
(Stdio::null(), Stdio::null(), Stdio::null()) (Stdio::null(), Stdio::null(), Stdio::null())
} else { } else {
(get_tty()?.into(), get_tty()?.into(), get_tty()?.into()) (get_tty()?.into(), get_tty()?.into(), get_tty()?.into())
}; };
Command::new(cmd.command.clone()) Command::new(cmd.command().clone())
.env("XPLR_APP_VERSION", app.version()) .env("XPLR_APP_VERSION", app.version())
.env("XPLR_CONFIG_VERSION", &app.config().version) .env("XPLR_CONFIG_VERSION", &app.config().version)
.env("XPLR_PID", &app.pid().to_string()) .env("XPLR_PID", &app.pid().to_string())
.env("XPLR_INPUT_BUFFER", input_buffer) .env("XPLR_INPUT_BUFFER", app.input_buffer().unwrap_or_default())
.env("XPLR_FOCUS_PATH", app.focused_node_str()) .env("XPLR_FOCUS_PATH", app.focused_node_str())
.env("XPLR_FOCUS_INDEX", focus_index) .env("XPLR_FOCUS_INDEX", focus_index)
.env("XPLR_SESSION_PATH", session_path) .env("XPLR_SESSION_PATH", app.session_path())
.env("XPLR_PIPE_MSG_IN", pipe_msg_in) .env("XPLR_PIPE_MSG_IN", app.pipe().msg_in())
.env("XPLR_PIPE_SELECTION_OUT", pipe_selection_out) .env("XPLR_PIPE_SELECTION_OUT", app.pipe().selection_out())
.env("XPLR_PIPE_HISTORY_OUT", pipe_history_out) .env("XPLR_PIPE_HISTORY_OUT", app.pipe().history_out())
.env("XPLR_PIPE_FOCUS_OUT", pipe_focus_out) .env("XPLR_PIPE_FOCUS_OUT", app.pipe().focus_out())
.env("XPLR_PIPE_MODE_OUT", pipe_mode_out) .env("XPLR_PIPE_MODE_OUT", app.pipe().mode_out())
.env("XPLR_PIPE_RESULT_OUT", pipe_result_out) .env("XPLR_PIPE_RESULT_OUT", app.pipe().result_out())
.env("XPLR_PIPE_GLOBAL_HELP_MENU_OUT", pipe_global_help_menu_out) .env(
.env("XPLR_PIPE_DIRECTORY_NODES_OUT", pipe_directory_nodes_out) "XPLR_PIPE_GLOBAL_HELP_MENU_OUT",
.env("XPLR_PIPE_LOGS_OUT", pipe_logs_out) app.pipe().global_help_menu_out(),
)
.env(
"XPLR_PIPE_DIRECTORY_NODES_OUT",
app.pipe().directory_nodes_out(),
)
.env("XPLR_PIPE_LOGS_OUT", app.pipe().logs_out())
.stdin(stdin) .stdin(stdin)
.stdout(stdout) .stdout(stdout)
.stderr(stderr) .stderr(stderr)
.args(cmd.args) .args(cmd.args())
.status() .status()
} }
@ -115,7 +108,7 @@ pub fn run(mut app: app::App, focused_path: Option<String>) -> Result<Option<Str
// Threads // Threads
auto_refresher::start_auto_refreshing(tx_msg_in.clone()); auto_refresher::start_auto_refreshing(tx_msg_in.clone());
pipe_reader::keep_reading(app.pipe().msg_in.clone(), tx_msg_in.clone()); pipe_reader::keep_reading(app.pipe().msg_in().clone(), tx_msg_in.clone());
event_reader::keep_reading(tx_msg_in.clone(), rx_event_reader); event_reader::keep_reading(tx_msg_in.clone(), rx_event_reader);
pwd_watcher::keep_watching(app.pwd(), tx_msg_in.clone(), rx_pwd_watcher)?; pwd_watcher::keep_watching(app.pwd(), tx_msg_in.clone(), rx_pwd_watcher)?;
@ -168,7 +161,7 @@ pub fn run(mut app: app::App, focused_path: Option<String>) -> Result<Option<Str
explorer::explore( explorer::explore(
app.explorer_config().clone(), app.explorer_config().clone(),
app.pwd().clone(), app.pwd().clone(),
app.focused_node().map(|n| n.relative_path.clone()), app.focused_node().map(|n| n.relative_path().clone()),
tx_msg_in.clone(), tx_msg_in.clone(),
); );
} }
@ -179,7 +172,7 @@ pub fn run(mut app: app::App, focused_path: Option<String>) -> Result<Option<Str
explorer::explore( explorer::explore(
app.explorer_config().clone(), app.explorer_config().clone(),
app.pwd().clone(), app.pwd().clone(),
app.focused_node().map(|n| n.relative_path.clone()), app.focused_node().map(|n| n.relative_path().clone()),
tx_msg_in.clone(), tx_msg_in.clone(),
); );
}; };

@ -23,10 +23,10 @@ lazy_static! {
#[derive(Debug, Copy, Clone, Default, PartialEq, Serialize, Deserialize)] #[derive(Debug, Copy, Clone, Default, PartialEq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)] #[serde(deny_unknown_fields)]
pub struct Style { pub struct Style {
pub fg: Option<Color>, fg: Option<Color>,
pub bg: Option<Color>, bg: Option<Color>,
pub add_modifier: Option<Modifier>, add_modifier: Option<Modifier>,
pub sub_modifier: Option<Modifier>, sub_modifier: Option<Modifier>,
} }
impl Style { impl Style {
@ -68,25 +68,25 @@ impl Into<TuiStyle> for Style {
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct ResolvedNodeUiMetadata { pub struct ResolvedNodeUiMetadata {
pub absolute_path: String, absolute_path: String,
pub extension: String, extension: String,
pub is_dir: bool, is_dir: bool,
pub is_file: bool, is_file: bool,
pub is_readonly: bool, is_readonly: bool,
pub mime_essence: String, mime_essence: String,
pub size: u64, size: u64,
} }
impl From<ResolvedNode> for ResolvedNodeUiMetadata { impl From<ResolvedNode> for ResolvedNodeUiMetadata {
fn from(node: ResolvedNode) -> Self { fn from(node: ResolvedNode) -> Self {
Self { Self {
absolute_path: node.absolute_path.clone(), absolute_path: node.absolute_path().clone(),
extension: node.extension.clone(), extension: node.extension().clone(),
is_dir: node.is_dir, is_dir: node.is_dir(),
is_file: node.is_file, is_file: node.is_file(),
is_readonly: node.is_readonly, is_readonly: node.is_readonly(),
mime_essence: node.mime_essence, mime_essence: node.mime_essence().clone(),
size: node.size, size: node.size(),
} }
} }
} }
@ -95,32 +95,32 @@ impl From<ResolvedNode> for ResolvedNodeUiMetadata {
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
struct NodeUiMetadata { struct NodeUiMetadata {
// From Node // From Node
pub parent: String, parent: String,
pub relative_path: String, relative_path: String,
pub absolute_path: String, absolute_path: String,
pub extension: String, extension: String,
pub is_symlink: bool, is_symlink: bool,
pub is_broken: bool, is_broken: bool,
pub is_dir: bool, is_dir: bool,
pub is_file: bool, is_file: bool,
pub is_readonly: bool, is_readonly: bool,
pub mime_essence: String, mime_essence: String,
pub size: u64, size: u64,
pub canonical: Option<ResolvedNodeUiMetadata>, canonical: Option<ResolvedNodeUiMetadata>,
pub symlink: Option<ResolvedNodeUiMetadata>, symlink: Option<ResolvedNodeUiMetadata>,
// Extra // Extra
pub index: usize, index: usize,
pub relative_index: usize, relative_index: usize,
pub is_before_focus: bool, is_before_focus: bool,
pub is_after_focus: bool, is_after_focus: bool,
pub tree: String, tree: String,
pub prefix: String, prefix: String,
pub suffix: String, suffix: String,
pub is_selected: bool, is_selected: bool,
pub is_focused: bool, is_focused: bool,
pub total: usize, total: usize,
pub meta: HashMap<String, String>, meta: HashMap<String, String>,
} }
impl NodeUiMetadata { impl NodeUiMetadata {
@ -139,19 +139,19 @@ impl NodeUiMetadata {
meta: HashMap<String, String>, meta: HashMap<String, String>,
) -> Self { ) -> Self {
Self { Self {
parent: node.parent.clone(), parent: node.parent().clone(),
relative_path: node.relative_path.clone(), relative_path: node.relative_path().clone(),
absolute_path: node.absolute_path.clone(), absolute_path: node.absolute_path().clone(),
extension: node.extension.clone(), extension: node.extension().clone(),
is_symlink: node.is_symlink, is_symlink: node.is_symlink(),
is_broken: node.is_broken, is_broken: node.is_broken(),
is_dir: node.is_dir, is_dir: node.is_dir(),
is_file: node.is_file, is_file: node.is_file(),
is_readonly: node.is_readonly, is_readonly: node.is_readonly(),
mime_essence: node.mime_essence.clone(), mime_essence: node.mime_essence().clone(),
size: node.size, size: node.size(),
canonical: node.canonical.to_owned().map(|s| s.into()), canonical: node.canonical().to_owned().map(|s| s.into()),
symlink: node.symlink.to_owned().map(|s| s.into()), symlink: node.symlink().to_owned().map(|s| s.into()),
index, index,
relative_index, relative_index,
is_before_focus, is_before_focus,
@ -175,19 +175,19 @@ fn draw_table<B: Backend>(f: &mut Frame<B>, rect: Rect, app: &app::App, hb: &Han
let rows = app let rows = app
.directory_buffer() .directory_buffer()
.map(|dir| { .map(|dir| {
dir.nodes dir.nodes()
.iter() .iter()
.enumerate() .enumerate()
.skip(height * (dir.focus / height.max(1))) .skip(height * (dir.focus() / height.max(1)))
.take(height) .take(height)
.map(|(index, node)| { .map(|(index, node)| {
let is_focused = dir.focus == index; let is_focused = dir.focus() == index;
// TODO : Optimize // TODO : Optimize
let is_selected = app.selection().contains(node); let is_selected = app.selection().contains(node);
let is_first = index == 0; let is_first = index == 0;
let is_last = index == dir.total.max(1) - 1; let is_last = index == dir.total().max(1) - 1;
let tree = config let tree = config
.general .general
@ -208,13 +208,13 @@ fn draw_table<B: Backend>(f: &mut Frame<B>, rect: Rect, app: &app::App, hb: &Han
let node_type = config let node_type = config
.node_types .node_types
.special .special
.get(&node.relative_path) .get(node.relative_path())
.or_else(|| config.node_types.extension.get(&node.extension)) .or_else(|| config.node_types.extension.get(node.extension()))
.or_else(|| config.node_types.mime_essence.get(&node.mime_essence)) .or_else(|| config.node_types.mime_essence.get(node.mime_essence()))
.unwrap_or_else(|| { .unwrap_or_else(|| {
if node.is_symlink { if node.is_symlink() {
&config.node_types.symlink &config.node_types.symlink
} else if node.is_dir { } else if node.is_dir() {
&config.node_types.directory &config.node_types.directory
} else { } else {
&config.node_types.file &config.node_types.file
@ -222,9 +222,9 @@ fn draw_table<B: Backend>(f: &mut Frame<B>, rect: Rect, app: &app::App, hb: &Han
}); });
let (relative_index, is_before_focus, is_after_focus) = let (relative_index, is_before_focus, is_after_focus) =
match dir.focus.cmp(&index) { match dir.focus().cmp(&index) {
Ordering::Greater => (dir.focus - index, true, false), Ordering::Greater => (dir.focus() - index, true, false),
Ordering::Less => (index - dir.focus, false, true), Ordering::Less => (index - dir.focus(), false, true),
Ordering::Equal => (0, false, false), Ordering::Equal => (0, false, false),
}; };
@ -258,7 +258,7 @@ fn draw_table<B: Backend>(f: &mut Frame<B>, rect: Rect, app: &app::App, hb: &Han
suffix.unwrap_or_default(), suffix.unwrap_or_default(),
is_selected, is_selected,
is_focused, is_focused,
dir.total, dir.total(),
node_type.meta.clone(), node_type.meta.clone(),
); );
@ -294,7 +294,7 @@ fn draw_table<B: Backend>(f: &mut Frame<B>, rect: Rect, app: &app::App, hb: &Han
.block(Block::default().borders(Borders::ALL).title(format!( .block(Block::default().borders(Borders::ALL).title(format!(
" {} ({}) ", " {} ({}) ",
app.pwd(), app.pwd(),
app.directory_buffer().map(|d| d.total).unwrap_or_default() app.directory_buffer().map(|d| d.total()).unwrap_or_default()
))); )));
let table = table.clone().header( let table = table.clone().header(
@ -323,7 +323,7 @@ fn draw_selection<B: Backend>(f: &mut Frame<B>, rect: Rect, app: &app::App, _: &
.rev() .rev()
.take((rect.height.max(2) - 2).into()) .take((rect.height.max(2) - 2).into())
.rev() .rev()
.map(|n| n.absolute_path.clone()) .map(|n| n.absolute_path().clone())
.map(ListItem::new) .map(ListItem::new)
.collect(); .collect();
@ -433,24 +433,24 @@ fn draw_sort_n_filter_by<B: Backend>(f: &mut Frame<B>, rect: Rect, app: &app::Ap
.iter() .iter()
.map(|f| { .map(|f| {
ui.filter_identifiers ui.filter_identifiers
.get(&f.filter) .get(&f.filter())
.map(|u| { .map(|u| {
( (
Span::styled(u.format.to_owned().unwrap_or_default(), u.style.into()), Span::styled(u.format.to_owned().unwrap_or_default(), u.style.into()),
Span::raw(f.input.clone()), Span::raw(f.input().clone()),
) )
}) })
.unwrap_or_else(|| (Span::raw("f"), Span::raw(""))) .unwrap_or_else(|| (Span::raw("f"), Span::raw("")))
}) })
.chain(sort_by.iter().map(|s| { .chain(sort_by.iter().map(|s| {
let direction = if s.reverse { let direction = if s.reverse() {
reverse.clone() reverse.clone()
} else { } else {
forward.clone() forward.clone()
}; };
ui.sorter_identifiers ui.sorter_identifiers
.get(&s.sorter) .get(&s.sorter())
.map(|u| { .map(|u| {
( (
Span::styled(u.format.to_owned().unwrap_or_default(), u.style.into()), Span::styled(u.format.to_owned().unwrap_or_default(), u.style.into()),
@ -484,27 +484,27 @@ fn draw_logs<B: Backend>(f: &mut Frame<B>, rect: Rect, app: &app::App, _: &Handl
.take(1) .take(1)
.rev() .rev()
.map(|l| { .map(|l| {
let time = l.created_at.format("%r"); let time = l.created_at().format("%r");
match &l.level { match l.level() {
app::LogLevel::Info => ListItem::new(format!( app::LogLevel::Info => ListItem::new(format!(
"{} | {} | {}", "{} | {} | {}",
&time, &time,
&config.info.format.to_owned().unwrap_or_default(), &config.info.format.to_owned().unwrap_or_default(),
&l.message l.message()
)) ))
.style(config.info.style.into()), .style(config.info.style.into()),
app::LogLevel::Success => ListItem::new(format!( app::LogLevel::Success => ListItem::new(format!(
"{} | {} | {}", "{} | {} | {}",
&time, &time,
&config.success.format.to_owned().unwrap_or_default(), &config.success.format.to_owned().unwrap_or_default(),
&l.message l.message()
)) ))
.style(config.success.style.into()), .style(config.success.style.into()),
app::LogLevel::Error => ListItem::new(format!( app::LogLevel::Error => ListItem::new(format!(
"{} | {} | {}", "{} | {} | {}",
&time, &time,
&config.error.format.to_owned().unwrap_or_default(), &config.error.format.to_owned().unwrap_or_default(),
&l.message l.message()
)) ))
.style(config.error.style.into()), .style(config.error.style.into()),
} }

Loading…
Cancel
Save