From 6fb0781fe40533fa1b3ec1a23ca8d8d396c30d9f Mon Sep 17 00:00:00 2001 From: Arijit Basu Date: Wed, 1 May 2024 11:15:37 +0530 Subject: [PATCH] xplr.util.lscolor shouldn't return nil Closes: https://github.com/sayanarijit/xplr/issues/705 Also update xplr version. --- Cargo.lock | 2 +- Cargo.toml | 2 +- docs/en/src/upgrade-guide.md | 7 +++++-- docs/en/src/xplr.util.md | 2 +- src/init.lua | 6 +++--- src/lua/mod.rs | 12 ++++++------ src/lua/util.rs | 7 +++++-- 7 files changed, 22 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 433d022..4ef9bdd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1943,7 +1943,7 @@ checksum = "213b7324336b53d2414b2db8537e56544d981803139155afa84f76eeebb7a546" [[package]] name = "xplr" -version = "0.21.7" +version = "0.21.8" dependencies = [ "ansi-to-tui", "anyhow", diff --git a/Cargo.toml b/Cargo.toml index c412af3..5f552be 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ path = './benches/criterion.rs' [package] name = 'xplr' -version = '0.21.7' +version = '0.21.8' authors = ['Arijit Basu '] edition = '2021' description = 'A hackable, minimal, fast TUI file explorer' diff --git a/docs/en/src/upgrade-guide.md b/docs/en/src/upgrade-guide.md index 54bb05c..38d5347 100644 --- a/docs/en/src/upgrade-guide.md +++ b/docs/en/src/upgrade-guide.md @@ -45,7 +45,7 @@ compatibility. ### Instructions -#### [v0.20.2][48] -> [v0.21.7][49] +#### [v0.20.2][48] -> [v0.21.8][49] - Some plugins might stop rendering colors. Wait for them to update. - Rename `xplr.config.general.sort_and_filter_ui.search_identifier` to @@ -127,6 +127,9 @@ compatibility. - 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. +- Since v0.21.8: + - You can set `xplr.config.general.vimlike_scrolling = true` to enable + vim-like scrolling. Thanks to @noahmayr for contributing to a major part of this release. @@ -525,5 +528,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.7 +[49]: https://github.com/sayanarijit/xplr/releases/tag/v0.21.8 [50]: https://github.com/lotabout/skim#search-syntax diff --git a/docs/en/src/xplr.util.md b/docs/en/src/xplr.util.md index fed14d0..7ef601c 100644 --- a/docs/en/src/xplr.util.md +++ b/docs/en/src/xplr.util.md @@ -397,7 +397,7 @@ xplr.util.to_yaml({ foo = "bar" }) Get a [Style][3] object for the given path based on the LS_COLORS environment variable. -Type: function( path:string ) -> [Style][3]|nil +Type: function( path:string ) -> [Style][3] Example: diff --git a/src/init.lua b/src/init.lua index 48a5f54..903a651 100644 --- a/src/init.lua +++ b/src/init.lua @@ -3118,8 +3118,8 @@ xplr.fn.builtin.fmt_general_selection_item = function(n) if n.is_dir then shortened = shortened .. "/" end - local ls_style = xplr.util.lscolor(n.absolute_path) local meta_style = xplr.util.node_type(n).style + local ls_style = xplr.util.lscolor(n.absolute_path) local style = xplr.util.style_mix({ ls_style, meta_style }) return xplr.util.paint(shortened:gsub("\n", nl), style) end @@ -3142,8 +3142,8 @@ end xplr.fn.builtin.fmt_general_table_row_cols_1 = function(m) local nl = xplr.util.paint("\\n", { add_modifiers = { "Italic", "Dim" } }) local r = m.tree .. m.prefix - local style = xplr.util.lscolor(m.absolute_path) - style = xplr.util.style_mix({ style, m.style }) + local ls_style = xplr.util.lscolor(m.absolute_path) + local style = xplr.util.style_mix({ ls_style, m.style }) if m.meta.icon == nil then r = r .. "" diff --git a/src/lua/mod.rs b/src/lua/mod.rs index 49c2640..467a3bf 100644 --- a/src/lua/mod.rs +++ b/src/lua/mod.rs @@ -160,24 +160,24 @@ mod tests { assert!(check_version(VERSION, "foo path").is_ok()); // Current release if OK - assert!(check_version("0.21.7", "foo path").is_ok()); + assert!(check_version("0.21.8", "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.7", "foo path").is_err()); + assert!(check_version("0.20.8", "foo path").is_err()); // Prev bugfix release is OK - assert!(check_version("0.21.6", "foo path").is_ok()); + assert!(check_version("0.21.7", "foo path").is_ok()); // Next major release is ERR - assert!(check_version("1.20.7", "foo path").is_err()); + assert!(check_version("1.20.8", "foo path").is_err()); // Next minor release is ERR - assert!(check_version("0.22.7", "foo path").is_err()); + assert!(check_version("0.22.8", "foo path").is_err()); // Next bugfix release is ERR (Change when we get to v1) - assert!(check_version("0.21.8", "foo path").is_err()); + assert!(check_version("0.21.9", "foo path").is_err()); } } diff --git a/src/lua/util.rs b/src/lua/util.rs index da01f3c..63abbe9 100644 --- a/src/lua/util.rs +++ b/src/lua/util.rs @@ -654,7 +654,7 @@ pub fn to_yaml<'a>(util: Table<'a>, lua: &Lua) -> Result> { /// Get a [Style][3] object for the given path based on the LS_COLORS /// environment variable. /// -/// Type: function( path:string ) -> [Style][3]|nil +/// Type: function( path:string ) -> [Style][3] /// /// Example: /// @@ -664,7 +664,10 @@ pub fn to_yaml<'a>(util: Table<'a>, lua: &Lua) -> Result> { /// ``` pub fn lscolor<'a>(util: Table<'a>, lua: &Lua) -> Result> { let func = lua.create_function(move |lua, path: String| { - let style = LS_COLORS.style_for_path(path).map(Style::from); + let style = LS_COLORS + .style_for_path(path) + .map(Style::from) + .unwrap_or_default(); lua::serialize(lua, &style).map_err(LuaError::custom) })?; util.set("lscolor", func)?;