mirror of
				https://github.com/neovim/neovim.git
				synced 2025-10-26 12:27:24 +00:00 
			
		
		
		
	api/vim: allow guis and tests to retrieve the entire color table
This commit is contained in:
		 Björn Linse
					Björn Linse
				
			
				
					committed by
					
						 Thiago de Arruda
						Thiago de Arruda
					
				
			
			
				
	
			
			
			 Thiago de Arruda
						Thiago de Arruda
					
				
			
						parent
						
							ae2b747e64
						
					
				
				
					commit
					f468fb70cb
				
			| @@ -552,6 +552,18 @@ Integer vim_name_to_color(String name) | ||||
|   return name_to_color((uint8_t *)name.data); | ||||
| } | ||||
|  | ||||
| Dictionary vim_get_color_map(void) | ||||
| { | ||||
|   Dictionary colors = ARRAY_DICT_INIT; | ||||
|  | ||||
|   for (int i = 0; color_name_table[i].name != NULL; i++) { | ||||
|     PUT(colors, color_name_table[i].name, | ||||
|         INTEGER_OBJ(color_name_table[i].color)); | ||||
|   } | ||||
|   return colors; | ||||
| } | ||||
|  | ||||
|  | ||||
| Array vim_get_api_info(uint64_t channel_id) | ||||
| { | ||||
|   Array rv = ARRAY_DICT_INIT; | ||||
|   | ||||
| @@ -7645,14 +7645,8 @@ char_u *get_highlight_name(expand_T *xp, int idx) | ||||
|   return HL_TABLE()[idx].sg_name; | ||||
| } | ||||
|  | ||||
|  | ||||
| RgbValue name_to_color(uint8_t *name) | ||||
| { | ||||
| #define RGB(r, g, b) ((r << 16) | (g << 8) | b) | ||||
|   static struct { | ||||
|     char *name; | ||||
|     RgbValue color; | ||||
|   } color_name_table[] = { | ||||
| color_name_table_T color_name_table[] = { | ||||
|   // Color names taken from | ||||
|   // http://www.rapidtables.com/web/color/RGB_Color.htm | ||||
|   {"Maroon", RGB(0x80, 0x00, 0x00)}, | ||||
| @@ -7822,7 +7816,10 @@ RgbValue name_to_color(uint8_t *name) | ||||
|   {"Gray90", RGB(0xe5, 0xe5, 0xe5)}, | ||||
|   {"Grey90", RGB(0xe5, 0xe5, 0xe5)}, | ||||
|   {NULL, 0}, | ||||
|   }; | ||||
| }; | ||||
|  | ||||
| RgbValue name_to_color(uint8_t *name) | ||||
| { | ||||
|  | ||||
|   if (name[0] == '#' && isxdigit(name[1]) && isxdigit(name[2]) | ||||
|       && isxdigit(name[3]) && isxdigit(name[4]) && isxdigit(name[5]) | ||||
|   | ||||
| @@ -38,6 +38,12 @@ | ||||
| #define HL_CONCEAL     0x20000 /* can be concealed */ | ||||
| #define HL_CONCEALENDS 0x40000 /* can be concealed */ | ||||
|  | ||||
| typedef struct { | ||||
|   char *name; | ||||
|   RgbValue color; | ||||
| } color_name_table_T; | ||||
| extern color_name_table_T color_name_table[]; | ||||
|  | ||||
| #ifdef INCLUDE_GENERATED_DECLARATIONS | ||||
| # include "syntax.h.generated.h" | ||||
| #endif | ||||
|   | ||||
| @@ -29,14 +29,12 @@ end) | ||||
| describe('Default highlight groups', function() | ||||
|   -- Test the default attributes for highlight groups shown by the :highlight | ||||
|   -- command | ||||
|   local screen, hlgroup_colors | ||||
|   local screen | ||||
|  | ||||
|   setup(function() | ||||
|     hlgroup_colors = { | ||||
|       NonText = nvim('name_to_color', 'Blue'), | ||||
|       Question = nvim('name_to_color', 'SeaGreen') | ||||
|   local hlgroup_colors = { | ||||
|     NonText = Screen.colors.Blue, | ||||
|     Question = Screen.colors.SeaGreen | ||||
|   } | ||||
|   end) | ||||
|  | ||||
|   before_each(function() | ||||
|     clear() | ||||
|   | ||||
| @@ -4,14 +4,12 @@ local clear, feed, nvim = helpers.clear, helpers.feed, helpers.nvim | ||||
| local insert, execute = helpers.insert, helpers.execute | ||||
|  | ||||
| describe('Mouse input', function() | ||||
|   local screen, hlgroup_colors | ||||
|   local screen | ||||
|  | ||||
|   setup(function() | ||||
|     hlgroup_colors = { | ||||
|       NonText = nvim('name_to_color', 'Blue'), | ||||
|       Visual = nvim('name_to_color', 'LightGrey'), | ||||
|   local hlgroup_colors = { | ||||
|     NonText = Screen.colors.Blue, | ||||
|     Visual = Screen.colors.LightGrey | ||||
|   } | ||||
|   end) | ||||
|  | ||||
|   before_each(function() | ||||
|     clear() | ||||
|   | ||||
| @@ -65,7 +65,7 @@ | ||||
| -- attribute(which normally is), here's how the call to "expect" should look | ||||
| -- like: | ||||
| -- | ||||
| --     NonText = nvim('name_to_color', 'Blue'), | ||||
| --     NonText = Screen.colors.Blue | ||||
| --     screen:expect([[ | ||||
| --       hello screen             \ | ||||
| --       ~                        \ | ||||
| @@ -86,7 +86,7 @@ | ||||
| -- | ||||
| -- Multiple expect:s will likely share a group of attribute sets to test. | ||||
| -- Therefore these could be specified at the beginning of a test like this: | ||||
| --    NonText = nvim('name_to_color', 'Blue') | ||||
| --    NonText = Screen.colors.Blue | ||||
| --    screen:set_default_attr_ids( { | ||||
| --      [1] = {reverse = true, bold = true}, | ||||
| --      [2] = {reverse = true} | ||||
| @@ -119,6 +119,16 @@ if os.getenv('VALGRIND') then | ||||
|   default_screen_timeout = 7500 | ||||
| end | ||||
|  | ||||
| local colors = request('vim_get_color_map') | ||||
| local colornames = {} | ||||
| for name, rgb in pairs(colors) do | ||||
|     -- we disregard the case that colornames might not be unique, as | ||||
|     -- this is just a helper to get any canonical name of a color | ||||
|     colornames[rgb] = name | ||||
| end | ||||
|  | ||||
| Screen.colors = colors | ||||
|  | ||||
| function Screen.debug(command) | ||||
|   if not command then | ||||
|     command = 'pynvim -n -g -c ' | ||||
| @@ -479,7 +489,13 @@ end | ||||
| function pprint_attrs(attrs) | ||||
|     local items = {} | ||||
|     for f, v in pairs(attrs) do | ||||
|       table.insert(items, f.." = "..tostring(v)) | ||||
|       local desc = tostring(v) | ||||
|       if f == "foreground" or f == "background" then | ||||
|         if colornames[v] ~= nil then | ||||
|           desc = "Screen.colors."..colornames[v] | ||||
|         end | ||||
|       end | ||||
|       table.insert(items, f.." = "..desc) | ||||
|     end | ||||
|     return table.concat(items, ", ") | ||||
| end | ||||
|   | ||||
		Reference in New Issue
	
	Block a user