v2.3.0 - Added functionality for Ctrl+Delete and Ctrl+Backspace
This commit is contained in:
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
local agcfg = {
|
local agcfg = {
|
||||||
["halyde"] = {
|
["halyde"] = {
|
||||||
["maindir"] = "",
|
["maindir"] = "",
|
||||||
["version"] = "2.2.0",
|
["version"] = "2.3.0",
|
||||||
["description"] = "A universal, customizable and feature-packed operating system for OpenComputers.",
|
["description"] = "A universal, customizable and feature-packed operating system for OpenComputers.",
|
||||||
["directories"] = {
|
["directories"] = {
|
||||||
"halyde/apps",
|
"halyde/apps",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
local loadfile = ...
|
local loadfile = ...
|
||||||
local filesystem = loadfile("/halyde/lib/filesystem.lua")(loadfile)
|
local filesystem = loadfile("/halyde/lib/filesystem.lua")(loadfile)
|
||||||
|
|
||||||
_G._OSVERSION = "Halyde 2.2.0"
|
_G._OSVERSION = "Halyde 2.3.0"
|
||||||
_G._OSLOGO = ""
|
_G._OSLOGO = ""
|
||||||
local handle, tmpdata = filesystem.open("/halyde/config/oslogo.ans", "r"), nil
|
local handle, tmpdata = filesystem.open("/halyde/config/oslogo.ans", "r"), nil
|
||||||
repeat
|
repeat
|
||||||
|
|||||||
+39
-12
@@ -243,6 +243,11 @@ function _G.read(readHistoryType, prefix, defaultText, maxChars)
|
|||||||
historyIdx = #termlib.readHistory[readHistoryType]
|
historyIdx = #termlib.readHistory[readHistoryType]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function updateHistory()
|
||||||
|
if not readHistoryType then return end
|
||||||
|
termlib.readHistory[readHistoryType][historyIdx]=text
|
||||||
|
end
|
||||||
|
|
||||||
local cur = unicode.len(text)+1
|
local cur = unicode.len(text)+1
|
||||||
if prefix then termlib.write(prefix) end
|
if prefix then termlib.write(prefix) end
|
||||||
local startX, startY = termlib.cursorPosX, termlib.cursorPosY
|
local startX, startY = termlib.cursorPosX, termlib.cursorPosY
|
||||||
@@ -306,23 +311,45 @@ function _G.read(readHistoryType, prefix, defaultText, maxChars)
|
|||||||
local function isLetter(chr)
|
local function isLetter(chr)
|
||||||
return not string.find("\x09 :@-./_~?&=%+#",chr,1,true)
|
return not string.find("\x09 :@-./_~?&=%+#",chr,1,true)
|
||||||
end
|
end
|
||||||
local function nextCur(dir,chr)
|
local function nextCur(dir,chr,icur)
|
||||||
local next = math.max(math.min(cur+dir,unicode.len(text)+1),1)
|
if icur==nil then icur=cur end
|
||||||
|
local next = math.max(math.min(icur+dir,unicode.len(text)+1),1)
|
||||||
if chr then return unicode.sub(text,next,next) end
|
if chr then return unicode.sub(text,next,next) end
|
||||||
return next
|
return next
|
||||||
end
|
end
|
||||||
|
local function curAfterWord(dir)
|
||||||
|
local ncur = cur
|
||||||
|
while nextCur(dir,false,ncur)~=ncur and isLetter(nextCur(dir,true,ncur))==(dir==1) do
|
||||||
|
ncur=nextCur(dir,false,ncur)
|
||||||
|
end
|
||||||
|
while nextCur(dir,false,ncur)~=ncur and isLetter(nextCur(dir,true,ncur))==(dir==-1) do
|
||||||
|
ncur=nextCur(dir,false,ncur)
|
||||||
|
end
|
||||||
|
return ncur
|
||||||
|
end
|
||||||
local function moveWord(dir)
|
local function moveWord(dir)
|
||||||
if nextCur(dir)==cur then return end
|
if nextCur(dir)==cur then return end
|
||||||
set(curPos(cur),strDef(unicode.sub(text,cur,cur)," "),false)
|
set(curPos(cur),strDef(unicode.sub(text,cur,cur)," "),false)
|
||||||
while nextCur(dir)~=cur and isLetter(nextCur(dir,true))==(dir==1) do
|
cur=curAfterWord(dir)
|
||||||
cur=nextCur(dir)
|
|
||||||
end
|
|
||||||
while nextCur(dir)~=cur and isLetter(nextCur(dir,true))==(dir==-1) do
|
|
||||||
cur=nextCur(dir)
|
|
||||||
end
|
|
||||||
set(curPos(cur),strDef(unicode.sub(text,cur,cur)," "),true)
|
set(curPos(cur),strDef(unicode.sub(text,cur,cur)," "),true)
|
||||||
cursorBlink = true
|
cursorBlink = true
|
||||||
end
|
end
|
||||||
|
local function deleteWord(dir)
|
||||||
|
local after = curAfterWord(dir)
|
||||||
|
local lenb = unicode.wlen(text)
|
||||||
|
if dir==1 then
|
||||||
|
text=unicode.sub(text,1,cur-1)..unicode.sub(text,after)
|
||||||
|
set(curPos(cur+1),unicode.sub(text,cur+1)..string.rep(" ",lenb-unicode.wlen(text)+1),false)
|
||||||
|
set(curPos(cur),strDef(unicode.sub(text,cur,cur)," "),true)
|
||||||
|
else
|
||||||
|
text = unicode.sub(text,1,after-1)..unicode.sub(text,cur)
|
||||||
|
cur=after
|
||||||
|
set(curPos(cur+1),unicode.sub(text,cur+1)..string.rep(" ",lenb-unicode.wlen(text)+1),false)
|
||||||
|
set(curPos(cur),strDef(unicode.sub(text,cur,cur)," "),true)
|
||||||
|
end
|
||||||
|
updateHistory()
|
||||||
|
cursorBlink = true
|
||||||
|
end
|
||||||
local function isLine(chr)
|
local function isLine(chr)
|
||||||
return chr=="\n" or chr=="\r"
|
return chr=="\n" or chr=="\r"
|
||||||
end
|
end
|
||||||
@@ -339,10 +366,6 @@ function _G.read(readHistoryType, prefix, defaultText, maxChars)
|
|||||||
text=new
|
text=new
|
||||||
set(curPos(cur)," ",true)
|
set(curPos(cur)," ",true)
|
||||||
end
|
end
|
||||||
local function updateHistory()
|
|
||||||
if not readHistoryType then return end
|
|
||||||
termlib.readHistory[readHistoryType][historyIdx]=text
|
|
||||||
end
|
|
||||||
|
|
||||||
while true do
|
while true do
|
||||||
local args = {event.pull("key_down", "clipboard", 0.5)}
|
local args = {event.pull("key_down", "clipboard", 0.5)}
|
||||||
@@ -366,6 +389,10 @@ function _G.read(readHistoryType, prefix, defaultText, maxChars)
|
|||||||
moveCur(-math.huge)
|
moveCur(-math.huge)
|
||||||
elseif key=="end" then
|
elseif key=="end" then
|
||||||
moveCur(math.huge)
|
moveCur(math.huge)
|
||||||
|
elseif key=="back" and keyboard.ctrlDown then
|
||||||
|
deleteWord(-1)
|
||||||
|
elseif key=="delete" and keyboard.ctrlDown then
|
||||||
|
deleteWord(1)
|
||||||
elseif key=="back" and cur>1 then
|
elseif key=="back" and cur>1 then
|
||||||
text=unicode.sub(text,1,cur-2)..unicode.sub(text,cur)
|
text=unicode.sub(text,1,cur-2)..unicode.sub(text,cur)
|
||||||
cur=cur-1
|
cur=cur-1
|
||||||
|
|||||||
Reference in New Issue
Block a user