mirror of
https://github.com/20kdc/OC-KittenOS.git
synced 2024-11-27 04:48:05 +11:00
Ported batmon from legacy, and made app-textedit less GPU-hungry
Both of these should be useful for multimonitor setups, in their own individual ways.
This commit is contained in:
parent
ccb9c3b279
commit
7ca2c26979
@ -96,7 +96,7 @@ return {
|
|||||||
},
|
},
|
||||||
["neo-coreapps"] = {
|
["neo-coreapps"] = {
|
||||||
desc = "KittenOS NEO Core Apps",
|
desc = "KittenOS NEO Core Apps",
|
||||||
v = 2,
|
v = 5,
|
||||||
deps = {
|
deps = {
|
||||||
"neo"
|
"neo"
|
||||||
},
|
},
|
||||||
@ -105,6 +105,7 @@ return {
|
|||||||
},
|
},
|
||||||
files = {
|
files = {
|
||||||
"apps/app-textedit.lua",
|
"apps/app-textedit.lua",
|
||||||
|
"apps/app-batmon.lua",
|
||||||
"apps/app-control.lua",
|
"apps/app-control.lua",
|
||||||
"apps/app-taskmgr.lua"
|
"apps/app-taskmgr.lua"
|
||||||
}
|
}
|
||||||
|
73
code/apps/app-batmon.lua
Normal file
73
code/apps/app-batmon.lua
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
-- This is released into the public domain.
|
||||||
|
-- No warranty is provided, implied or otherwise.
|
||||||
|
|
||||||
|
-- app-batmon: Still not batman.
|
||||||
|
-- Port of the original 'batmon.lua' from KittenOS Legacy.
|
||||||
|
local window = neo.requireAccess("x.neo.pub.window", "window")(10, 2)
|
||||||
|
|
||||||
|
-- OCE/s, OCE at last check, uptime of last check
|
||||||
|
local lastChange, lastValue, lastTimer = 0
|
||||||
|
local usage = {
|
||||||
|
"[####]:",
|
||||||
|
"[###:]:",
|
||||||
|
"[### ]:",
|
||||||
|
"[##: ]:",
|
||||||
|
"[## ]:",
|
||||||
|
"[#: ]:",
|
||||||
|
"[# ]:",
|
||||||
|
"[: ]:",
|
||||||
|
"[ ]:",
|
||||||
|
"WARNING"
|
||||||
|
}
|
||||||
|
local function getText(y)
|
||||||
|
if y == 2 then
|
||||||
|
if not lastChange then
|
||||||
|
return "Wait..."
|
||||||
|
end
|
||||||
|
local ind = "Dc. "
|
||||||
|
local wc = lastChange
|
||||||
|
local wv = os.energy()
|
||||||
|
if wc > 0 then
|
||||||
|
wc = -wc
|
||||||
|
wv = os.maxEnergy() - wv
|
||||||
|
ind = "Ch. "
|
||||||
|
end
|
||||||
|
local m = math.floor((wv / -wc) / 60)
|
||||||
|
return ind .. m .. "m"
|
||||||
|
end
|
||||||
|
local dec = os.energy() / os.maxEnergy()
|
||||||
|
-- dec is from 0 to 1.
|
||||||
|
local potential = math.floor(dec * #usage)
|
||||||
|
if potential < 0 then potential = 1 end
|
||||||
|
if potential >= #usage then potential = #usage - 1 end
|
||||||
|
return usage[#usage - potential]
|
||||||
|
end
|
||||||
|
local function update()
|
||||||
|
local nv = os.energy()
|
||||||
|
if lastValue then
|
||||||
|
lastChange = (nv - lastValue) / (os.uptime() - lastTimer)
|
||||||
|
end
|
||||||
|
lastValue = nv
|
||||||
|
lastTimer = os.uptime() + 10
|
||||||
|
if lastChange then
|
||||||
|
if lastChange > 10 then
|
||||||
|
lastTimer = lastTimer - 9
|
||||||
|
end
|
||||||
|
end
|
||||||
|
neo.scheduleTimer(lastTimer)
|
||||||
|
window.setSize(10, 2)
|
||||||
|
end
|
||||||
|
update()
|
||||||
|
while true do
|
||||||
|
local ev, a, b, c = coroutine.yield()
|
||||||
|
if ev == "x.neo.pub.window" then
|
||||||
|
if b == "close" then
|
||||||
|
return
|
||||||
|
elseif b == "line" then
|
||||||
|
local tx = getText(c):sub(1, 10)
|
||||||
|
window.span(1, c, tx .. (" "):rep(10 - #tx), 0xFFFFFF, 0)
|
||||||
|
end
|
||||||
|
elseif ev == "k.timer" then
|
||||||
|
update()
|
||||||
|
end
|
||||||
|
end
|
@ -11,7 +11,7 @@ local lines = {
|
|||||||
"F5, F6, ^←: Copy, Paste, Delete Line",
|
"F5, F6, ^←: Copy, Paste, Delete Line",
|
||||||
-- These two are meant to replace similar functionality in GNU Nano
|
-- These two are meant to replace similar functionality in GNU Nano
|
||||||
-- (which I consider the best console text editor out there - Neolithic is an *imitation* and a poor one at that),
|
-- (which I consider the best console text editor out there - Neolithic is an *imitation* and a poor one at that),
|
||||||
-- except fixing a UI flaw by instead making J responsible for resetting the append flag,
|
-- except fixing a UI flaw by instead adding a visible way to reset the append flag,
|
||||||
-- so the user can more or less arbitrarily mash together lines
|
-- so the user can more or less arbitrarily mash together lines
|
||||||
"F7: Reset 'append' flag for Cut Lines",
|
"F7: Reset 'append' flag for Cut Lines",
|
||||||
"F8: Cut Line(s)",
|
"F8: Cut Line(s)",
|
||||||
@ -33,9 +33,8 @@ local files = neo.requireAccess("x.neo.pub.base", "files").showFileDialogAsync
|
|||||||
local cursorX = 1
|
local cursorX = 1
|
||||||
local cursorY = math.ceil(#lines / 2)
|
local cursorY = math.ceil(#lines / 2)
|
||||||
local cFlash = true
|
local cFlash = true
|
||||||
local ctrlFlag = false
|
local ctrlFlag, focFlag, appendFlag
|
||||||
local dialogLock = false
|
local dialogLock = false
|
||||||
local appendFlag = false
|
|
||||||
local sW, sH = 37, #lines + 2
|
local sW, sH = 37, #lines + 2
|
||||||
local window = windows(sW, sH)
|
local window = windows(sW, sH)
|
||||||
local filedialog = nil
|
local filedialog = nil
|
||||||
@ -213,23 +212,19 @@ local function key(ka, kc, down)
|
|||||||
sH = 1
|
sH = 1
|
||||||
end
|
end
|
||||||
sW, sH = window.setSize(sW, sH)
|
sW, sH = window.setSize(sW, sH)
|
||||||
end
|
elseif kc == 208 then -- Down
|
||||||
if kc == 208 then -- Down
|
|
||||||
sH = sH + 1
|
sH = sH + 1
|
||||||
sW, sH = window.setSize(sW, sH)
|
sW, sH = window.setSize(sW, sH)
|
||||||
end
|
elseif kc == 203 then -- Left
|
||||||
if kc == 203 then -- Left
|
|
||||||
sW = sW - 1
|
sW = sW - 1
|
||||||
if sW == 0 then
|
if sW == 0 then
|
||||||
sW = 1
|
sW = 1
|
||||||
end
|
end
|
||||||
sW, sH = window.setSize(sW, sH)
|
sW, sH = window.setSize(sW, sH)
|
||||||
end
|
elseif kc == 205 then -- Right
|
||||||
if kc == 205 then -- Right
|
|
||||||
sW = sW + 1
|
sW = sW + 1
|
||||||
sW, sH = window.setSize(sW, sH)
|
sW, sH = window.setSize(sW, sH)
|
||||||
end
|
elseif kc == 14 then -- ^Backspace
|
||||||
if kc == 14 then -- ^Backspace
|
|
||||||
delLine()
|
delLine()
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
@ -247,8 +242,7 @@ local function key(ka, kc, down)
|
|||||||
end
|
end
|
||||||
clampCursorX()
|
clampCursorX()
|
||||||
return true
|
return true
|
||||||
end
|
elseif kc == 208 or kc == 209 then -- Go down one - go down page
|
||||||
if kc == 208 or kc == 209 then -- Go down one - go down page
|
|
||||||
local moveAmount = 1
|
local moveAmount = 1
|
||||||
if kc == 209 then
|
if kc == 209 then
|
||||||
moveAmount = math.floor(sH / 2)
|
moveAmount = math.floor(sH / 2)
|
||||||
@ -259,8 +253,7 @@ local function key(ka, kc, down)
|
|||||||
end
|
end
|
||||||
clampCursorX()
|
clampCursorX()
|
||||||
return true
|
return true
|
||||||
end
|
elseif kc == 203 then
|
||||||
if kc == 203 then
|
|
||||||
if cursorX > 1 then
|
if cursorX > 1 then
|
||||||
cursorX = cursorX - 1
|
cursorX = cursorX - 1
|
||||||
else
|
else
|
||||||
@ -272,8 +265,7 @@ local function key(ka, kc, down)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end
|
elseif kc == 205 then
|
||||||
if kc == 205 then
|
|
||||||
cursorX = cursorX + 1
|
cursorX = cursorX + 1
|
||||||
if clampCursorX() then
|
if clampCursorX() then
|
||||||
if cursorY < #lines then
|
if cursorY < #lines then
|
||||||
@ -287,8 +279,7 @@ local function key(ka, kc, down)
|
|||||||
if kc == 199 then
|
if kc == 199 then
|
||||||
cursorX = 1
|
cursorX = 1
|
||||||
return true
|
return true
|
||||||
end
|
elseif kc == 207 then
|
||||||
if kc == 207 then
|
|
||||||
cursorX = unicode.len(lines[cursorY]) + 1
|
cursorX = unicode.len(lines[cursorY]) + 1
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
@ -298,17 +289,13 @@ local function key(ka, kc, down)
|
|||||||
cursorX = 1
|
cursorX = 1
|
||||||
cursorY = 1
|
cursorY = 1
|
||||||
return true
|
return true
|
||||||
end
|
elseif kc == 61 then -- F3
|
||||||
if kc == 61 then -- F3
|
|
||||||
startLoad()
|
startLoad()
|
||||||
end
|
elseif kc == 62 then -- F4
|
||||||
if kc == 62 then -- F4
|
|
||||||
startSave()
|
startSave()
|
||||||
end
|
elseif kc == 63 then -- F5
|
||||||
if kc == 63 then -- F5
|
|
||||||
clipsrc.setSetting("clipboard", lines[cursorY])
|
clipsrc.setSetting("clipboard", lines[cursorY])
|
||||||
end
|
elseif kc == 64 then -- F6
|
||||||
if kc == 64 then -- F6
|
|
||||||
local tx = clipsrc.getSetting("clipboard") or ""
|
local tx = clipsrc.getSetting("clipboard") or ""
|
||||||
local txi = tx:find("\n")
|
local txi = tx:find("\n")
|
||||||
local nt = {}
|
local nt = {}
|
||||||
@ -322,11 +309,9 @@ local function key(ka, kc, down)
|
|||||||
table.insert(lines, cursorY, v)
|
table.insert(lines, cursorY, v)
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end
|
elseif kc == 65 then -- F7
|
||||||
if kc == 65 then -- F7
|
|
||||||
appendFlag = false
|
appendFlag = false
|
||||||
end
|
elseif kc == 66 then -- F8
|
||||||
if kc == 66 then -- F8
|
|
||||||
if appendFlag then
|
if appendFlag then
|
||||||
local base = clipsrc.getSetting("clipboard")
|
local base = clipsrc.getSetting("clipboard")
|
||||||
clipsrc.setSetting("clipboard", base .. "\n" .. delLine())
|
clipsrc.setSetting("clipboard", base .. "\n" .. delLine())
|
||||||
@ -372,11 +357,11 @@ neo.scheduleTimer(os.uptime() + 0.5)
|
|||||||
|
|
||||||
while true do
|
while true do
|
||||||
local e = {coroutine.yield()}
|
local e = {coroutine.yield()}
|
||||||
if e[1] == "k.timer" then
|
if e[1] == "k.timer" and e[2] == focFlag then
|
||||||
cFlash = not cFlash
|
cFlash = not cFlash
|
||||||
local csY = math.ceil(sH / 2)
|
local csY = math.ceil(sH / 2)
|
||||||
window.span(1, csY, getline(csY), 0xFFFFFF, 0)
|
window.span(1, csY, getline(csY), 0xFFFFFF, 0)
|
||||||
neo.scheduleTimer(os.uptime() + 0.5)
|
focFlag = neo.scheduleTimer(os.uptime() + 0.5)
|
||||||
elseif e[1] == "x.neo.pub.window" then
|
elseif e[1] == "x.neo.pub.window" then
|
||||||
if e[2] == window.id then
|
if e[2] == window.id then
|
||||||
if e[3] == "line" then
|
if e[3] == "line" then
|
||||||
@ -395,6 +380,7 @@ while true do
|
|||||||
flush()
|
flush()
|
||||||
end
|
end
|
||||||
elseif e[3] == "focus" then
|
elseif e[3] == "focus" then
|
||||||
|
focFlag = e[4] and neo.scheduleTimer(0)
|
||||||
ctrlFlag = false
|
ctrlFlag = false
|
||||||
elseif e[3] == "close" then
|
elseif e[3] == "close" then
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user