Skip to content

Commit

Permalink
fix uosc syntax support
Browse files Browse the repository at this point in the history
  • Loading branch information
tsl0922 committed Feb 21, 2024
1 parent f755e3a commit f788120
Showing 1 changed file with 27 additions and 21 deletions.
48 changes: 27 additions & 21 deletions src/lua/dyn_menu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,13 @@ end

-- parse input.conf, return menu items
local function parse_input_conf(conf)
local function parse_line(line)
local c = line:match('^%s*#')
if c and (not o.uosc_syntax) then return end
local key, cmd = line:match('%s*([%S]+)%s+(.-)%s*$')
return ((o.uosc_syntax and c) and '' or key), cmd
end

local function extract_title(cmd)
if not cmd or cmd == '' then return '' end
local title = cmd:match('#menu:%s*(.*)%s*')
Expand Down Expand Up @@ -631,28 +638,27 @@ local function parse_input_conf(conf)
local by_id = {}

for line in conf:gmatch('[^\r\n]+') do
if line:sub(1, 1) ~= '#' or o.uosc_syntax then
local submenu_id = ''
local target_menu = items
local key, cmd = line:match('%s*([%S]+)%s+(.-)%s*$')
local list = split_title(extract_title(cmd))

for id, name in ipairs(list) do
if id < #list then
submenu_id = submenu_id .. name
if not by_id[submenu_id] then
local submenu = {}
by_id[submenu_id] = submenu
append_menu(target_menu, 'submenu', name, nil, submenu)
end
target_menu = by_id[submenu_id]
local key, cmd = parse_line(line)
local list = split_title(extract_title(cmd))

local submenu_id = ''
local target_menu = items

for id, name in ipairs(list) do
if id < #list then
submenu_id = submenu_id .. name
if not by_id[submenu_id] then
local submenu = {}
by_id[submenu_id] = submenu
append_menu(target_menu, 'submenu', name, nil, submenu)
end
target_menu = by_id[submenu_id]
else
if name == '-' or (o.uosc_syntax and name:sub(1, 3) == '---') then
append_menu(target_menu, 'separator')
else
if name == '-' or (o.uosc_syntax and name:sub(1, 3) == '---') then
append_menu(target_menu, 'separator')
else
local title = (key ~= '' and key ~= '_') and (name .. "\t" .. key) or name
append_menu(target_menu, nil, title, cmd)
end
local title = (key ~= '' and key ~= '_') and (name .. "\t" .. key) or name
append_menu(target_menu, nil, title, cmd)
end
end
end
Expand Down

0 comments on commit f788120

Please sign in to comment.