Added status line and "not implemented" messages

This commit is contained in:
Casey 2023-10-20 04:58:34 +03:00
parent 3dbd27525a
commit b051d36bc0
Signed by: hkc
GPG Key ID: F0F6CFE11CDB0960
1 changed files with 58 additions and 35 deletions

View File

@ -166,6 +166,10 @@ end):gmatch("[^\n]+") do
table.insert(help, line) table.insert(help, line)
end end
local statusText, statusTicks = nil, 0
local function setStatus(txt, ticks)
statusText, statusTicks = txt, ticks or 10
end
local mplayer = { local mplayer = {
colors = { colors = {
@ -306,6 +310,7 @@ local mplayer = {
render = function(self) render = function(self)
term.clear() term.clear()
term.write(string.format("opt = %d, scroll = %d", self.screens[3].cursor, self.screens[3].scroll)) term.write(string.format("opt = %d, scroll = %d", self.screens[3].cursor, self.screens[3].scroll))
term.write(" // TODO")
end, end,
handleKey = function(self, key, repeating) handleKey = function(self, key, repeating)
if key == keys.down or key == keys.j then if key == keys.down or key == keys.j then
@ -376,13 +381,30 @@ function()
title = song.title title = song.title
end end
-- Statusline -- Progressbar
term.setCursorPos(1, th) local lw = math.floor(tw * time / duration)
term.setCursorPos(1, th - 1)
term.setTextColor(mplayer.colors.current)
term.clearLine() term.clearLine()
term.write(string.rep("=", lw))
term.write("\x10")
term.setTextColor(mplayer.colors.cursor)
term.write(string.rep("\xad", tw - lw - 1))
local timeString = string.format("[%s:%s]", time2str(time), time2str(duration)) local timeString = string.format("[%s:%s]", time2str(time), time2str(duration))
term.setCursorPos(1, th)
term.clearLine()
if statusTicks > 0 then
term.setTextColor(colors.red)
term.write(statusText)
statusTicks = statusTicks - 1
end
if drive.getState() ~= "STOPPED" then if drive.getState() ~= "STOPPED" then
term.setTextColor(mplayer.colors.status) term.setTextColor(mplayer.colors.status)
if statusTicks <= 0 then
local speen = spinner[(math.floor(drive.getPosition() / 3000) % #spinner) + 1] local speen = spinner[(math.floor(drive.getPosition() / 3000) % #spinner) + 1]
local action = "" local action = ""
if drive.getState() == "PLAYING" then action = "Playing:" if drive.getState() == "PLAYING" then action = "Playing:"
@ -393,17 +415,8 @@ function()
return return
end end
action = speen .. " " .. action action = speen .. " " .. action
term.write(action)
-- Progressbar term.write(action)
local lw = math.floor(tw * time / duration)
term.setCursorPos(1, th - 1)
term.setTextColor(mplayer.colors.current)
term.clearLine()
term.write(string.rep("=", lw))
term.write("\x10")
term.setTextColor(mplayer.colors.cursor)
term.write(string.rep("\xad", tw - lw - 1))
-- Statusline text -- Statusline text
term.setCursorPos(#action + 2, th) term.setCursorPos(#action + 2, th)
@ -418,9 +431,12 @@ function()
term.write(txt:sub(off, off + w - 1)) term.write(txt:sub(off, off + w - 1))
end end
end end
end
if statusTicks <= 0 then
term.setTextColor(mplayer.colors.status) term.setTextColor(mplayer.colors.status)
term.setCursorPos(tw - #timeString + 1, th) term.setCursorPos(tw - #timeString + 1, th)
term.write(timeString) term.write(timeString)
end
os.sleep(0.1) os.sleep(0.1)
end end
end, end,
@ -435,6 +451,9 @@ function()
mplayer.heldKeys[evd[1]] = nil mplayer.heldKeys[evd[1]] = nil
end end
local shiftHeld = mplayer.heldKeys[keys.leftShift] ~= nil or mplayer.heldKeys[keys.rightShift] ~= nil
local ctrlHeld = mplayer.heldKeys[keys.leftCtrl] ~= nil or mplayer.heldKeys[keys.rightCtrl] ~= nil
if ev == "key_up" and evd[1] == keys.q then if ev == "key_up" and evd[1] == keys.q then
break break
elseif ev == "key" and (evd[1] == keys.one or evd[1] == keys.f1) then elseif ev == "key" and (evd[1] == keys.one or evd[1] == keys.f1) then
@ -447,6 +466,10 @@ function()
drive.seek(3000) drive.seek(3000)
elseif ev == "key" and evd[1] == keys.b then elseif ev == "key" and evd[1] == keys.b then
drive.seek(-3000) drive.seek(-3000)
elseif ev == "key" and (evd[1] == keys.comma or evd[1] == keys.period) and shiftHeld then
setStatus("Not implemented yet!", 20)
elseif ev == "key" and evd[1] == keys.left or evd[1] == keys.right or evd[1] == keys.minus or (evd[1] == keys.equals and shiftHeld) then
setStatus("Not implemented yet!", 20)
elseif ev == "key" and evd[1] == keys.s then elseif ev == "key" and evd[1] == keys.s then
drive.stop() drive.stop()
drive.seek(-drive.getSize()) drive.seek(-drive.getSize())