Improved small screen support

also added jump to top/bottom/current
also added cleanup code
This commit is contained in:
Casey 2023-10-20 03:32:27 +03:00
parent bbede80038
commit 77c6d13689
Signed by: hkc
GPG Key ID: F0F6CFE11CDB0960
1 changed files with 46 additions and 25 deletions

View File

@ -62,7 +62,7 @@ if not drive then
printError("No drive found, starting in dummy mode") printError("No drive found, starting in dummy mode")
local fp = io.open("noita.dfpwm", "rb") local fp = io.open("noita.dfpwm", "rb")
if fp == nil then if fp == nil then
printError("No sample file found, are you running it on a real* computer without a tape drive?") printError("No sample file found, are you running it on a real computer without a tape drive?")
return return
end end
local size = fp:seek("end", 0) local size = fp:seek("end", 0)
@ -126,38 +126,38 @@ local help = {}
for line in ([[# Movement: for line in ([[# Movement:
-- --
Up k : Move cursor up Up k : Move cursor up
Down j : Move cursor down Dn j : Move cursor down
H : Move cursor to the top of screen H : Jump to top
L : Move cursor to the bottom of screen L : Jump down
PageUp : Page up PgUp : Page up
PageDown : Page down PgDn : Page down
Tab : Next screen
Shift+Tab : Previous screen
1 F1 h : Help screen (this one) Tab : Next screen
2 F2 : Songs list S+Tab : Prev. screen
3 F3 : Options screen
1 F1 : Help screen
2 F2 : Songs list
3 F3 : Settings
# Global: # Global:
-- --
s : Stop and seek to the beginning s : Stop, jump to start
p : Pause/resume p : Pause/resume
< : Next track < : Next track
> : Previous track > : Previous track
f : Seek forward f : Seek forward
b : Seek backward b : Seek backward
Left - : Decrease volume \x11 - : Lower volume
Right + : Increase volume \x10 + : Higher volume
# List screen: # List screen:
-- --
Enter : Play Enter : Play
Ctrl+l : Center Ctrl+l : Center
l : Jump to current track l : Jump to current
]]):gmatch("[^\n]+") do ]]):gsub("\\x11", "\x11"):gsub("\\x10", "\x10"):gmatch("[^\n]+") do
table.insert(help, line) table.insert(help, line)
end end
@ -240,6 +240,7 @@ local mplayer = {
end end
end, end,
handleKey = function(self, key, repeating) handleKey = function(self, key, repeating)
local shiftHeld = self.heldKeys[keys.leftShift] ~= nil or self.heldKeys[keys.rightShift] ~= nil
if key == keys.down or key == keys.j then if key == keys.down or key == keys.j then
self.screens[2].handleScroll(self, 1) self.screens[2].handleScroll(self, 1)
elseif key == keys.up or key == keys.k then elseif key == keys.up or key == keys.k then
@ -248,6 +249,13 @@ local mplayer = {
self.screens[2].handleScroll(self, th - 3) self.screens[2].handleScroll(self, th - 3)
elseif key == keys.pageUp then elseif key == keys.pageUp then
self.screens[2].handleScroll(self, -(th - 3)) self.screens[2].handleScroll(self, -(th - 3))
elseif key == keys.h and shiftHeld then
self.screens[2].handleScroll(self, -#self.songs)
elseif key == keys.l and shiftHeld then
self.screens[2].handleScroll(self, #self.songs)
elseif key == keys.l then
self.screens[2].cursor = self.currentSong or 1
self.screens[2].handleScroll(self, 0, 1, 1)
elseif key == keys.enter then elseif key == keys.enter then
drive.seek(-drive.getSize()) drive.seek(-drive.getSize())
drive.seek(self.songs[self.screens[2].cursor].offset) drive.seek(self.songs[self.screens[2].cursor].offset)
@ -512,3 +520,16 @@ function()
end end
) )
-- cleanup
term.clear()
term.setCursorPos(1, 1)
for i = 1, 16 do
local c = math.pow(2, i - 1)
term.setPaletteColor(c, term.nativePaletteColor(c))
end
term.setBackgroundColor(colors.black)
term.setTextColor(colors.white)
if term.current().setTextScale then
term.current.setTextScale(1.0)
end
print("<tmpc> Goodbye!")