diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2016-06-18 13:09:01 -0400 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2016-06-18 13:09:01 -0400 |
commit | 1e93e24f5e6e36fa89ebbc234b8c91a21ef0b788 (patch) | |
tree | 3f43059e07bad1645712f3355e182dc278f0b779 | |
parent | cbda7d85f867d3786d7f2cc7dd5e22c3575285a4 (diff) | |
parent | abeb2f020fe5cd265b8098d5fe000ca0ec20dcfe (diff) | |
download | rneovim-1e93e24f5e6e36fa89ebbc234b8c91a21ef0b788.tar.gz rneovim-1e93e24f5e6e36fa89ebbc234b8c91a21ef0b788.tar.bz2 rneovim-1e93e24f5e6e36fa89ebbc234b8c91a21ef0b788.zip |
Merge #4851
-rw-r--r-- | src/nvim/syntax.c | 17 | ||||
-rw-r--r-- | test/functional/terminal/highlight_spec.lua | 39 | ||||
-rw-r--r-- | test/functional/ui/highlight_spec.lua | 1 |
3 files changed, 48 insertions, 9 deletions
diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 9e4dc0204f..05141eaf1e 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -6952,8 +6952,23 @@ highlight_color ( else if (!(TOLOWER_ASC(what[0]) == 'b' && TOLOWER_ASC(what[1]) == 'g')) return NULL; if (modec == 'g') { - if (fg) + if (what[2] == '#' && ui_rgb_attached()) { + if (fg) { + n = HL_TABLE()[id - 1].sg_rgb_fg; + } else if (sp) { + n = HL_TABLE()[id - 1].sg_rgb_sp; + } else { + n = HL_TABLE()[id - 1].sg_rgb_bg; + } + if (n < 0 || n > 0xffffff) { + return NULL; + } + snprintf((char *)name, sizeof(name), "#%06x", n); + return name; + } + if (fg) { return HL_TABLE()[id - 1].sg_rgb_fg_name; + } if (sp) { return HL_TABLE()[id - 1].sg_rgb_sp_name; } diff --git a/test/functional/terminal/highlight_spec.lua b/test/functional/terminal/highlight_spec.lua index 8876c68673..8d7c7451d3 100644 --- a/test/functional/terminal/highlight_spec.lua +++ b/test/functional/terminal/highlight_spec.lua @@ -165,24 +165,49 @@ end) describe('synIDattr()', function() local screen - before_each(function() clear() screen = Screen.new(50, 7) - execute('highlight Normal ctermfg=1 guifg=#ff0000') + execute('highlight Normal ctermfg=252 guifg=#ff0000 guibg=Black') + -- Salmon #fa8072 Maroon #800000 + execute('highlight Keyword ctermfg=79 guifg=Salmon guisp=Maroon') + end) + + it('returns cterm-color if RGB-capable UI is _not_ attached', function() + eq('252', eval('synIDattr(hlID("Normal"), "fg")')) + eq('252', eval('synIDattr(hlID("Normal"), "fg#")')) + eq('-1', eval('synIDattr(hlID("Normal"), "bg")')) + eq('-1', eval('synIDattr(hlID("Normal"), "bg#")')) + eq('79', eval('synIDattr(hlID("Keyword"), "fg")')) + eq('79', eval('synIDattr(hlID("Keyword"), "fg#")')) + eq('', eval('synIDattr(hlID("Keyword"), "sp")')) + eq('', eval('synIDattr(hlID("Keyword"), "sp#")')) end) - after_each(function() - screen:detach() + it('returns gui-color if "gui" arg is passed', function() + eq('Black', eval('synIDattr(hlID("Normal"), "bg", "gui")')) + eq('Maroon', eval('synIDattr(hlID("Keyword"), "sp", "gui")')) + end) + + it('returns gui-color if RGB-capable UI is attached', function() + screen:attach(true) + eq('#ff0000', eval('synIDattr(hlID("Normal"), "fg")')) + eq('Black', eval('synIDattr(hlID("Normal"), "bg")')) + eq('Salmon', eval('synIDattr(hlID("Keyword"), "fg")')) + eq('Maroon', eval('synIDattr(hlID("Keyword"), "sp")')) end) - it('returns RGB number if GUI', function() + it('returns #RRGGBB value for fg#/bg#/sp#', function() screen:attach(true) - eq('#ff0000', eval('synIDattr(hlID("Normal"), "fg")')) + eq('#ff0000', eval('synIDattr(hlID("Normal"), "fg#")')) + eq('#000000', eval('synIDattr(hlID("Normal"), "bg#")')) + eq('#fa8072', eval('synIDattr(hlID("Keyword"), "fg#")')) + eq('#800000', eval('synIDattr(hlID("Keyword"), "sp#")')) end) it('returns color number if non-GUI', function() screen:attach(false) - eq('1', eval('synIDattr(hlID("Normal"), "fg")')) + eq('252', eval('synIDattr(hlID("Normal"), "fg")')) + eq('79', eval('synIDattr(hlID("Keyword"), "fg")')) end) end) diff --git a/test/functional/ui/highlight_spec.lua b/test/functional/ui/highlight_spec.lua index b156f13885..6ef40fff62 100644 --- a/test/functional/ui/highlight_spec.lua +++ b/test/functional/ui/highlight_spec.lua @@ -38,7 +38,6 @@ describe('manual syntax highlight', function() os.remove('Xtest-functional-ui-highlight.tmp.vim') end) - -- test with "set hidden" even if the bug did not occur this way it("works with buffer switch and 'hidden'", function() execute('e tmp1.vim') execute('e Xtest-functional-ui-highlight.tmp.vim') |