Skip to content

Commit

Permalink
feat: add altfont support
Browse files Browse the repository at this point in the history
  • Loading branch information
rktjmp committed Mar 17, 2024
1 parent 2e8d34e commit 5337450
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 9 deletions.
1 change: 1 addition & 0 deletions doc/lush.txt
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ Supports the following keys:
underdash: boolean, enables or disables underdash.
underdashed: boolean, underdash in nvim 0.8
strikethrough: boolean, enables or disables strikethrough.
altfont: boolean, enables or disables alternate font in nvim 0.9
reverse: boolean, enables or disables flipping fg and bg values.
standout: boolean, enables or disables standout.
nocombine: boolean, enables or disables nocombine.
Expand Down
5 changes: 2 additions & 3 deletions lua/lush/compiler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,15 @@ local function normal_group_to_attrs(group_def)
local formatters = {
"bold", "italic", "underline", "underlineline",
"undercurl", "underdot", "underdash", "strikethrough",
-- https://github.com/rktjmp/lush.nvim/issues/96
-- 0.8 key renames
"underdouble", "underdotted", "underdashed",
"reverse", "standout", "nocombine"
"reverse", "standout", "nocombine", "altfont"
}
for i, formatter in ipairs(formatters) do
attrs[formatter] = maybe_set(formatter)
end
end

-- TODO: there is ambiguity here, where a user may give { gui="italic" italic=false }
-- now re-merge any extra attrs which may override gui settings
for key, value in pairs(extra_attrs) do
attrs[key] = value
Expand Down
5 changes: 2 additions & 3 deletions lua/lush/parser.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,14 @@ local function allowed_option_keys()
return {
-- could be any value
"fg", "bg", "sp",
"gui", -- should be a string
"gui", -- string
"blend", -- integer
-- booleans
"bold", "italic", "underline", "underlineline",
"undercurl", "underdot", "underdash", "strikethrough",
"reverse", "standout", "nocombine",
-- https://github.com/rktjmp/lush.nvim/issues/96
-- 0.8 key renames
"underdouble", "underdotted", "underdashed",
"altfont",
-- lush special namespace
"lush"
}
Expand Down
5 changes: 2 additions & 3 deletions lua/shipwright/transform/lush/to_vimscript.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,9 @@ local function make_group(group_name, group_spec)
local formatters = {
"bold", "italic", "underline", "underlineline",
"undercurl", "underdot", "underdash", "strikethrough",
-- https://github.com/rktjmp/lush.nvim/issues/96
-- 0.8 key renames
"underdouble", "underdotted", "underdashed",
"reverse", "standout", "nocombine"
"reverse", "standout", "nocombine",
"altfont"
}
for _, key in ipairs(formatters) do
if group_spec[key] then
Expand Down
14 changes: 14 additions & 0 deletions spec/compiler/compiler_spec.moon
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@ describe "compiler", ->
assert.is_equal(true, compiled.B.bold)
assert.is_equal(true, compiled.B.italic)

it "will extract both gui='' and direct properties", ->
ast = parse -> {
A { bg: "a_bg", fg: "a_fg", bold: true, gui: "bold,altfont,italic"},
}
compiled = compile(ast)
assert.is_not_nil(compiled.A)
assert.is_equal(compiled.A.bg, "a_bg")
assert.is_equal(compiled.A.fg, "a_fg")
-- compiled output should not have the gui field
assert.is_equal(compiled.A.gui, nil)
assert.is_equal(compiled.A.bold, true)
assert.is_equal(compiled.A.altfont, true)
assert.is_equal(compiled.A.italic, true)

it "defines a link group", ->
ast = parse -> {
A { bg: "a_bg", fg: "a_fg" }
Expand Down
14 changes: 14 additions & 0 deletions spec/parser/parser_spec.moon
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,20 @@ describe "parser", ->
assert.is_equal(s.A.bg, "a_bg")
assert.is_equal(s.A.fg, "a_fg")

it "will parse both gui='' and direct properties", ->
s = parse -> {
A { bg: "a_bg", fg: "a_fg", bold: true, gui: "bold,altfont"},
}
assert.is_not_nil(s.A)
assert.is_equal(s.A.bg, "a_bg")
assert.is_equal(s.A.fg, "a_fg")
assert.is_equal(s.A.gui, "bold,altfont")
assert.is_equal(s.A.bold, true)
-- altfont is NOT given as a prop, so its nil until the compiler extracts
-- from the gui field. We do not extract in the parser stage as other
-- groups may expect the field to be indexable.
assert.is_equal(s.A.altfont, nil)

it "should only keep keys on allowed keys list", ->
s = parse -> {
A { bg: "a_bg", fg: "a_fg", lush: "abc", not_lush: "xyz", sp: "a_sp", blend: "20"},
Expand Down

0 comments on commit 5337450

Please sign in to comment.