GQBUV2XOMEPMTXMPCBQWGGIUXGQDX77VTGPFIG6YT7G64ASOYHXQC CZY3IDERLI6MTKKKMX6QLLERSPM2ZJ57NGQRKILJBM7S5PYPQ3XAC BB4JL5NTURTH4VDDUOUYNM66GJX3VMNNDE4FFK47CV6SN2YEN4ZQC UH4YWHW5NDKNR7RS664UG4PRJNZIPNWAD5JWBEUB22JHOY2SWZKAC CE4LZV4TNXJT54CVGM3QANCBP42TMLMZWF2DBSMUYKAHILXIZEMQC OTIBCAUJ3KDQJLVDN3A536DLZGNRYMGJLORZVR3WLCGXGO6UGO6AC DGMHQDVOII6WF2OJNHP42AYYMCMAIM266I3KHED74OBYMIWWAQXQC R5QXEHUIZLELJGGCZAE7ATNS3CLRJ7JFRENMGH4XXH24C5WABZDQC endfunction handle_command_palette_keychord(chord, key)if chord == 'escape' thenDisplay_settings.mode = nilelseif chord == 'backspace' thenlocal len = utf8.len(Display_settings.palette)local byte_offset = Text.offset(Display_settings.palette, len)Display_settings.palette = string.sub(Display_settings.palette, 1, byte_offset-1)Display_settings.palette_text = App.newText(love.graphics.getFont(), Display_settings.palette)elseif chord == 'return' then-- TODO: handle search commandlocal candidates = candidates()if #candidates > 0 then-- TODOprint(candidates[1])endDisplay_settings.mode = nilendendfunction draw_command_palette()local pwidth,pheight = 400, 300local left = math.max(App.screen.width/2-pwidth/2, 0)local top = math.max(App.screen.height/2-pheight/2, 0)local width = math.min(pwidth, App.screen.width)local height = math.min(pheight, App.screen.height)-- backgroundApp.color(Command_palette_background_color)love.graphics.rectangle('fill', left, top, width, height, 10, 10) -- rounded cornersApp.color(Command_palette_border_color)love.graphics.rectangle('line', left, top, width, height, 10, 10) -- rounded cornerslove.graphics.line(left, top+5+Line_height+5, left+width, top+5+Line_height+5)-- input boxApp.color(Command_palette_command_color)draw_palette_input(left+10, top+5)-- alternativesApp.color(Command_palette_alternatives_color)local y = top+5+Line_height+5+5for _,cmd in ipairs(candidates()) dolove.graphics.print(cmd, left+5,y)y = y+Line_heightif y >= top+height thenbreakendendendfunction draw_palette_input(x, y)love.graphics.draw(Display_settings.palette_text, x,y)x = x+App.width(Display_settings.palette_text)draw_cursor(x, y)endfunction draw_cursor(x, y)-- blink every 0.5sif math.floor(Cursor_time*2)%2 == 0 thenApp.color(Cursor_color)love.graphics.rectangle('fill', x,y, 3,Line_height)endendfunction candidates()if Display_settings.palette == '' thenreturn Commandselseif Display_settings.palette:sub(1,1) == '/' thenreturn {}elselocal results = filter_candidates(Commands, Display_settings.palette)append(results, file_candidates(Display_settings.palette))return resultsend
function filter_candidates(candidates, prefix)local result = {}for _,cand in ipairs(candidates) doif cand:find(prefix) == 1 thentable.insert(result, cand)endendreturn resultendfunction file_candidates(prefix)local path = Directorylocal dir = dirname(prefix)local visible_dir = dirif dir ~= './' thenpath = path..'/'..direlsevisible_dir = ''endlocal files = love.filesystem.getDirectoryItems(path)local base = basename(prefix)return concat_all(visible_dir, filter_candidates(reorder(path, files), base))endfunction reorder(dir, files)local result = {}local info = {}for _,file in ipairs(files) doinfo[file] = love.filesystem.getInfo(dir..'/'..file)end-- files before directoriesfor _,file in ipairs(files) doif info[file].type ~= 'directory' thentable.insert(result, file)endendfor _,file in ipairs(files) doif info[file].type == 'directory' thentable.insert(result, file..'/')endendreturn resultend
function handle_command_palette_keychord(chord, key)if chord == 'escape' thenDisplay_settings.mode = nilelseif chord == 'backspace' thenlocal len = utf8.len(Display_settings.palette)local byte_offset = Text.offset(Display_settings.palette, len)Display_settings.palette = string.sub(Display_settings.palette, 1, byte_offset-1)Display_settings.palette_text = App.newText(love.graphics.getFont(), Display_settings.palette)elseif chord == 'return' then-- TODO: handle search commandlocal candidates = candidates()if #candidates > 0 then-- TODOprint(candidates[1])endDisplay_settings.mode = nilendendfunction draw_command_palette()local pwidth,pheight = 400, 300local left = math.max(App.screen.width/2-pwidth/2, 0)local top = math.max(App.screen.height/2-pheight/2, 0)local width = math.min(pwidth, App.screen.width)local height = math.min(pheight, App.screen.height)-- backgroundApp.color(Command_palette_background_color)love.graphics.rectangle('fill', left, top, width, height, 10, 10) -- rounded cornersApp.color(Command_palette_border_color)love.graphics.rectangle('line', left, top, width, height, 10, 10) -- rounded cornerslove.graphics.line(left, top+5+Line_height+5, left+width, top+5+Line_height+5)-- input boxApp.color(Command_palette_command_color)draw_palette_input(left+10, top+5)-- alternativesApp.color(Command_palette_alternatives_color)local y = top+5+Line_height+5+5for _,cmd in ipairs(candidates()) dolove.graphics.print(cmd, left+5,y)y = y+Line_heightif y >= top+height thenbreakendendendfunction draw_palette_input(x, y)love.graphics.draw(Display_settings.palette_text, x,y)x = x+App.width(Display_settings.palette_text)draw_cursor(x, y)endfunction draw_cursor(x, y)-- blink every 0.5sif math.floor(Cursor_time*2)%2 == 0 thenApp.color(Cursor_color)love.graphics.rectangle('fill', x,y, 3,Line_height)endendfunction candidates()if Display_settings.palette == '' thenreturn Commandselseif Display_settings.palette:sub(1,1) == '/' thenreturn {}elselocal results = filter_candidates(Commands, Display_settings.palette)append(results, file_candidates(Display_settings.palette))return resultsendendfunction filter_candidates(candidates, prefix)local result = {}for _,cand in ipairs(candidates) doif cand:find(prefix) == 1 thentable.insert(result, cand)endendreturn resultendfunction file_candidates(prefix)local path = Directorylocal dir = dirname(prefix)local visible_dir = dirif dir ~= './' thenpath = path..'/'..direlsevisible_dir = ''endlocal files = love.filesystem.getDirectoryItems(path)local base = basename(prefix)return concat_all(visible_dir, filter_candidates(reorder(path, files), base))endfunction reorder(dir, files)local result = {}local info = {}for _,file in ipairs(files) doinfo[file] = love.filesystem.getInfo(dir..'/'..file)end-- files before directoriesfor _,file in ipairs(files) doif info[file].type ~= 'directory' thentable.insert(result, file)endendfor _,file in ipairs(files) doif info[file].type == 'directory' thentable.insert(result, file..'/')endendreturn resultend