1
0
mirror of https://github.com/20kdc/OC-KittenOS.git synced 2024-09-28 06:31:07 +10:00
OC-KittenOS/apps/eeprog.lua
gamemanj 2ae3f9a93a Initial commit
Currently eeprog pirate-speak language is unsupported, but... oh well.
2016-10-23 13:27:16 +01:00

78 lines
1.7 KiB
Lua

local lang, unicode = A.request("lang", "unicode")
local eeprom = A.request("c.eeprom")
if eeprom then
eeprom = eeprom.list()()
end
local langTable = lang.getTable()
local function G(text)
if langTable then
if langTable[text] then
return langTable[text]
end
end
return text
end
local postFlash = false
local label = ""
local app = {}
function app.key(ka, kc, down)
if down then
if postFlash then
if ka ~= 0 then
if ka == 8 then
label = unicode.sub(label, 1, unicode.len(label) - 1)
return true
end
if ka == 13 then
eeprom.setLabel(label)
postFlash = false
return true
end
label = label .. unicode.char(ka)
return true
end
return false
end
if ka == ("r"):byte() then
local f = A.openfile(G("EEPROM Dump"), "w")
if f then
f.write(eeprom.get())
f.close()
end
end
if ka == ("w"):byte() then
local f = A.openfile(G("EEPROM to flash"), "r")
if f then
local txt = f.read(128)
local ch = ""
while txt do
ch = ch .. txt
txt = f.read(128)
end
eeprom.set(ch)
postFlash = true
label = ""
return true
end
end
if ka == ("C"):byte() then
A.die()
return false
end
end
end
-- this string must be the longest, kind of bad but oh well
-- at least it's not a forced 29 chars...
local baseString = unicode.safeTextFormat(G("EEPROMFlash! (R)ead, (W)rite?"))
function app.get_ch(x, y)
if postFlash then
return unicode.sub(unicode.safeTextFormat(G("Label: ") .. label), x, x)
end
if not eeprom then
return unicode.sub(unicode.safeTextFormat(G("No EEPROM installed?")), x, x)
end
return unicode.sub(baseString, x, x)
end
return app, unicode.len(baseString), 1