Add xplr.util.debug

Also update version
pull/696/head
Arijit Basu 3 months ago
parent 6e8f3da971
commit ded2e108bf
No known key found for this signature in database
GPG Key ID: 0F8EF5258DC38077

2
Cargo.lock generated

@ -1917,7 +1917,7 @@ checksum = "213b7324336b53d2414b2db8537e56544d981803139155afa84f76eeebb7a546"
[[package]]
name = "xplr"
version = "0.21.5"
version = "0.21.6"
dependencies = [
"ansi-to-tui",
"anyhow",

@ -8,7 +8,7 @@ path = './benches/criterion.rs'
[package]
name = 'xplr'
version = '0.21.5'
version = '0.21.6'
authors = ['Arijit Basu <hi@arijitbasu.in>']
edition = '2021'
description = 'A hackable, minimal, fast TUI file explorer'

@ -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
@ -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.
@ -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

@ -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.

@ -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.
--

@ -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());
}
}

@ -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
@ -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)?;

Loading…
Cancel
Save