xplr.util.lscolor shouldn't return nil

Closes: https://github.com/sayanarijit/xplr/issues/705

Also update xplr version.
pull/707/head
Arijit Basu 1 month ago committed by Arijit Basu
parent c1bb251fef
commit 6fb0781fe4

2
Cargo.lock generated

@ -1943,7 +1943,7 @@ checksum = "213b7324336b53d2414b2db8537e56544d981803139155afa84f76eeebb7a546"
[[package]]
name = "xplr"
version = "0.21.7"
version = "0.21.8"
dependencies = [
"ansi-to-tui",
"anyhow",

@ -8,7 +8,7 @@ path = './benches/criterion.rs'
[package]
name = 'xplr'
version = '0.21.7'
version = '0.21.8'
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.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

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

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

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

@ -654,7 +654,7 @@ pub fn to_yaml<'a>(util: Table<'a>, lua: &Lua) -> Result<Table<'a>> {
/// 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<Table<'a>> {
/// ```
pub fn lscolor<'a>(util: Table<'a>, lua: &Lua) -> Result<Table<'a>> {
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)?;

Loading…
Cancel
Save