mirror of
				https://github.com/neovim/neovim.git
				synced 2025-11-04 01:34:25 +00:00 
			
		
		
		
	feat(highlight): define the concept of altfont as a (c)term rendering attribute
This commit is contained in:
		@@ -8328,6 +8328,7 @@ synIDattr({synID}, {what} [, {mode}])			*synIDattr()*
 | 
			
		||||
		"underdotted"	"1" if dotted underlined
 | 
			
		||||
		"underdashed"	"1" if dashed underlined
 | 
			
		||||
		"strikethrough"	"1" if struckthrough
 | 
			
		||||
		"altfont"	"1" if alternative font
 | 
			
		||||
		"nocombine"	"1" if nocombine
 | 
			
		||||
 | 
			
		||||
		Returns an empty string on error.
 | 
			
		||||
 
 | 
			
		||||
@@ -149,6 +149,8 @@ The following new APIs or features were added.
 | 
			
		||||
  deterministic, and a `LUA_GEN_PRG` build parameter has been introduced to
 | 
			
		||||
  allow for a workaround for some remaining reproducibility problems.
 | 
			
		||||
 | 
			
		||||
• |:highlight| now supports an additional attribute "altfont".
 | 
			
		||||
 | 
			
		||||
==============================================================================
 | 
			
		||||
CHANGED FEATURES                                                 *news-changes*
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -4958,7 +4958,8 @@ the same syntax file on all UIs.
 | 
			
		||||
					*bold* *underline* *undercurl*
 | 
			
		||||
					*underdouble* *underdotted*
 | 
			
		||||
					*underdashed* *inverse* *italic*
 | 
			
		||||
					*standout* *nocombine* *strikethrough*
 | 
			
		||||
					*standout* *strikethrough* *altfont*
 | 
			
		||||
					*nocombine*
 | 
			
		||||
cterm={attr-list}			*attr-list* *highlight-cterm* *E418*
 | 
			
		||||
	attr-list is a comma-separated list (without spaces) of the
 | 
			
		||||
	following items (in any order):
 | 
			
		||||
@@ -4973,6 +4974,7 @@ cterm={attr-list}			*attr-list* *highlight-cterm* *E418*
 | 
			
		||||
		inverse		same as reverse
 | 
			
		||||
		italic
 | 
			
		||||
		standout
 | 
			
		||||
		altfont
 | 
			
		||||
		nocombine	override attributes instead of combining them
 | 
			
		||||
		NONE		no attributes used (used to reset it)
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -324,6 +324,7 @@ numerical highlight ids to the actual attributes.
 | 
			
		||||
	`underdouble`:		double underlined text. The lines have `special` color.
 | 
			
		||||
	`underdotted`:		underdotted text. The dots have `special` color.
 | 
			
		||||
	`underdashed`:		underdashed text. The dashes have `special` color.
 | 
			
		||||
	`altfont`:		alternative font.
 | 
			
		||||
	`blend`:		Blend level (0-100). Could be used by UIs to
 | 
			
		||||
				support blending floating windows to the
 | 
			
		||||
				background or to signal a transparent cursor.
 | 
			
		||||
 
 | 
			
		||||
@@ -114,6 +114,7 @@ return {
 | 
			
		||||
    "underdashed";
 | 
			
		||||
    "italic";
 | 
			
		||||
    "reverse";
 | 
			
		||||
    "altfont";
 | 
			
		||||
    "nocombine";
 | 
			
		||||
    "default";
 | 
			
		||||
    "cterm";
 | 
			
		||||
@@ -140,6 +141,7 @@ return {
 | 
			
		||||
    "underdashed";
 | 
			
		||||
    "italic";
 | 
			
		||||
    "reverse";
 | 
			
		||||
    "altfont";
 | 
			
		||||
    "nocombine";
 | 
			
		||||
  }};
 | 
			
		||||
  -- Autocmds
 | 
			
		||||
 
 | 
			
		||||
@@ -867,6 +867,10 @@ void hlattrs2dict(Dictionary *dict, HlAttrs ae, bool use_rgb)
 | 
			
		||||
    PUT_C(hl, "strikethrough", BOOLEAN_OBJ(true));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if (mask & HL_ALTFONT) {
 | 
			
		||||
    PUT_C(hl, "altfont", BOOLEAN_OBJ(true));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if (mask & HL_NOCOMBINE) {
 | 
			
		||||
    PUT_C(hl, "nocombine", BOOLEAN_OBJ(true));
 | 
			
		||||
  }
 | 
			
		||||
@@ -932,6 +936,7 @@ HlAttrs dict2hlattrs(Dict(highlight) *dict, bool use_rgb, int *link_id, Error *e
 | 
			
		||||
  CHECK_FLAG(dict, mask, underdashed, , HL_UNDERDASHED);
 | 
			
		||||
  CHECK_FLAG(dict, mask, standout, , HL_STANDOUT);
 | 
			
		||||
  CHECK_FLAG(dict, mask, strikethrough, , HL_STRIKETHROUGH);
 | 
			
		||||
  CHECK_FLAG(dict, mask, altfont, , HL_ALTFONT);
 | 
			
		||||
  if (use_rgb) {
 | 
			
		||||
    CHECK_FLAG(dict, mask, fg_indexed, , HL_FG_INDEXED);
 | 
			
		||||
    CHECK_FLAG(dict, mask, bg_indexed, , HL_BG_INDEXED);
 | 
			
		||||
@@ -1014,6 +1019,7 @@ HlAttrs dict2hlattrs(Dict(highlight) *dict, bool use_rgb, int *link_id, Error *e
 | 
			
		||||
    CHECK_FLAG(cterm, cterm_mask, undercurl, , HL_UNDERCURL);
 | 
			
		||||
    CHECK_FLAG(cterm, cterm_mask, standout, , HL_STANDOUT);
 | 
			
		||||
    CHECK_FLAG(cterm, cterm_mask, strikethrough, , HL_STRIKETHROUGH);
 | 
			
		||||
    CHECK_FLAG(cterm, cterm_mask, altfont, , HL_ALTFONT);
 | 
			
		||||
    CHECK_FLAG(cterm, cterm_mask, nocombine, , HL_NOCOMBINE);
 | 
			
		||||
  } else if (dict->cterm.type == kObjectTypeArray && dict->cterm.data.array.size == 0) {
 | 
			
		||||
    // empty list from Lua API should clear all cterm attributes
 | 
			
		||||
 
 | 
			
		||||
@@ -25,7 +25,8 @@ typedef enum {
 | 
			
		||||
  // 0x30 and 0x38 spare for underline styles
 | 
			
		||||
  HL_STANDOUT      = 0x0040,
 | 
			
		||||
  HL_STRIKETHROUGH = 0x0080,
 | 
			
		||||
  // 0x0100-0x0200 spare
 | 
			
		||||
  HL_ALTFONT       = 0x0100,
 | 
			
		||||
  // 0x0200 spare
 | 
			
		||||
  HL_NOCOMBINE     = 0x0400,
 | 
			
		||||
  HL_BG_INDEXED    = 0x0800,
 | 
			
		||||
  HL_FG_INDEXED    = 0x1000,
 | 
			
		||||
 
 | 
			
		||||
@@ -67,11 +67,13 @@ Map(cstr_t, int) highlight_unames = MAP_INIT;
 | 
			
		||||
static char *(hl_name_table[]) =
 | 
			
		||||
{ "bold", "standout", "underline",
 | 
			
		||||
  "undercurl", "underdouble", "underdotted", "underdashed",
 | 
			
		||||
  "italic", "reverse", "inverse", "strikethrough", "nocombine", "NONE" };
 | 
			
		||||
  "italic", "reverse", "inverse", "strikethrough", "altfont",
 | 
			
		||||
  "nocombine", "NONE" };
 | 
			
		||||
static int hl_attr_table[] =
 | 
			
		||||
{ HL_BOLD, HL_STANDOUT, HL_UNDERLINE,
 | 
			
		||||
  HL_UNDERCURL, HL_UNDERDOUBLE, HL_UNDERDOTTED, HL_UNDERDASHED,
 | 
			
		||||
  HL_ITALIC, HL_INVERSE, HL_INVERSE, HL_STRIKETHROUGH, HL_NOCOMBINE, 0 };
 | 
			
		||||
  HL_ITALIC, HL_INVERSE, HL_INVERSE, HL_STRIKETHROUGH, HL_ALTFONT,
 | 
			
		||||
  HL_NOCOMBINE, 0 };
 | 
			
		||||
 | 
			
		||||
/// Structure that stores information about a highlight group.
 | 
			
		||||
/// The ID of a highlight group is also called group ID.  It is the index in
 | 
			
		||||
@@ -1595,7 +1597,12 @@ const char *highlight_has_attr(const int id, const int flag, const int modec)
 | 
			
		||||
    attr = hl_table[id - 1].sg_cterm;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if (flag & HL_UNDERLINE_MASK) {
 | 
			
		||||
    int ul = attr & HL_UNDERLINE_MASK;
 | 
			
		||||
    return ul == flag ? "1" : NULL;
 | 
			
		||||
  } else {
 | 
			
		||||
    return (attr & flag) ? "1" : NULL;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Return color name of the given highlight group
 | 
			
		||||
 
 | 
			
		||||
@@ -33,6 +33,7 @@ describe('API: highlight',function()
 | 
			
		||||
    reverse = true,
 | 
			
		||||
    underline = true,
 | 
			
		||||
    strikethrough = true,
 | 
			
		||||
    altfont = true,
 | 
			
		||||
    nocombine = true,
 | 
			
		||||
  }
 | 
			
		||||
  local expected_undercurl = {
 | 
			
		||||
@@ -61,7 +62,7 @@ describe('API: highlight',function()
 | 
			
		||||
    eq('Invalid highlight id: 30000', string.match(emsg, 'Invalid.*'))
 | 
			
		||||
 | 
			
		||||
    -- Test all highlight properties.
 | 
			
		||||
    command('hi NewHighlight gui=underline,bold,italic,reverse,strikethrough,nocombine')
 | 
			
		||||
    command('hi NewHighlight gui=underline,bold,italic,reverse,strikethrough,altfont,nocombine')
 | 
			
		||||
    eq(expected_rgb2, nvim("get_hl_by_id", hl_id, true))
 | 
			
		||||
 | 
			
		||||
    -- Test undercurl
 | 
			
		||||
@@ -215,10 +216,12 @@ describe("API: set highlight", function()
 | 
			
		||||
    reverse = true,
 | 
			
		||||
    underline = true,
 | 
			
		||||
    strikethrough = true,
 | 
			
		||||
    altfont = true,
 | 
			
		||||
    cterm = {
 | 
			
		||||
      italic = true,
 | 
			
		||||
      reverse = true,
 | 
			
		||||
      strikethrough = true,
 | 
			
		||||
      altfont = true,
 | 
			
		||||
      nocombine = true,
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
@@ -230,6 +233,7 @@ describe("API: set highlight", function()
 | 
			
		||||
    reverse = true,
 | 
			
		||||
    underline = true,
 | 
			
		||||
    strikethrough = true,
 | 
			
		||||
    altfont = true,
 | 
			
		||||
  }
 | 
			
		||||
  local highlight3_result_cterm = {
 | 
			
		||||
    background = highlight_color.ctermbg,
 | 
			
		||||
@@ -237,6 +241,7 @@ describe("API: set highlight", function()
 | 
			
		||||
    italic = true,
 | 
			
		||||
    reverse = true,
 | 
			
		||||
    strikethrough = true,
 | 
			
		||||
    altfont = true,
 | 
			
		||||
    nocombine = true,
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@@ -292,7 +297,7 @@ describe("API: set highlight", function()
 | 
			
		||||
      exec_capture('highlight Test_hl'))
 | 
			
		||||
 | 
			
		||||
    meths.set_hl(0, 'Test_hl2', highlight3_config)
 | 
			
		||||
    eq('Test_hl2       xxx cterm=italic,reverse,strikethrough,nocombine ctermfg=8 ctermbg=15 gui=bold,underline,italic,reverse,strikethrough guifg=#ff0000 guibg=#0032aa',
 | 
			
		||||
    eq('Test_hl2       xxx cterm=italic,reverse,strikethrough,altfont,nocombine ctermfg=8 ctermbg=15 gui=bold,underline,italic,reverse,strikethrough,altfont guifg=#ff0000 guibg=#0032aa',
 | 
			
		||||
      exec_capture('highlight Test_hl2'))
 | 
			
		||||
 | 
			
		||||
    -- Colors are stored with the name they are defined, but
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user