Merge pensieve.love
This commit is contained in:
commit
a77ba7852e
124
commands.lua
124
commands.lua
|
@ -131,7 +131,7 @@ function draw_menu_bar()
|
||||||
love.graphics.rectangle('fill', 0,0, App.screen.width, Menu_status_bar_height)
|
love.graphics.rectangle('fill', 0,0, App.screen.width, Menu_status_bar_height)
|
||||||
App.color(Menu_border_color)
|
App.color(Menu_border_color)
|
||||||
love.graphics.rectangle('line', 0,0, App.screen.width, Menu_status_bar_height)
|
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
|
-- TODO: continue to put shortcuts on the menu bar, enter commands/search strings one row down
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@ -197,41 +197,37 @@ end
|
||||||
function keychord_press_on_command_palette(chord, key)
|
function keychord_press_on_command_palette(chord, key)
|
||||||
if chord == 'escape' then
|
if chord == 'escape' then
|
||||||
-- forget text for next command
|
-- forget text for next command
|
||||||
Display_settings.palette_command = ''
|
Display_settings.palette = nil
|
||||||
Display_settings.show_palette = false
|
|
||||||
Display_settings.palette_alternative_index = 1
|
|
||||||
Display_settings.palette_candidates = nil
|
|
||||||
elseif chord == 'backspace' then
|
elseif chord == 'backspace' then
|
||||||
local len = utf8.len(Display_settings.palette_command)
|
local len = utf8.len(Display_settings.palette.command)
|
||||||
local byte_offset = Text.offset(Display_settings.palette_command, len)
|
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.command = string.sub(Display_settings.palette.command, 1, byte_offset-1)
|
||||||
Display_settings.palette_alternative_index = 1
|
Display_settings.palette.alternative_index = 1
|
||||||
Display_settings.palette_candidates = candidates()
|
Display_settings.palette.candidates = candidates()
|
||||||
elseif chord == 'tab' then
|
elseif chord == 'tab' then
|
||||||
-- select top candidate, but don't submit
|
-- select top candidate, but don't submit
|
||||||
local candidates = Display_settings.palette_candidates
|
local p = Display_settings.palette
|
||||||
Display_settings.palette_command = command_string(candidates[Display_settings.palette_alternative_index])
|
p.command = command_string(p.candidates[p.alternative_index])
|
||||||
elseif chord == 'C-v' then
|
elseif chord == 'C-v' then
|
||||||
Display_settings.palette_command = Display_settings.palette_command..App.get_clipboard()
|
local p = Display_settings.palette
|
||||||
Display_settings.palette_candidates = candidates()
|
p.command = p.command..App.get_clipboard()
|
||||||
|
p.candidates = candidates()
|
||||||
elseif chord == 'return' then
|
elseif chord == 'return' then
|
||||||
-- submit selected candidate
|
-- submit selected candidate
|
||||||
local candidates = Display_settings.palette_candidates
|
local p = Display_settings.palette
|
||||||
if #candidates > 0 then
|
local candidates = Display_settings.palette.candidates
|
||||||
if file_exists(Directory..candidates[Display_settings.palette_alternative_index]) then
|
if #p.candidates > 0 then
|
||||||
command.open_file_in_next_column(candidates[Display_settings.palette_alternative_index])
|
if file_exists(Directory..p.candidates[p.alternative_index]) then
|
||||||
|
command.open_file_in_next_column(p.candidates[p.alternative_index])
|
||||||
else
|
else
|
||||||
run_command(command_string(candidates[Display_settings.palette_alternative_index]))
|
run_command(command_string(p.candidates[p.alternative_index]))
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
-- try to run the command as if it contains args
|
-- 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
|
end
|
||||||
-- forget text for next command
|
-- forget text for next command
|
||||||
Display_settings.palette_command = ''
|
Display_settings.palette = nil
|
||||||
Display_settings.show_palette = false
|
|
||||||
Display_settings.palette_alternative_index = 1
|
|
||||||
Display_settings.palette_candidates = nil
|
|
||||||
-- clean up some columns if possible
|
-- clean up some columns if possible
|
||||||
if Cursor_pane.col < 45 then
|
if Cursor_pane.col < 45 then
|
||||||
while #Surface > 50 do
|
while #Surface > 50 do
|
||||||
|
@ -240,20 +236,20 @@ function keychord_press_on_command_palette(chord, key)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
elseif chord == 'up' then
|
elseif chord == 'up' then
|
||||||
if Display_settings.palette_alternative_index > 1 then
|
if Display_settings.palette.alternative_index > 1 then
|
||||||
Display_settings.palette_alternative_index = Display_settings.palette_alternative_index-1
|
Display_settings.palette.alternative_index = Display_settings.palette.alternative_index-1
|
||||||
end
|
end
|
||||||
elseif chord == 'down' then
|
elseif chord == 'down' then
|
||||||
if Display_settings.palette_alternative_index < #Display_settings.palette_candidates then
|
if Display_settings.palette.alternative_index < #Display_settings.palette.candidates then
|
||||||
Display_settings.palette_alternative_index = Display_settings.palette_alternative_index+1
|
Display_settings.palette.alternative_index = Display_settings.palette.alternative_index+1
|
||||||
end
|
end
|
||||||
elseif chord == 'left' then
|
elseif chord == 'left' then
|
||||||
if Display_settings.palette_alternative_index > Palette_alternatives_height then
|
if Display_settings.palette.alternative_index > Palette_alternatives_height then
|
||||||
Display_settings.palette_alternative_index = Display_settings.palette_alternative_index-Palette_alternatives_height
|
Display_settings.palette.alternative_index = Display_settings.palette.alternative_index-Palette_alternatives_height
|
||||||
end
|
end
|
||||||
elseif chord == 'right' then
|
elseif chord == 'right' then
|
||||||
if Display_settings.palette_alternative_index <= #Display_settings.palette_candidates-Palette_alternatives_height 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
|
Display_settings.palette.alternative_index = Display_settings.palette.alternative_index+Palette_alternatives_height
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -278,8 +274,8 @@ function draw_command_palette()
|
||||||
App.color(Command_palette_border_color)
|
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)
|
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}
|
Palette_cursor = {y=Menu_status_bar_height+5, x=5, nextx=5}
|
||||||
for i,cmd in ipairs(Display_settings.palette_candidates) do
|
for i,cmd in ipairs(Display_settings.palette.candidates) do
|
||||||
add_command_to_palette(cmd, i == Display_settings.palette_alternative_index)
|
add_command_to_palette(cmd, i == Display_settings.palette.alternative_index)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -332,8 +328,8 @@ function add_command_to_palette(s, cursor_highlight)
|
||||||
end
|
end
|
||||||
|
|
||||||
function draw_palette_input(x, y)
|
function draw_palette_input(x, y)
|
||||||
love.graphics.print(Display_settings.palette_command, x,y)
|
love.graphics.print(Display_settings.palette.command, x,y)
|
||||||
x = x+Display_settings.font:getWidth(Display_settings.palette_command)
|
x = x+Display_settings.font:getWidth(Display_settings.palette.command)
|
||||||
draw_cursor(x, y)
|
draw_cursor(x, y)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -348,14 +344,14 @@ end
|
||||||
function candidates()
|
function candidates()
|
||||||
-- slight context-sensitive tweaks
|
-- slight context-sensitive tweaks
|
||||||
local candidates = initial_candidates()
|
local candidates = initial_candidates()
|
||||||
if Display_settings.palette_command == '' then
|
if Display_settings.palette.command == '' then
|
||||||
return candidates
|
return candidates
|
||||||
elseif Display_settings.palette_command:sub(1,1) == '/' then
|
elseif Display_settings.palette.command:sub(1,1) == '/' then
|
||||||
return {}
|
return {}
|
||||||
else
|
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
|
if Display_settings.mode == 'normal' then
|
||||||
append(results, file_candidates(Display_settings.palette_command))
|
append(results, file_candidates(Display_settings.palette.command))
|
||||||
end
|
end
|
||||||
return results
|
return results
|
||||||
end
|
end
|
||||||
|
@ -909,14 +905,14 @@ end
|
||||||
|
|
||||||
function resume_search_all()
|
function resume_search_all()
|
||||||
-- make a little more progress towards searching the whole disk
|
-- 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_progress_indicator = 'initialized top-level files'
|
||||||
Display_settings.search_all_state = {
|
Display_settings.search_all_progress = {
|
||||||
top_level_files = App.files(Directory),
|
top_level_files = App.files(Directory),
|
||||||
top_level_file_index = 1,
|
top_level_file_index = 1,
|
||||||
}
|
}
|
||||||
elseif Display_settings.search_all_state.top_level_file_index then
|
elseif Display_settings.search_all_progress.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]
|
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
|
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
|
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)
|
local info = App.file_info(Directory..current_filename)
|
||||||
|
@ -924,20 +920,20 @@ function resume_search_all()
|
||||||
search_in_file(current_filename)
|
search_in_file(current_filename)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Display_settings.search_all_state.top_level_file_index = Display_settings.search_all_state.top_level_file_index+1
|
Display_settings.search_all_progress.top_level_file_index = Display_settings.search_all_progress.top_level_file_index+1
|
||||||
if Display_settings.search_all_state.top_level_file_index > #Display_settings.search_all_state.top_level_files then
|
if Display_settings.search_all_progress.top_level_file_index > #Display_settings.search_all_progress.top_level_files then
|
||||||
Display_settings.search_all_state.top_level_file_index = nil
|
Display_settings.search_all_progress.top_level_file_index = nil
|
||||||
Display_settings.search_all_state.top_level_files = nil
|
Display_settings.search_all_progress.top_level_files = nil
|
||||||
Display_settings.search_all_state.time = os.time()
|
Display_settings.search_all_progress.time = os.time()
|
||||||
Display_settings.search_all_state.year = os.date('%Y', Display_settings.search_all_state.time)
|
Display_settings.search_all_progress.year = os.date('%Y', Display_settings.search_all_progress.time)
|
||||||
Display_settings.search_all_state.date = os.date('%Y/%m/%d/', Display_settings.search_all_state.time)
|
Display_settings.search_all_progress.date = os.date('%Y/%m/%d/', Display_settings.search_all_progress.time)
|
||||||
end
|
end
|
||||||
elseif Display_settings.search_all_state.date then
|
elseif Display_settings.search_all_progress.date then
|
||||||
-- search one day's directory per frame
|
-- search one day's directory per frame
|
||||||
-- stop when a whole year is missing
|
-- stop when a whole year is missing
|
||||||
Display_settings.search_all_progress_indicator = 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_state.year
|
local old_year = Display_settings.search_all_progress.year
|
||||||
local date_dir = Directory..Display_settings.search_all_state.date
|
local date_dir = Directory..Display_settings.search_all_progress.date
|
||||||
local info = App.file_info(date_dir)
|
local info = App.file_info(date_dir)
|
||||||
if info then
|
if info then
|
||||||
if info.type == 'directory' 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).
|
-- I often have other stuff here that's a lot larger (email).
|
||||||
if filename:match('^%d%d%-%d%d%-%d%d$') then
|
if filename:match('^%d%d%-%d%d%-%d%d$') then
|
||||||
--? print(date_dir..filename)
|
--? 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
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Display_settings.search_all_state.time = Display_settings.search_all_state.time - 24*60*60
|
Display_settings.search_all_progress.time = Display_settings.search_all_progress.time - 24*60*60
|
||||||
Display_settings.search_all_state.year = os.date('%Y', Display_settings.search_all_state.time)
|
Display_settings.search_all_progress.year = os.date('%Y', Display_settings.search_all_progress.time)
|
||||||
Display_settings.search_all_state.date = os.date('%Y/%m/%d/', Display_settings.search_all_state.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_state.year then
|
if old_year ~= Display_settings.search_all_progress.year then
|
||||||
local previous_year_info = App.file_info(Directory..Display_settings.search_all_state.year)
|
local previous_year_info = App.file_info(Directory..Display_settings.search_all_progress.year)
|
||||||
if previous_year_info == nil then
|
if previous_year_info == nil then
|
||||||
Display_settings.search_all_state = nil
|
Display_settings.search_all_progress = nil
|
||||||
Display_settings.mode = 'normal'
|
Display_settings.mode = 'normal'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1009,14 +1005,14 @@ function find_previous_byte(s, b, index)
|
||||||
end
|
end
|
||||||
|
|
||||||
function interrupt_search_all()
|
function interrupt_search_all()
|
||||||
if Display_settings.search_all_state then
|
if Display_settings.search_all_progress then
|
||||||
local outfilename = Directory..'search'
|
local outfilename = Directory..'search'
|
||||||
local success, errmsg = append_to_file(outfilename, 'interrupted at '..Display_settings.search_all_progress_indicator..'\n')
|
local success, errmsg = append_to_file(outfilename, 'interrupted at '..Display_settings.search_all_progress_indicator..'\n')
|
||||||
if not success then error(errmsg) end
|
if not success then error(errmsg) end
|
||||||
load_from_disk(Display_settings.search_all_pane)
|
load_from_disk(Display_settings.search_all_pane)
|
||||||
Text.redraw_all(Display_settings.search_all_pane)
|
Text.redraw_all(Display_settings.search_all_pane)
|
||||||
end
|
end
|
||||||
Display_settings.search_all_state = nil
|
Display_settings.search_all_progress = nil
|
||||||
Display_settings.mode = 'normal'
|
Display_settings.mode = 'normal'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
29
run.lua
29
run.lua
|
@ -71,14 +71,13 @@ function run.initialize_globals()
|
||||||
x=0, y=0, -- <==== Top-left corner of the viewport into the surface
|
x=0, y=0, -- <==== Top-left corner of the viewport into the surface
|
||||||
column_width=400,
|
column_width=400,
|
||||||
show_debug=false,
|
show_debug=false,
|
||||||
show_palette=false,
|
palette=nil, -- {command='', alternative_index=1, candidates=nil}
|
||||||
palette_command='',
|
|
||||||
palette_alternative_index=1, palette_candidates=nil,
|
|
||||||
search_term='',
|
search_term='',
|
||||||
search_backup_x=nil, search_backup_y=nil, search_backup_cursor_pane=nil,
|
search_backup_x=nil, search_backup_y=nil, search_backup_cursor_pane=nil,
|
||||||
search_all_query=nil, search_all_terms=nil,
|
search_all_query=nil, search_all_terms=nil,
|
||||||
|
search_all_progress=nil,
|
||||||
search_all_progress_indicator=nil,
|
search_all_progress_indicator=nil,
|
||||||
search_all_pane=nil, search_all_state=nil,
|
search_all_pane=nil,
|
||||||
}
|
}
|
||||||
-- display settings that are constants
|
-- display settings that are constants
|
||||||
Font_filename = 'NotoSansJP-Regular.otf' -- in current directory
|
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
|
if Display_settings.mode == 'search_all' or Display_settings.mode == 'searching_all' then
|
||||||
draw_command_palette_for_search_all()
|
draw_command_palette_for_search_all()
|
||||||
else
|
else
|
||||||
if Display_settings.show_palette then
|
if Display_settings.palette then
|
||||||
draw_command_palette()
|
draw_command_palette()
|
||||||
else
|
else
|
||||||
show_error()
|
show_error()
|
||||||
|
@ -597,7 +596,7 @@ function run.update(dt)
|
||||||
edit.update(pane, dt)
|
edit.update(pane, dt)
|
||||||
end
|
end
|
||||||
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
|
-- pan the surface by dragging
|
||||||
plan_draw()
|
plan_draw()
|
||||||
end
|
end
|
||||||
|
@ -818,10 +817,10 @@ function run.text_input(t)
|
||||||
Cursor_time = 0 -- ensure cursor is visible immediately after it moves
|
Cursor_time = 0 -- ensure cursor is visible immediately after it moves
|
||||||
--? print('textinput', t)
|
--? print('textinput', t)
|
||||||
-- hotkeys operating on the cursor pane
|
-- hotkeys operating on the cursor pane
|
||||||
if Display_settings.show_palette then
|
if Display_settings.palette then
|
||||||
Display_settings.palette_command = Display_settings.palette_command..t
|
Display_settings.palette.command = Display_settings.palette.command..t
|
||||||
Display_settings.palette_alternative_index = 1
|
Display_settings.palette.alternative_index = 1
|
||||||
Display_settings.palette_candidates = candidates()
|
Display_settings.palette.candidates = candidates()
|
||||||
elseif Display_settings.mode == 'normal' then
|
elseif Display_settings.mode == 'normal' then
|
||||||
if Cursor_pane.col >= 1 then
|
if Cursor_pane.col >= 1 then
|
||||||
local pane = Surface[Cursor_pane.col][Cursor_pane.row]
|
local pane = Surface[Cursor_pane.col][Cursor_pane.row]
|
||||||
|
@ -894,12 +893,11 @@ function run.keychord_press(chord, key)
|
||||||
elseif chord == 'C-0' then
|
elseif chord == 'C-0' then
|
||||||
update_font_settings(20)
|
update_font_settings(20)
|
||||||
-- mode-specific hotkeys
|
-- mode-specific hotkeys
|
||||||
elseif Display_settings.show_palette then
|
elseif Display_settings.palette then
|
||||||
keychord_press_on_command_palette(chord, key)
|
keychord_press_on_command_palette(chord, key)
|
||||||
elseif Display_settings.mode == 'normal' then
|
elseif Display_settings.mode == 'normal' then
|
||||||
if chord == 'C-return' then
|
if chord == 'C-return' then
|
||||||
Display_settings.show_palette = true
|
Display_settings.palette = {command='', alternative_index=1, candidates = initial_candidates()}
|
||||||
Display_settings.palette_candidates = candidates()
|
|
||||||
elseif chord == 'C-f' then
|
elseif chord == 'C-f' then
|
||||||
command.commence_find_on_surface()
|
command.commence_find_on_surface()
|
||||||
elseif Cursor_pane.col >= 1 then
|
elseif Cursor_pane.col >= 1 then
|
||||||
|
@ -944,8 +942,7 @@ function run.keychord_press(chord, key)
|
||||||
interrupt_search_all()
|
interrupt_search_all()
|
||||||
elseif Display_settings.mode == 'maximize' then
|
elseif Display_settings.mode == 'maximize' then
|
||||||
if chord == 'C-return' then
|
if chord == 'C-return' then
|
||||||
Display_settings.show_palette = true
|
Display_settings.palette = {command='', alternative_index=1, candidates = initial_candidates()}
|
||||||
Display_settings.palette_candidates = candidates()
|
|
||||||
else
|
else
|
||||||
keychord_press_in_maximize_mode(chord, key)
|
keychord_press_in_maximize_mode(chord, key)
|
||||||
end
|
end
|
||||||
|
@ -1392,7 +1389,7 @@ function keychord_press_in_search_all_mode(chord, key)
|
||||||
if chord == 'escape' then
|
if chord == 'escape' then
|
||||||
Display_settings.mode = 'normal'
|
Display_settings.mode = 'normal'
|
||||||
-- don't forget search text
|
-- don't forget search text
|
||||||
Display_settings.search_all_state = nil
|
Display_settings.search_all_progress = nil
|
||||||
elseif chord == 'return' then
|
elseif chord == 'return' then
|
||||||
finalize_search_all_pane()
|
finalize_search_all_pane()
|
||||||
add_search_all_pane_to_right_of_cursor()
|
add_search_all_pane_to_right_of_cursor()
|
||||||
|
|
2
text.lua
2
text.lua
|
@ -94,7 +94,7 @@ function Text.draw_cursor(State, x, y, force)
|
||||||
if not State.editable and not force then
|
if not State.editable and not force then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if Display_settings.show_palette then return end
|
if Display_settings.palette then return end
|
||||||
-- blink every 0.5s
|
-- blink every 0.5s
|
||||||
if math.floor(Cursor_time*2)%2 == 0 then
|
if math.floor(Cursor_time*2)%2 == 0 then
|
||||||
App.color(Cursor_color)
|
App.color(Cursor_color)
|
||||||
|
|
Loading…
Reference in New Issue