Merge lines.love
[?]
Sep 4, 2022, 12:24 AM
AKZWDWIAC7OAPT563CPQK7GHLOVEMAPCFT3XAUGVKI5KGYBMPGXQCDependencies
- [2]
DCO5BQWVMerge lines.love - [3]
X3CQLBTRset window title within each app - [4]
AVTNUQYRbasic test-enabled framework - [5]
VXORMHMEdelete experimental REPL - [6]
3QNOKBFMbeginnings of a test harness - [7]
LXTTOB33extract a couple of files - [8]
VHQCNMARseveral more modules - [9]
BJ5X5O4Alet's prevent the text cursor from ever getting on a drawing - [10]
RSZD5A7Gforgot to add json.lua - [11]
XX7G2FFJintermingle freehand line drawings with text - [12]
T4FRZSYLdelete an ancient, unused file - [13]
AJB4LFRBtry to maintain a reasonable line width - [14]
OGUV4HSAremove some memory leaks from rendered fragments - [15]
4YDBYBA4clean up memory leak experiments - [16]
66X36NZNa little more prose describing manual_tests - [17]
MD3W5IRAnew fork: rip out drawing support - [18]
TVCPXAAUrename - [19]
6LJZN727handle chords - [20]
FS2ITYYHrecord a known issue - [21]
D2GCFTTTclean up repl functionality - [22]
K2X6G75Zstart writing some tests for drawings - [23]
KKMFQDR4editing source code from within the app - [24]
TLOAPLBJadd a license - [25]
JOPVPUSAediting source code from within the app - [26]
BULPIBEGbeginnings of a module for the text editor - [27]
CE4LZV4Tdrop last couple of manual tests - [28]
OTIBCAUJlove2d scaffold - [29]
BLWAYPKVextract a module - [30]
73OCE2MCafter much struggle, a brute-force undo - [31]
2CTN2IEFMerge lines.love - [32]
2L5MEZV3experiment: new edit namespace - [33]
R5QXEHUIsomebody stop me - [34]
32V6ZHQBMerge lines.love - [35]
GUOQRUL7Merge lines.love
Change contents
- file deletion: source.lua source.lua
love.window.setTitle('lines.love - source')end-- a copy of source.filedropped when given a filenamefunction source.switch_to_file(filename)-- first make sure to save edits on any existing fileif Editor_state.next_save thensave_to_disk(Editor_state)end-- clear the slate for the new fileEditor_state.filename = filenameload_from_disk(Editor_state)Text.redraw_all(Editor_state)Editor_state.screen_top1 = {line=1, pos=1}Editor_state.cursor1 = {line=1, pos=1}endfunction source.draw()source.draw_menu_bar()edit.draw(Editor_state)if Show_log_browser_side then-- dividerApp.color(Divider_color)love.graphics.rectangle('fill', App.screen.width/2-1,Menu_status_bar_height, 3,App.screen.height)--log_browser.draw(Log_browser_state)endendfunction source.update(dt)Cursor_time = Cursor_time + dtif App.mouse_x() < Editor_state.right thenedit.update(Editor_state, dt)elseif Show_log_browser_side thenlog_browser.update(Log_browser_state, dt)endendfunction source.quit()edit.quit(Editor_state)log_browser.quit(Log_browser_state)-- convert any bifold files hereendfunction source.convert_bifold_text(infilename, outfilename)local contents = love.filesystem.read(infilename)contents = contents:gsub('\u{1e}', ';')love.filesystem.write(outfilename, contents)endfunction source.settings()if Current_app == 'source' then--? print('reading source window position')Settings.source.x, Settings.source.y, Settings.source.displayindex = love.window.getPosition()endlocal filename = Editor_state.filenameif filename:sub(1,1) ~= '/' thenfilename = love.filesystem.getWorkingDirectory()..'/'..filename -- '/' should work even on Windowsend--? print('saving source settings', Settings.source.x, Settings.source.y, Settings.source.displayindex)return {x=Settings.source.x, y=Settings.source.y, displayindex=Settings.source.displayindex,width=App.screen.width, height=App.screen.height,font_height=Editor_state.font_height,filename=filename,screen_top=Editor_state.screen_top1, cursor=Editor_state.cursor1,show_log_browser_side=Show_log_browser_side,focus=Focus,}endfunction source.mouse_pressed(x,y, mouse_button)Cursor_time = 0 -- ensure cursor is visible immediately after it moves--? print('mouse click', x, y)--? print(Editor_state.left, Editor_state.right)--? print(Log_browser_state.left, Log_browser_state.right)if Editor_state.left <= x and x < Editor_state.right then--? print('click on edit side')if Focus ~= 'edit' thenFocus = 'edit'endedit.mouse_pressed(Editor_state, x,y, mouse_button)elseif Show_log_browser_side and Log_browser_state.left <= x and x < Log_browser_state.right then--? print('click on log_browser side')if Focus ~= 'log_browser' thenFocus = 'log_browser'endlog_browser.mouse_pressed(Log_browser_state, x,y, mouse_button)for _,line_cache in ipairs(Editor_state.line_cache) do line_cache.starty = nil end -- just in case we scrollendendfunction source.mouse_released(x,y, mouse_button)Cursor_time = 0 -- ensure cursor is visible immediately after it movesif Focus == 'edit' thenreturn edit.mouse_released(Editor_state, x,y, mouse_button)elsereturn log_browser.mouse_released(Log_browser_state, x,y, mouse_button)endendfunction source.textinput(t)Cursor_time = 0 -- ensure cursor is visible immediately after it movesif Focus == 'edit' thenreturn edit.textinput(Editor_state, t)elsereturn log_browser.textinput(Log_browser_state, t)endendfunction source.keychord_pressed(chord, key)Cursor_time = 0 -- ensure cursor is visible immediately after it moves--? print('source keychord')if Show_file_navigator thenkeychord_pressed_on_file_navigator(chord, key)returnendif chord == 'C-l' then--? print('C-l')Show_log_browser_side = not Show_log_browser_sideif Show_log_browser_side thenApp.screen.width = Log_browser_state.right + Margin_rightelseApp.screen.width = Editor_state.right + Margin_rightend--? print('setting window:', App.screen.width, App.screen.height)love.window.setMode(App.screen.width, App.screen.height, App.screen.flags)--? print('done setting window')-- try to restore position if possible-- if the window gets wider the window manager may not respect thissource.set_window_position_from_settings(Settings.source)returnendif chord == 'C-g' thenShow_file_navigator = trueFile_navigation.index = 1returnendif Focus == 'edit' thenreturn edit.keychord_pressed(Editor_state, chord, key)elsereturn log_browser.keychord_pressed(Log_browser_state, chord, key)endendfunction source.key_released(key, scancode)Cursor_time = 0 -- ensure cursor is visible immediately after it movesif Focus == 'edit' thenreturn edit.key_released(Editor_state, key, scancode)elsereturn log_browser.keychord_pressed(Log_browser_state, chordkey, scancode)endend-- use this sparinglyfunction to_text(s)if Text_cache[s] == nil thenText_cache[s] = App.newText(love.graphics.getFont(), s)endreturn Text_cache[s]endlove.window.setTitle('lines.love - source')end-- environment for a mutable file of bifolded text-- TODO: some initialization is also happening in load_settings/initialize_default_settings. Clean that up.function source.initialize_edit_side(arg)if #arg > 0 thenEditor_state.filename = arg[1]load_from_disk(Editor_state)Text.redraw_all(Editor_state)Editor_state.screen_top1 = {line=1, pos=1}Editor_state.cursor1 = {line=1, pos=1}elseload_from_disk(Editor_state)Text.redraw_all(Editor_state)endif #arg > 1 thenprint('ignoring commandline args after '..arg[1])end-- We currently start out with side B collapsed.-- Other options:-- * save all expanded state by line-- * expand all if any location is in side Bif Editor_state.cursor1.line > #Editor_state.lines thenEditor_state.cursor1 = {line=1, pos=1}endif Editor_state.screen_top1.line > #Editor_state.lines thenEditor_state.screen_top1 = {line=1, pos=1}endedit.eradicate_locations_after_the_fold(Editor_state)if rawget(_G, 'jit') thenjit.off()jit.flush()endendfunction source.load_settings()local settings = Settings.sourcelove.graphics.setFont(love.graphics.newFont(settings.font_height))-- maximize window to determine maximum allowable dimensionslove.window.setMode(0, 0) -- maximizeDisplay_width, Display_height, App.screen.flags = love.window.getMode()-- set up desired window dimensionsApp.screen.flags.resizable = trueApp.screen.flags.minwidth = math.min(Display_width, 200)App.screen.flags.minheight = math.min(Display_height, 200)App.screen.width, App.screen.height = settings.width, settings.height--? print('setting window from settings:', App.screen.width, App.screen.height)love.window.setMode(App.screen.width, App.screen.height, App.screen.flags)--? print('loading source position', settings.x, settings.y, settings.displayindex)source.set_window_position_from_settings(settings)Show_log_browser_side = settings.show_log_browser_sidelocal right = App.screen.width - Margin_rightif Show_log_browser_side thenright = App.screen.width/2 - Margin_rightendEditor_state = edit.initialize_state(Margin_top, Margin_left, right, settings.font_height, math.floor(settings.font_height*1.3))Editor_state.filename = settings.filenameEditor_state.screen_top1 = settings.screen_topEditor_state.cursor1 = settings.cursorendfunction source.set_window_position_from_settings(settings)-- setPosition doesn't quite seem to do what is asked of it on Linux.love.window.setPosition(settings.x, settings.y-37, settings.displayindex)endfunction source.initialize_default_settings()local font_height = 20love.graphics.setFont(love.graphics.newFont(font_height))local em = App.newText(love.graphics.getFont(), 'm')source.initialize_window_geometry(App.width(em))Editor_state = edit.initialize_state(Margin_top, Margin_left, App.screen.width-Margin_right)Editor_state.font_height = font_heightEditor_state.line_height = math.floor(font_height*1.3)Editor_state.em = emendfunction source.initialize_window_geometry(em_width)-- maximize windowlove.window.setMode(0, 0) -- maximizeDisplay_width, Display_height, App.screen.flags = love.window.getMode()-- shrink height slightly to account for window decorationApp.screen.height = Display_height-100App.screen.width = 40*em_widthApp.screen.flags.resizable = trueApp.screen.flags.minwidth = math.min(App.screen.width, 200)App.screen.flags.minheight = math.min(App.screen.width, 200)love.window.setMode(App.screen.width, App.screen.height, App.screen.flags)print('initializing source position')if Settings == nil then Settings = {} endif Settings.source == nil then Settings.source = {} endSettings.source.x, Settings.source.y, Settings.source.displayindex = love.window.getPosition()endfunction source.resize(w, h)--? print(("Window resized to width: %d and height: %d."):format(w, h))App.screen.width, App.screen.height = w, hText.redraw_all(Editor_state)Editor_state.selection1 = {} -- no support for shift drag while we're resizingif Show_log_browser_side thenEditor_state.right = App.screen.width/2 - Margin_rightelseEditor_state.right = App.screen.width-Margin_rightendLog_browser_state.left = App.screen.width/2 + Margin_rightLog_browser_state.right = App.screen.width-Margin_rightEditor_state.width = Editor_state.right-Editor_state.leftText.tweak_screen_top_and_cursor(Editor_state, Editor_state.left, Editor_state.right)--? print('end resize')endfunction source.filedropped(file)-- first make sure to save edits on any existing fileif Editor_state.next_save thensave_to_disk(Editor_state)end-- clear the slate for the new fileEditor_state.filename = file:getFilename()file:open('r')Editor_state.lines = load_from_file(file)file:close()Text.redraw_all(Editor_state)Editor_state.screen_top1 = {line=1, pos=1}Editor_state.cursor1 = {line=1, pos=1} - edit in source.lua at line 72
love.window.setTitle('text.love - source') - edit in source.lua at line 200
love.window.setTitle('text.love - source') - edit in main.lua at line 107
love.window.setTitle('lines.love - '..Current_app)