forked from hkc/cc-stuff
1
0
Fork 0

Small tweaks, mouse handling and speeny block

This commit is contained in:
Casey 2023-10-20 04:00:02 +03:00
parent dd42590052
commit eece2153e4
Signed by: hkc
GPG Key ID: F0F6CFE11CDB0960
1 changed files with 58 additions and 14 deletions

View File

@ -148,8 +148,8 @@ S+Tab : Prev. screen
> : Previous track
f : Seek forward
b : Seek backward
\x11 - : Lower volume
\x10 + : Higher volume
\x1b - : Lower volume
\x1a + : Higher volume
# List screen:
--
@ -157,7 +157,9 @@ S+Tab : Prev. screen
Ctrl+l : Center
l : Jump to current
]]):gsub("\\x11", "\x11"):gsub("\\x10", "\x10"):gmatch("[^\n]+") do
]]):gsub("\\x(..)", function(m)
return string.char(tonumber(m, 16))
end):gmatch("[^\n]+") do
table.insert(help, line)
end
@ -241,20 +243,25 @@ local mplayer = {
end,
handleKey = function(self, key, repeating)
local shiftHeld = self.heldKeys[keys.leftShift] ~= nil or self.heldKeys[keys.rightShift] ~= nil
local ctrlHeld = self.heldKeys[keys.leftCtrl] ~= nil or self.heldKeys[keys.rightCtrl] ~= nil
if key == keys.down or key == keys.j then
self.screens[2].handleScroll(self, 1)
self.screens[2].handleScroll(self, 1, 1, 1)
elseif key == keys.up or key == keys.k then
self.screens[2].handleScroll(self, -1)
self.screens[2].handleScroll(self, -1, 1, 1)
elseif key == keys.pageDown then
self.screens[2].handleScroll(self, th - 3)
self.screens[2].handleScroll(self, th - 3, 1, 1)
elseif key == keys.pageUp then
self.screens[2].handleScroll(self, -(th - 3))
self.screens[2].handleScroll(self, -(th - 3), 1, 1)
elseif key == keys.h and shiftHeld then
self.screens[2].handleScroll(self, -#self.songs)
self.screens[2].handleScroll(self, -#self.songs, 1, 1)
elseif key == keys.l and shiftHeld then
self.screens[2].handleScroll(self, #self.songs)
self.screens[2].handleScroll(self, #self.songs, 1, 1)
elseif key == keys.l then
self.screens[2].cursor = self.currentSong or 1
if ctrlHeld then
self.screens[2].scroll = self.screens[2].scroll - math.floor((th - 3) / 2)
end
self.screens[2].handleScroll(self, 0, 1, 1)
elseif key == keys.enter then
drive.seek(-drive.getSize())
@ -272,8 +279,22 @@ local mplayer = {
if self.screens[2].cursor > maxi then
self.screens[2].scroll = self.screens[2].cursor - (th - 3)
end
if self.screens[2].scroll < 0 then
self.screens[2].scroll = 0
end
if self.screens[2].scroll > #self.songs - (th - 3) then
self.screens[2].scroll = #self.songs - (th - 3)
end
self.screens[2].textScroll = 0
end,
handleClick = function(self, x, y)
local i = self.screens[2].scroll + y - 1
if i == self.screens[2].cursor then
self.screens[2].handleKey(self, keys.enter, false)
elseif i <= #self.songs then
self.screens[2].cursor = i
end
end,
},
{
title = "Settings",
@ -320,6 +341,13 @@ term.setBackgroundColor(mplayer.colors.bg)
term.setTextColor(mplayer.colors.fg)
term.clear()
local spinner = {
"\x81", "\x83", "\x82",
"\x8a", "\x88", "\x8c",
"\x84", "\x85"
}
parallel.waitForAny(
function()
while true do
@ -352,7 +380,8 @@ function()
local timeString = string.format("[%s:%s]", time2str(time), time2str(duration))
if drive.getState() == "PLAYING" then
term.setTextColor(mplayer.colors.status)
term.write("Playing: ") -- 9 characters
local speen = spinner[(math.floor(drive.getPosition() / 600) % #spinner) + 1]
term.write(speen .. " Playing: ") -- 11 characters
-- Progressbar
local lw = math.floor(tw * time / duration)
@ -360,13 +389,13 @@ function()
term.setTextColor(mplayer.colors.current)
term.clearLine()
term.write(string.rep("=", lw))
term.write(">")
term.write("\x10")
term.setTextColor(mplayer.colors.cursor)
term.write(string.rep("-", tw - lw - 1))
term.write(string.rep("\xad", tw - lw - 1))
-- Statusline text
term.setCursorPos(10, th)
local w = tw - #timeString - 10 -- "Playing: " plus extra space
term.setCursorPos(12, th)
local w = tw - #timeString - 12 -- "Playing: " plus extra space
term.setTextColor(mplayer.colors.current)
if #title <= w then
@ -406,6 +435,16 @@ function()
drive.seek(3000)
elseif ev == "key" and evd[1] == keys.b then
drive.seek(-3000)
elseif ev == "key" and evd[1] == keys.s then
drive.stop()
drive.seek(-drive.getSize())
drive.seek(6000)
elseif ev == "key" and (evd[1] == keys.p or evd[1] == keys.space) then
if drive.getState() ~= "STOPPED" then
drive.stop()
else
drive.play()
end
elseif ev == "key" and evd[1] == keys.tab then
local dir = ((mplayer.heldKeys[keys.leftShift] ~= nil) or (mplayer.heldKeys[keys.rightShift] ~= nil)) and -1 or 1
mplayer.currentScreen = ((mplayer.currentScreen - 1 + #mplayer.screens + dir)) % #mplayer.screens + 1
@ -435,6 +474,11 @@ function()
end
cx = cx + #caption
end
elseif ev == "mouse_click" or ev == "mouse_drag" then
if mplayer.screens[mplayer.currentScreen].handleClick then
local butt, x, y = table.unpack(evd)
mplayer.screens[mplayer.currentScreen].handleClick(mplayer, x, y)
end
elseif ev == "term_resize" then
tw, th = term.getSize()
elseif ev == "tape_removed" then