Skip to content

Commit

Permalink
Improve CallLua and CallLuaSilently
Browse files Browse the repository at this point in the history
Pass a custom table, optimized for convenience and speed.
  • Loading branch information
sayanarijit committed May 27, 2021
1 parent 695acf5 commit fc7d205
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "xplr"
version = "0.12.2" # Update lua.rs
version = "0.13.0" # Update lua.rs
authors = ["Arijit Basu <[email protected]>"]
edition = "2018"
description = "A hackable, minimal, fast TUI file explorer"
Expand Down
37 changes: 37 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1460,6 +1460,24 @@ impl History {
}
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CallLuaArg {
pub version: String,
pub config: Config,
pub pwd: String,
pub focused_node: Option<Node>,
pub directory_buffer: Option<DirectoryBuffer>,
pub selection: IndexSet<Node>,
pub mode: Mode,
pub layout: Layout,
pub input_buffer: Option<String>,
pub pid: u32,
pub session_path: String,
pub explorer_config: ExplorerConfig,
pub history: History,
pub last_modes: Vec<Mode>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct App {
pub version: String,
Expand Down Expand Up @@ -2758,4 +2776,23 @@ impl App {
pub fn logs_hidden(&self) -> bool {
self.logs_hidden
}

pub fn to_lua_arg(&self) -> CallLuaArg {
CallLuaArg {
version: self.version.clone(),
config: self.config.clone(),
pwd: self.pwd.clone(),
focused_node: self.focused_node().cloned(),
directory_buffer: self.directory_buffer().cloned(),
selection: self.selection.clone(),
mode: self.mode.clone(),
layout: self.layout.clone(),
input_buffer: self.input_buffer.clone(),
pid: self.pid,
session_path: self.session_path.clone(),
explorer_config: self.explorer_config.clone(),
history: self.history.clone(),
last_modes: self.last_modes.clone(),
}
}
}
11 changes: 5 additions & 6 deletions src/lua.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,11 @@ mod test {
#[test]
fn test_compatibility() {
assert!(check_version(VERSION, "foo path").is_ok());
assert!(check_version("0.12.0", "foo path").is_ok());
assert!(check_version("0.12.1", "foo path").is_ok());
assert!(check_version("0.12.2", "foo path").is_ok());
assert!(check_version("0.13.0", "foo path").is_ok());

assert!(check_version("0.12.3", "foo path").is_err());
assert!(check_version("0.11.2", "foo path").is_err());
assert!(check_version("1.12.2", "foo path").is_err());
assert!(check_version("0.13.1", "foo path").is_err());
assert!(check_version("0.14.0", "foo path").is_err());
assert!(check_version("0.11.0", "foo path").is_err());
assert!(check_version("1.13.0", "foo path").is_err());
}
}
2 changes: 1 addition & 1 deletion src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fn call_lua(
(get_tty()?.into(), get_tty()?.into(), get_tty()?.into())
};

lua::call(lua, func, &app)
lua::call(lua, func, &app.to_lua_arg())
}

fn call(app: &app::App, cmd: app::Command, silent: bool) -> io::Result<ExitStatus> {
Expand Down

0 comments on commit fc7d205

Please sign in to comment.