Skip to content

Commit

Permalink
Add xplr.util.debug
Browse files Browse the repository at this point in the history
Also update version
  • Loading branch information
sayanarijit committed Feb 10, 2024
1 parent 6e8f3da commit ded2e10
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 34 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
Expand Up @@ -8,7 +8,7 @@ path = './benches/criterion.rs'

[package]
name = 'xplr'
version = '0.21.5'
version = '0.21.6'
authors = ['Arijit Basu <[email protected]>']
edition = '2021'
description = 'A hackable, minimal, fast TUI file explorer'
Expand Down
8 changes: 6 additions & 2 deletions docs/en/src/upgrade-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ compatibility.

### Instructions

#### [v0.20.2][48] -> [v0.21.5][49]
#### [v0.20.2][48] -> [v0.21.6][49]

- Some plugins might stop rendering colors. Wait for them to update.
- Rename `xplr.config.general.sort_and_filter_ui.search_identifier` to
Expand Down Expand Up @@ -123,6 +123,10 @@ compatibility.
messages:
- NextVisitedDeepBranch (bound to `)` key)
- PreviousVisitedDeepBranch (bound to `(` key)
- Since v0.21.6:
- You can use `c` and `m` keys in default mode to quickly copy
and move focused or selected files, without having to change directory.
- Use `xplr.util.debug()` to debug lua values.

Thanks to @noahmayr for contributing to a major part of this release.

Expand Down Expand Up @@ -521,5 +525,5 @@ Else do the following:
[46]: https://github.com/sayanarijit/xplr/releases/tag/v0.18.0
[47]: https://github.com/sayanarijit/xplr/releases/tag/v0.19.4
[48]: https://github.com/sayanarijit/xplr/releases/tag/v0.20.2
[49]: https://github.com/sayanarijit/xplr/releases/tag/v0.21.5
[49]: https://github.com/sayanarijit/xplr/releases/tag/v0.21.6
[50]: https://github.com/lotabout/skim#search-syntax
17 changes: 17 additions & 0 deletions docs/en/src/xplr.util.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,23 @@ xplr.util.version()
-- { major = 0, minor = 0, patch = 0 }
```

### xplr.util.debug

Print the given value to the console, and return it as a string.
Useful for debugging.

Type: function( value ) -> string

Example:

```lua
xplr.util.debug({ foo = "bar", bar = function() end })
-- {
-- ["bar"] = function: 0x55e5cebdeae0,
-- ["foo"] = "bar",
-- }
```

### xplr.util.clone

Clone/deepcopy a Lua value. Doesn't work with functions.
Expand Down
48 changes: 24 additions & 24 deletions src/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ xplr.config.general.sort_and_filter_ui.search_identifiers = {
--
-- Type: nullable string
xplr.config.general.sort_and_filter_ui.search_direction_identifiers.ordered.format =
""
""

-- The shape of unordered indicator for search ordering identifiers in Sort & filter panel.
--
Expand Down Expand Up @@ -676,7 +676,7 @@ xplr.config.general.panel_ui.sort_and_filter.border_style = {}
-- Type: nullable list of [Node Sorter](https://xplr.dev/en/sorting#node-sorter-applicable)
xplr.config.general.initial_sorting = {
{ sorter = "ByCanonicalIsDir", reverse = true },
{ sorter = "ByIRelativePath", reverse = false },
{ sorter = "ByIRelativePath", reverse = false },
}

-- The name of one of the modes to use when xplr loads.
Expand Down Expand Up @@ -1325,23 +1325,23 @@ xplr.config.modes.builtin.default = {
}

xplr.config.modes.builtin.default.key_bindings.on_key["v"] =
xplr.config.modes.builtin.default.key_bindings.on_key["space"]
xplr.config.modes.builtin.default.key_bindings.on_key["space"]
xplr.config.modes.builtin.default.key_bindings.on_key["V"] =
xplr.config.modes.builtin.default.key_bindings.on_key["ctrl-a"]
xplr.config.modes.builtin.default.key_bindings.on_key["ctrl-a"]
xplr.config.modes.builtin.default.key_bindings.on_key["/"] =
xplr.config.modes.builtin.default.key_bindings.on_key["ctrl-f"]
xplr.config.modes.builtin.default.key_bindings.on_key["ctrl-f"]
xplr.config.modes.builtin.default.key_bindings.on_key["h"] =
xplr.config.modes.builtin.default.key_bindings.on_key["left"]
xplr.config.modes.builtin.default.key_bindings.on_key["left"]
xplr.config.modes.builtin.default.key_bindings.on_key["j"] =
xplr.config.modes.builtin.default.key_bindings.on_key["down"]
xplr.config.modes.builtin.default.key_bindings.on_key["down"]
xplr.config.modes.builtin.default.key_bindings.on_key["k"] =
xplr.config.modes.builtin.default.key_bindings.on_key["up"]
xplr.config.modes.builtin.default.key_bindings.on_key["up"]
xplr.config.modes.builtin.default.key_bindings.on_key["l"] =
xplr.config.modes.builtin.default.key_bindings.on_key["right"]
xplr.config.modes.builtin.default.key_bindings.on_key["right"]
xplr.config.modes.builtin.default.key_bindings.on_key["tab"] =
xplr.config.modes.builtin.default.key_bindings.on_key["ctrl-i"] -- compatibility workaround
xplr.config.modes.builtin.default.key_bindings.on_key["ctrl-i"] -- compatibility workaround
xplr.config.modes.builtin.default.key_bindings.on_key["?"] =
xplr.config.general.global_key_bindings.on_key["f1"]
xplr.config.general.global_key_bindings.on_key["f1"]

-- The builtin debug error mode.
--
Expand Down Expand Up @@ -1993,9 +1993,9 @@ xplr.config.modes.builtin.number = {
}

xplr.config.modes.builtin.number.key_bindings.on_key["j"] =
xplr.config.modes.builtin.number.key_bindings.on_key["down"]
xplr.config.modes.builtin.number.key_bindings.on_key["down"]
xplr.config.modes.builtin.number.key_bindings.on_key["k"] =
xplr.config.modes.builtin.number.key_bindings.on_key["up"]
xplr.config.modes.builtin.number.key_bindings.on_key["up"]

-- The builtin go to mode.
--
Expand Down Expand Up @@ -2479,9 +2479,9 @@ xplr.config.modes.builtin.search = {
}

xplr.config.modes.builtin.search.key_bindings.on_key["ctrl-n"] =
xplr.config.modes.builtin.search.key_bindings.on_key["down"]
xplr.config.modes.builtin.search.key_bindings.on_key["down"]
xplr.config.modes.builtin.search.key_bindings.on_key["ctrl-p"] =
xplr.config.modes.builtin.search.key_bindings.on_key["up"]
xplr.config.modes.builtin.search.key_bindings.on_key["up"]

-- The builtin filter mode.
--
Expand Down Expand Up @@ -3161,7 +3161,7 @@ xplr.fn.builtin.fmt_general_table_row_cols_1 = function(m)
r = r .. "×"
else
local symlink_path =
xplr.util.shorten(m.symlink.absolute_path, { base = m.parent })
xplr.util.shorten(m.symlink.absolute_path, { base = m.parent })
if m.symlink.is_dir then
symlink_path = symlink_path .. "/"
end
Expand All @@ -3183,14 +3183,14 @@ xplr.fn.builtin.fmt_general_table_row_cols_2 = function(m)
local T = xplr.util.paint("T", { fg = "Red" })

return xplr.util
.permissions_rwx(m.permissions)
:gsub("r", r)
:gsub("w", w)
:gsub("x", x)
:gsub("s", s)
:gsub("S", S)
:gsub("t", t)
:gsub("T", T)
.permissions_rwx(m.permissions)
:gsub("r", r)
:gsub("w", w)
:gsub("x", x)
:gsub("s", s)
:gsub("S", S)
:gsub("t", t)
:gsub("T", T)
end

-- Renders the fourth column in the table
Expand Down
12 changes: 6 additions & 6 deletions src/lua/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,24 +160,24 @@ mod tests {
assert!(check_version(VERSION, "foo path").is_ok());

// Current release if OK
assert!(check_version("0.21.5", "foo path").is_ok());
assert!(check_version("0.21.6", "foo path").is_ok());

// Prev major release is ERR
// - Not yet

// Prev minor release is ERR (Change when we get to v1)
assert!(check_version("0.20.5", "foo path").is_err());
assert!(check_version("0.20.6", "foo path").is_err());

// Prev bugfix release is OK
assert!(check_version("0.21.4", "foo path").is_ok());
assert!(check_version("0.21.5", "foo path").is_ok());

// Next major release is ERR
assert!(check_version("1.20.5", "foo path").is_err());
assert!(check_version("1.20.6", "foo path").is_err());

// Next minor release is ERR
assert!(check_version("0.22.5", "foo path").is_err());
assert!(check_version("0.22.6", "foo path").is_err());

// Next bugfix release is ERR (Change when we get to v1)
assert!(check_version("0.21.6", "foo path").is_err());
assert!(check_version("0.21.7", "foo path").is_err());
}
}
25 changes: 25 additions & 0 deletions src/lua/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,30 @@ pub fn version<'a>(util: Table<'a>, lua: &Lua) -> Result<Table<'a>> {
Ok(util)
}

/// Print the given value to the console, and return it as a string.
/// Useful for debugging.
///
/// Type: function( value ) -> string
///
/// Example:
///
/// ```lua
/// xplr.util.debug({ foo = "bar", bar = function() end })
/// -- {
/// -- ["bar"] = function: 0x55e5cebdeae0,
/// -- ["foo"] = "bar",
/// -- }
/// ```
pub fn debug<'a>(util: Table<'a>, lua: &Lua) -> Result<Table<'a>> {
let func = lua.create_function(|_, value: Value| {
let log = format!("{:#?}", value);
println!("{}", log);
Ok(log)
})?;
util.set("debug", func)?;
Ok(util)
}

/// Clone/deepcopy a Lua value. Doesn't work with functions.
///
/// Type: function( value ) -> value
Expand Down Expand Up @@ -838,6 +862,7 @@ pub(crate) fn create_table(lua: &Lua) -> Result<Table> {
let mut util = lua.create_table()?;

util = version(util, lua)?;
util = debug(util, lua)?;
util = clone(util, lua)?;
util = exists(util, lua)?;
util = is_dir(util, lua)?;
Expand Down

0 comments on commit ded2e10

Please sign in to comment.