@@ -56,31 +56,54 @@ local pygments_hl_map = {
5656 [" ('OutPromptNum',)" ] = { " @number" , " Number" },
5757}
5858
59- --- @param hl_name string
59+ local prompt_toolkit_hl_map = {
60+ [" readline-like-completions" ] = " Pmenu" ,
61+ [" matching-bracket.other" ] = " MatchParen" ,
62+ [" matching-bracket.cursor" ] = " Cursor" ,
63+
64+ [" completion-menu" ] = " Pmenu" ,
65+ [" completion-menu.completion" ] = " Pmenu" ,
66+ [" completion-menu.completion.current" ] = " PmenuSel" ,
67+ [" completion-menu.meta.completion" ] = " PmenuExtra" ,
68+ [" completion-menu.meta.completion.current" ] = " PmenuExtraSel" ,
69+ [" completion-menu.multi-column-meta" ] = " PmenuExtra" ,
70+
71+ [" completion-toolbar" ] = " Pmenu" ,
72+ [" completion-toolbar.completion.current" ] = " PmenuSel" ,
73+ }
74+
75+ --- @param hl string
6076--- @return string | nil
61- local function style_from_hl (hl_name )
62- local hl = vim .api .nvim_get_hl (0 , {
63- name = hl_name ,
77+ local function pygments_style_from_hl (hl )
78+ local parts = {}
79+ local style = vim .api .nvim_get_hl (0 , {
80+ name = hl ,
6481 link = false ,
6582 })
6683
67- if type (hl .fg ) ~= " number" then
68- return
84+ if style .fg then
85+ parts [# parts + 1 ] = string.format (" fg:#%06x" , style .fg )
86+ end
87+
88+ if style .bg then
89+ parts [# parts + 1 ] = string.format (" bg:#%06x" , style .bg )
6990 end
7091
71- return string.format (" '#%06x'" , hl .fg )
92+ if # parts > 0 then
93+ return table.concat (parts , " " )
94+ end
7295end
7396
7497--- @return string | nil
7598function M .build_pygments_theme ()
7699 local theme = {}
77100
78- for pygments , hls in pairs (pygments_hl_map ) do
101+ for pygments_hls , hls in pairs (pygments_hl_map ) do
79102 -- obtain style from candidates
80103 for _ , hl in ipairs (hls ) do
81- local color = style_from_hl (hl )
82- if color then
83- theme [# theme + 1 ] = string.format (" %s: %s " , pygments , color )
104+ local style = pygments_style_from_hl (hl )
105+ if style then
106+ theme [# theme + 1 ] = string.format (" %s: '%s' " , pygments_hls , style )
84107 break
85108 end
86109 end
@@ -94,4 +117,21 @@ function M.build_pygments_theme()
94117 return " {" .. table.concat (theme , " , " ) .. " }"
95118end
96119
120+ function M .build_prompt_toolkit_theme ()
121+ local theme = {}
122+
123+ for prompt_toolkit_hl , hl in pairs (prompt_toolkit_hl_map ) do
124+ local style = pygments_style_from_hl (hl )
125+ if style then
126+ theme [prompt_toolkit_hl ] = style
127+ end
128+ end
129+
130+ if vim .tbl_isempty (theme ) then
131+ return nil
132+ end
133+
134+ return vim .json .encode (theme )
135+ end
136+
97137return M
0 commit comments