Skip to content

Commit

Permalink
xplr.util.lscolor shouldn't return nil
Browse files Browse the repository at this point in the history
Closes: #705

Also update xplr version.
  • Loading branch information
sayanarijit committed May 1, 2024
1 parent c1bb251 commit 63cada7
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 14 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.7'
version = '0.21.8'
authors = ['Arijit Basu <hi@arijitbasu.in>']
edition = '2021'
description = 'A hackable, minimal, fast TUI file explorer'
Expand Down
2 changes: 1 addition & 1 deletion docs/en/src/xplr.util.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
7 changes: 4 additions & 3 deletions src/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -3142,8 +3142,9 @@ 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 .. ""
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.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());
}
}
7 changes: 5 additions & 2 deletions src/lua/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
///
Expand All @@ -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)?;
Expand Down

0 comments on commit 63cada7

Please sign in to comment.