From 221bd0229e46b13894cf515cfbb11f119d8470fd Mon Sep 17 00:00:00 2001 From: Ponali Date: Wed, 9 Jul 2025 16:17:35 +0200 Subject: [PATCH] v2.3.0 - Added functionality for Ctrl+Delete and Ctrl+Backspace --- argentum.cfg | 2 +- halyde/core/boot.lua | 2 +- halyde/core/termlib.lua | 51 +++++++++++++++++++++++++++++++---------- 3 files changed, 41 insertions(+), 14 deletions(-) diff --git a/argentum.cfg b/argentum.cfg index facf784..4491480 100644 --- a/argentum.cfg +++ b/argentum.cfg @@ -1,7 +1,7 @@ local agcfg = { ["halyde"] = { ["maindir"] = "", - ["version"] = "2.2.0", + ["version"] = "2.3.0", ["description"] = "A universal, customizable and feature-packed operating system for OpenComputers.", ["directories"] = { "halyde/apps", diff --git a/halyde/core/boot.lua b/halyde/core/boot.lua index df9c279..c2650dc 100644 --- a/halyde/core/boot.lua +++ b/halyde/core/boot.lua @@ -1,7 +1,7 @@ local loadfile = ... local filesystem = loadfile("/halyde/lib/filesystem.lua")(loadfile) -_G._OSVERSION = "Halyde 2.2.0" +_G._OSVERSION = "Halyde 2.3.0" _G._OSLOGO = "" local handle, tmpdata = filesystem.open("/halyde/config/oslogo.ans", "r"), nil repeat diff --git a/halyde/core/termlib.lua b/halyde/core/termlib.lua index 3a50011..a0a61c8 100644 --- a/halyde/core/termlib.lua +++ b/halyde/core/termlib.lua @@ -243,6 +243,11 @@ function _G.read(readHistoryType, prefix, defaultText, maxChars) historyIdx = #termlib.readHistory[readHistoryType] end + local function updateHistory() + if not readHistoryType then return end + termlib.readHistory[readHistoryType][historyIdx]=text + end + local cur = unicode.len(text)+1 if prefix then termlib.write(prefix) end local startX, startY = termlib.cursorPosX, termlib.cursorPosY @@ -306,23 +311,45 @@ function _G.read(readHistoryType, prefix, defaultText, maxChars) local function isLetter(chr) return not string.find("\x09 :@-./_~?&=%+#",chr,1,true) end - local function nextCur(dir,chr) - local next = math.max(math.min(cur+dir,unicode.len(text)+1),1) + local function nextCur(dir,chr,icur) + 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 return next 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) if nextCur(dir)==cur then return end set(curPos(cur),strDef(unicode.sub(text,cur,cur)," "),false) - while nextCur(dir)~=cur and isLetter(nextCur(dir,true))==(dir==1) do - cur=nextCur(dir) - end - while nextCur(dir)~=cur and isLetter(nextCur(dir,true))==(dir==-1) do - cur=nextCur(dir) - end + cur=curAfterWord(dir) set(curPos(cur),strDef(unicode.sub(text,cur,cur)," "),true) cursorBlink = true 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) return chr=="\n" or chr=="\r" end @@ -339,10 +366,6 @@ function _G.read(readHistoryType, prefix, defaultText, maxChars) text=new set(curPos(cur)," ",true) end - local function updateHistory() - if not readHistoryType then return end - termlib.readHistory[readHistoryType][historyIdx]=text - end while true do local args = {event.pull("key_down", "clipboard", 0.5)} @@ -366,6 +389,10 @@ function _G.read(readHistoryType, prefix, defaultText, maxChars) moveCur(-math.huge) elseif key=="end" then 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 text=unicode.sub(text,1,cur-2)..unicode.sub(text,cur) cur=cur-1