summaryrefslogtreecommitdiff
path: root/main.lua
diff options
context:
space:
mode:
Diffstat (limited to 'main.lua')
-rw-r--r--main.lua32
1 files changed, 28 insertions, 4 deletions
diff --git a/main.lua b/main.lua
index 76fc7b8..a2746d5 100644
--- a/main.lua
+++ b/main.lua
@@ -21,6 +21,10 @@ local menus = {categories}
local menu_top = {1}
local menu_pos = {1}
+function osd_menu_lines()
+ return osd_lines - depth + 1
+end
+
function update_osd()
local out = {}
for i = 1, depth - 1 do
@@ -28,7 +32,8 @@ function update_osd()
menus[i][menu_pos[i]]['category_name'] .. ']{\\c}'
end
for i = menu_top[depth], math.min(
- menu_top[depth] + osd_lines - depth, #menus[depth]) do
+ menu_top[depth] + osd_menu_lines() - 1,
+ #menus[depth]) do
local key = (depth == 1 and 'category_name' or 'name')
local str = menus[depth][i][key]
if i == menu_pos[depth] then
@@ -60,13 +65,29 @@ function handle_down()
end
menu_pos[depth] = menu_pos[depth] + 1
- if menu_pos[depth] > menu_top[depth] + osd_lines - depth then
+ if menu_pos[depth] > menu_top[depth] + osd_menu_lines() - 1 then
menu_top[depth] = menu_top[depth] + 1
end
update_osd()
end
+function handle_page_up()
+ menu_pos[depth] = math.max(menu_pos[depth] - osd_menu_lines(), 1)
+ menu_top[depth] = math.max(menu_top[depth] - osd_menu_lines(), 1)
+
+ update_osd()
+end
+
+function handle_page_down()
+ menu_pos[depth] = math.min(menu_pos[depth] + osd_menu_lines(),
+ #menus[depth])
+ menu_top[depth] = math.min(menu_top[depth] + osd_menu_lines(),
+ math.max(1, #menus[depth] - osd_menu_lines() + 1))
+
+ update_osd()
+end
+
function select_category()
local cat = categories[menu_pos[depth]]
local menu = {}
@@ -105,8 +126,11 @@ function handle_backspace()
update_osd()
end
-mp.add_forced_key_binding('UP', 'up', handle_up, {repeatable=true})
-mp.add_forced_key_binding('DOWN', 'down', handle_down, {repeatable=true})
+local repeatable = {repeatable=true}
+mp.add_forced_key_binding('UP', 'up', handle_up, repeatable)
+mp.add_forced_key_binding('DOWN', 'down', handle_down, repeatable)
+mp.add_forced_key_binding('PGUP', 'page_up', handle_page_up, repeatable)
+mp.add_forced_key_binding('PGDWN', 'page_down', handle_page_down, repeatable)
mp.add_forced_key_binding('ENTER', 'enter', handle_enter)
mp.add_forced_key_binding('BS', 'backspace', handle_backspace)