Merge pensieve.love

This commit is contained in:
Kartik K. Agaram 2024-03-01 19:22:04 -08:00
commit a77ba7852e
3 changed files with 74 additions and 81 deletions

View File

@ -131,7 +131,7 @@ function draw_menu_bar()
love.graphics.rectangle('fill', 0,0, App.screen.width, Menu_status_bar_height)
App.color(Menu_border_color)
love.graphics.rectangle('line', 0,0, App.screen.width, Menu_status_bar_height)
if Display_settings.show_palette then
if Display_settings.palette then
-- TODO: continue to put shortcuts on the menu bar, enter commands/search strings one row down
return
end
@ -197,41 +197,37 @@ end
function keychord_press_on_command_palette(chord, key)
if chord == 'escape' then
-- forget text for next command
Display_settings.palette_command = ''
Display_settings.show_palette = false
Display_settings.palette_alternative_index = 1
Display_settings.palette_candidates = nil
Display_settings.palette = nil
elseif chord == 'backspace' then
local len = utf8.len(Display_settings.palette_command)
local byte_offset = Text.offset(Display_settings.palette_command, len)
Display_settings.palette_command = string.sub(Display_settings.palette_command, 1, byte_offset-1)
Display_settings.palette_alternative_index = 1
Display_settings.palette_candidates = candidates()
local len = utf8.len(Display_settings.palette.command)
local byte_offset = Text.offset(Display_settings.palette.command, len)
Display_settings.palette.command = string.sub(Display_settings.palette.command, 1, byte_offset-1)
Display_settings.palette.alternative_index = 1
Display_settings.palette.candidates = candidates()
elseif chord == 'tab' then
-- select top candidate, but don't submit
local candidates = Display_settings.palette_candidates
Display_settings.palette_command = command_string(candidates[Display_settings.palette_alternative_index])
local p = Display_settings.palette
p.command = command_string(p.candidates[p.alternative_index])
elseif chord == 'C-v' then
Display_settings.palette_command = Display_settings.palette_command..App.get_clipboard()
Display_settings.palette_candidates = candidates()
local p = Display_settings.palette
p.command = p.command..App.get_clipboard()
p.candidates = candidates()
elseif chord == 'return' then
-- submit selected candidate
local candidates = Display_settings.palette_candidates
if #candidates > 0 then
if file_exists(Directory..candidates[Display_settings.palette_alternative_index]) then
command.open_file_in_next_column(candidates[Display_settings.palette_alternative_index])
local p = Display_settings.palette
local candidates = Display_settings.palette.candidates
if #p.candidates > 0 then
if file_exists(Directory..p.candidates[p.alternative_index]) then
command.open_file_in_next_column(p.candidates[p.alternative_index])
else
run_command(command_string(candidates[Display_settings.palette_alternative_index]))
run_command(command_string(p.candidates[p.alternative_index]))
end
else
-- try to run the command as if it contains args
run_command_with_args(Display_settings.palette_command)
run_command_with_args(p.command)
end
-- forget text for next command
Display_settings.palette_command = ''
Display_settings.show_palette = false
Display_settings.palette_alternative_index = 1
Display_settings.palette_candidates = nil
Display_settings.palette = nil
-- clean up some columns if possible
if Cursor_pane.col < 45 then
while #Surface > 50 do
@ -240,20 +236,20 @@ function keychord_press_on_command_palette(chord, key)
end
end
elseif chord == 'up' then
if Display_settings.palette_alternative_index > 1 then
Display_settings.palette_alternative_index = Display_settings.palette_alternative_index-1
if Display_settings.palette.alternative_index > 1 then
Display_settings.palette.alternative_index = Display_settings.palette.alternative_index-1
end
elseif chord == 'down' then
if Display_settings.palette_alternative_index < #Display_settings.palette_candidates then
Display_settings.palette_alternative_index = Display_settings.palette_alternative_index+1
if Display_settings.palette.alternative_index < #Display_settings.palette.candidates then
Display_settings.palette.alternative_index = Display_settings.palette.alternative_index+1
end
elseif chord == 'left' then
if Display_settings.palette_alternative_index > Palette_alternatives_height then
Display_settings.palette_alternative_index = Display_settings.palette_alternative_index-Palette_alternatives_height
if Display_settings.palette.alternative_index > Palette_alternatives_height then
Display_settings.palette.alternative_index = Display_settings.palette.alternative_index-Palette_alternatives_height
end
elseif chord == 'right' then
if Display_settings.palette_alternative_index <= #Display_settings.palette_candidates-Palette_alternatives_height then
Display_settings.palette_alternative_index = Display_settings.palette_alternative_index+Palette_alternatives_height
if Display_settings.palette.alternative_index <= #Display_settings.palette.candidates-Palette_alternatives_height then
Display_settings.palette.alternative_index = Display_settings.palette.alternative_index+Palette_alternatives_height
end
end
end
@ -278,8 +274,8 @@ function draw_command_palette()
App.color(Command_palette_border_color)
love.graphics.rectangle('line', 0, Menu_status_bar_height, App.screen.width, 5+Palette_alternatives_height*Line_height+5)
Palette_cursor = {y=Menu_status_bar_height+5, x=5, nextx=5}
for i,cmd in ipairs(Display_settings.palette_candidates) do
add_command_to_palette(cmd, i == Display_settings.palette_alternative_index)
for i,cmd in ipairs(Display_settings.palette.candidates) do
add_command_to_palette(cmd, i == Display_settings.palette.alternative_index)
end
end
@ -332,8 +328,8 @@ function add_command_to_palette(s, cursor_highlight)
end
function draw_palette_input(x, y)
love.graphics.print(Display_settings.palette_command, x,y)
x = x+Display_settings.font:getWidth(Display_settings.palette_command)
love.graphics.print(Display_settings.palette.command, x,y)
x = x+Display_settings.font:getWidth(Display_settings.palette.command)
draw_cursor(x, y)
end
@ -348,14 +344,14 @@ end
function candidates()
-- slight context-sensitive tweaks
local candidates = initial_candidates()
if Display_settings.palette_command == '' then
if Display_settings.palette.command == '' then
return candidates
elseif Display_settings.palette_command:sub(1,1) == '/' then
elseif Display_settings.palette.command:sub(1,1) == '/' then
return {}
else
local results = filter_candidates(candidates, Display_settings.palette_command)
local results = filter_candidates(candidates, Display_settings.palette.command)
if Display_settings.mode == 'normal' then
append(results, file_candidates(Display_settings.palette_command))
append(results, file_candidates(Display_settings.palette.command))
end
return results
end
@ -909,14 +905,14 @@ end
function resume_search_all()
-- make a little more progress towards searching the whole disk
if Display_settings.search_all_state == nil then
if Display_settings.search_all_progress == nil then
Display_settings.search_all_progress_indicator = 'initialized top-level files'
Display_settings.search_all_state = {
Display_settings.search_all_progress = {
top_level_files = App.files(Directory),
top_level_file_index = 1,
}
elseif Display_settings.search_all_state.top_level_file_index then
local current_filename = Display_settings.search_all_state.top_level_files[Display_settings.search_all_state.top_level_file_index]
elseif Display_settings.search_all_progress.top_level_file_index then
local current_filename = Display_settings.search_all_progress.top_level_files[Display_settings.search_all_progress.top_level_file_index]
Display_settings.search_all_progress_indicator = current_filename
if current_filename ~= 'search' and current_filename ~= 'config' and current_filename ~= 'recent' then -- ignore some housekeeping files for pensieve.love
local info = App.file_info(Directory..current_filename)
@ -924,20 +920,20 @@ function resume_search_all()
search_in_file(current_filename)
end
end
Display_settings.search_all_state.top_level_file_index = Display_settings.search_all_state.top_level_file_index+1
if Display_settings.search_all_state.top_level_file_index > #Display_settings.search_all_state.top_level_files then
Display_settings.search_all_state.top_level_file_index = nil
Display_settings.search_all_state.top_level_files = nil
Display_settings.search_all_state.time = os.time()
Display_settings.search_all_state.year = os.date('%Y', Display_settings.search_all_state.time)
Display_settings.search_all_state.date = os.date('%Y/%m/%d/', Display_settings.search_all_state.time)
Display_settings.search_all_progress.top_level_file_index = Display_settings.search_all_progress.top_level_file_index+1
if Display_settings.search_all_progress.top_level_file_index > #Display_settings.search_all_progress.top_level_files then
Display_settings.search_all_progress.top_level_file_index = nil
Display_settings.search_all_progress.top_level_files = nil
Display_settings.search_all_progress.time = os.time()
Display_settings.search_all_progress.year = os.date('%Y', Display_settings.search_all_progress.time)
Display_settings.search_all_progress.date = os.date('%Y/%m/%d/', Display_settings.search_all_progress.time)
end
elseif Display_settings.search_all_state.date then
elseif Display_settings.search_all_progress.date then
-- search one day's directory per frame
-- stop when a whole year is missing
Display_settings.search_all_progress_indicator = Display_settings.search_all_state.date
local old_year = Display_settings.search_all_state.year
local date_dir = Directory..Display_settings.search_all_state.date
Display_settings.search_all_progress_indicator = Display_settings.search_all_progress.date
local old_year = Display_settings.search_all_progress.year
local date_dir = Directory..Display_settings.search_all_progress.date
local info = App.file_info(date_dir)
if info then
if info.type == 'directory' then
@ -947,18 +943,18 @@ function resume_search_all()
-- I often have other stuff here that's a lot larger (email).
if filename:match('^%d%d%-%d%d%-%d%d$') then
--? print(date_dir..filename)
search_in_file(Display_settings.search_all_state.date..filename)
search_in_file(Display_settings.search_all_progress.date..filename)
end
end
end
end
Display_settings.search_all_state.time = Display_settings.search_all_state.time - 24*60*60
Display_settings.search_all_state.year = os.date('%Y', Display_settings.search_all_state.time)
Display_settings.search_all_state.date = os.date('%Y/%m/%d/', Display_settings.search_all_state.time)
if old_year ~= Display_settings.search_all_state.year then
local previous_year_info = App.file_info(Directory..Display_settings.search_all_state.year)
Display_settings.search_all_progress.time = Display_settings.search_all_progress.time - 24*60*60
Display_settings.search_all_progress.year = os.date('%Y', Display_settings.search_all_progress.time)
Display_settings.search_all_progress.date = os.date('%Y/%m/%d/', Display_settings.search_all_progress.time)
if old_year ~= Display_settings.search_all_progress.year then
local previous_year_info = App.file_info(Directory..Display_settings.search_all_progress.year)
if previous_year_info == nil then
Display_settings.search_all_state = nil
Display_settings.search_all_progress = nil
Display_settings.mode = 'normal'
end
end
@ -1009,14 +1005,14 @@ function find_previous_byte(s, b, index)
end
function interrupt_search_all()
if Display_settings.search_all_state then
if Display_settings.search_all_progress then
local outfilename = Directory..'search'
local success, errmsg = append_to_file(outfilename, 'interrupted at '..Display_settings.search_all_progress_indicator..'\n')
if not success then error(errmsg) end
load_from_disk(Display_settings.search_all_pane)
Text.redraw_all(Display_settings.search_all_pane)
end
Display_settings.search_all_state = nil
Display_settings.search_all_progress = nil
Display_settings.mode = 'normal'
end

29
run.lua
View File

@ -71,14 +71,13 @@ function run.initialize_globals()
x=0, y=0, -- <==== Top-left corner of the viewport into the surface
column_width=400,
show_debug=false,
show_palette=false,
palette_command='',
palette_alternative_index=1, palette_candidates=nil,
palette=nil, -- {command='', alternative_index=1, candidates=nil}
search_term='',
search_backup_x=nil, search_backup_y=nil, search_backup_cursor_pane=nil,
search_all_query=nil, search_all_terms=nil,
search_all_progress=nil,
search_all_progress_indicator=nil,
search_all_pane=nil, search_all_state=nil,
search_all_pane=nil,
}
-- display settings that are constants
Font_filename = 'NotoSansJP-Regular.otf' -- in current directory
@ -458,7 +457,7 @@ function run.draw()
if Display_settings.mode == 'search_all' or Display_settings.mode == 'searching_all' then
draw_command_palette_for_search_all()
else
if Display_settings.show_palette then
if Display_settings.palette then
draw_command_palette()
else
show_error()
@ -597,7 +596,7 @@ function run.update(dt)
edit.update(pane, dt)
end
end
if not Display_settings.show_palette and (Display_settings.mode == 'normal' or Display_settings.mode == 'search') and App.mouse_down(1) then
if not Display_settings.palette and (Display_settings.mode == 'normal' or Display_settings.mode == 'search') and App.mouse_down(1) then
-- pan the surface by dragging
plan_draw()
end
@ -818,10 +817,10 @@ function run.text_input(t)
Cursor_time = 0 -- ensure cursor is visible immediately after it moves
--? print('textinput', t)
-- hotkeys operating on the cursor pane
if Display_settings.show_palette then
Display_settings.palette_command = Display_settings.palette_command..t
Display_settings.palette_alternative_index = 1
Display_settings.palette_candidates = candidates()
if Display_settings.palette then
Display_settings.palette.command = Display_settings.palette.command..t
Display_settings.palette.alternative_index = 1
Display_settings.palette.candidates = candidates()
elseif Display_settings.mode == 'normal' then
if Cursor_pane.col >= 1 then
local pane = Surface[Cursor_pane.col][Cursor_pane.row]
@ -894,12 +893,11 @@ function run.keychord_press(chord, key)
elseif chord == 'C-0' then
update_font_settings(20)
-- mode-specific hotkeys
elseif Display_settings.show_palette then
elseif Display_settings.palette then
keychord_press_on_command_palette(chord, key)
elseif Display_settings.mode == 'normal' then
if chord == 'C-return' then
Display_settings.show_palette = true
Display_settings.palette_candidates = candidates()
Display_settings.palette = {command='', alternative_index=1, candidates = initial_candidates()}
elseif chord == 'C-f' then
command.commence_find_on_surface()
elseif Cursor_pane.col >= 1 then
@ -944,8 +942,7 @@ function run.keychord_press(chord, key)
interrupt_search_all()
elseif Display_settings.mode == 'maximize' then
if chord == 'C-return' then
Display_settings.show_palette = true
Display_settings.palette_candidates = candidates()
Display_settings.palette = {command='', alternative_index=1, candidates = initial_candidates()}
else
keychord_press_in_maximize_mode(chord, key)
end
@ -1392,7 +1389,7 @@ function keychord_press_in_search_all_mode(chord, key)
if chord == 'escape' then
Display_settings.mode = 'normal'
-- don't forget search text
Display_settings.search_all_state = nil
Display_settings.search_all_progress = nil
elseif chord == 'return' then
finalize_search_all_pane()
add_search_all_pane_to_right_of_cursor()

View File

@ -94,7 +94,7 @@ function Text.draw_cursor(State, x, y, force)
if not State.editable and not force then
return
end
if Display_settings.show_palette then return end
if Display_settings.palette then return end
-- blink every 0.5s
if math.floor(Cursor_time*2)%2 == 0 then
App.color(Cursor_color)