From 74e93068fb54af892a6ef4ed610337c0b71946a2 Mon Sep 17 00:00:00 2001 From: "kepler155c@gmail.com" Date: Sun, 1 Jan 2017 21:46:37 -0500 Subject: [PATCH] hot keys --- apps/edit.lua | 65 ++++++++++++++++++++++++++++++----------------- apps/multishell | 4 +++ apps/recorder.lua | 14 +++++++--- 3 files changed, 56 insertions(+), 27 deletions(-) diff --git a/apps/edit.lua b/apps/edit.lua index 2d8d634..0c02df7 100644 --- a/apps/edit.lua +++ b/apps/edit.lua @@ -32,6 +32,7 @@ local keyboard local clipboard = { size, internal } local searchPattern local undo = { chain = { }, pointer = 0 } +local complete = { } if _G.__CLIPBOARD then clipboard = _G.__CLIPBOARD @@ -485,36 +486,51 @@ local __actions = { end, autocomplete = function() - local sLine = tLines[y]:sub(1, x - 1) - local nStartPos = sLine:find("[a-zA-Z0-9_%.]+$") - if nStartPos then - sLine = sLine:sub(nStartPos) + if keyboard.lastAction ~= 'autocomplete' or not complete.results then + local sLine = tLines[y]:sub(1, x - 1) + local nStartPos = sLine:find("[a-zA-Z0-9_%.]+$") + if nStartPos then + sLine = sLine:sub(nStartPos) + end + if #sLine > 0 then + complete.results = textutils.complete(sLine) + else + complete.results = { } + end + complete.index = 0 + complete.x = x end - if #sLine > 0 then - local results = textutils.complete(sLine) - if #results == 0 then - setError('No completions available') + if #complete.results == 0 then + setError('No completions available') - elseif #results == 1 then - actions.insertText(x, y, results[1]) + elseif #complete.results == 1 then + actions.insertText(x, y, complete.results[1]) + complete.results = nil - elseif #results > 1 then - local prefix = results[1] - for n = 1, #results do - local result = results[n] - while #prefix > 0 do - if result:find(prefix, 1, true) == 1 then - break - end - prefix = prefix:sub(1, #prefix - 1) + elseif #complete.results > 1 then + local prefix = complete.results[1] + for n = 1, #complete.results do + local result = complete.results[n] + while #prefix > 0 do + if result:find(prefix, 1, true) == 1 then + break end + prefix = prefix:sub(1, #prefix - 1) end - if #prefix > 0 then - actions.insertText(x, y, prefix) - else - setStatus('Too many results') + end + if #prefix > 0 then + actions.insertText(x, y, prefix) + complete.results = nil + else + if complete.index > 0 then + actions.deleteText(complete.x, y, complete.x + #complete.results[complete.index], y) end + complete.index = complete.index + 1 + if complete.index > #complete.results then + complete.index = 1 + end + actions.insertText(complete.x, y, complete.results[complete.index]) end end end, @@ -1203,6 +1219,9 @@ while bRunning do mark.continue = false actions[action](param, param2) + if action ~= 'menu' then + keyboard.lastAction = action + end if x ~= lastPos.x or y ~= lastPos.y then actions.setCursor() diff --git a/apps/multishell b/apps/multishell index 6f88988..6fbf5de 100644 --- a/apps/multishell +++ b/apps/multishell @@ -518,6 +518,10 @@ while true do local tEventData = { os.pullEventRaw() } local sEvent = table.remove(tEventData, 1) + if sEvent == 'key_up' then + processKeyEvent(sEvent, tEventData[1]) + end + if sEvent == "term_resize" then -- Resize event w,h = parentTerm.getSize() diff --git a/apps/recorder.lua b/apps/recorder.lua index 660a970..2485256 100644 --- a/apps/recorder.lua +++ b/apps/recorder.lua @@ -129,7 +129,7 @@ recTerm = multishell.term for key, func in pairs(oldTerm) do recTerm[key] = function(...) local result = { func(...) } - + if callCount == 0 then os.queueEvent('capture_frame') end @@ -480,9 +480,15 @@ for i = 1, #calls do for xx = xMin, xMax do if buffer[yy][xx][1] ~= oldBuffer[yy][xx][1] or (buffer[yy][xx][2] ~= oldBuffer[yy][xx][2] and buffer[yy][xx][1] ~= " ") or buffer[yy][xx][3] ~= oldBuffer[yy][xx][3] or buffer[yy][xx][4] ~= oldBuffer[yy][xx][4] or i == 1 then local thisChar, thisT, thisB, xBump = chars[buffer[yy][xx][1]:byte()], buffer[yy][xx][2], buffer[yy][xx][3], (xx - xMin) * charW - - for y = 1, charH do for x = 1, charW do thisFrame[y + yBump][x + xBump] = thisChar[y][x] and thisT or thisB end end - +if thisChar then + for y = 1, charH do + for x = 1, charW do + local ch = thisChar[y][x] and thisT or thisB + thisFrame[y + yBump][x + xBump] = ch + end + end +end + if buffer[yy][xx][4] then thisT, thisChar = colourNum[tCol], chars[95] for y = 1, charH do for x = 1, charW do if thisChar[y][x] then thisFrame[y + yBump][x + xBump] = thisT end end end