diff options
author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2025-05-05 15:07:23 -0700 |
---|---|---|
committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2025-05-05 15:07:23 -0700 |
commit | df67945f328b87967f63b1fef6060fc1ca8e153c (patch) | |
tree | b1040fa68edf5dd22f1f27a4d2cc07c1626fda52 | |
parent | 5e69e25df6ef735be6e703456ceabedd4d2529ed (diff) | |
download | mpv-iptv-menu-df67945f328b87967f63b1fef6060fc1ca8e153c.tar.gz mpv-iptv-menu-df67945f328b87967f63b1fef6060fc1ca8e153c.tar.xz |
add support for page up and page down keys
-rw-r--r-- | main.lua | 32 |
1 files changed, 28 insertions, 4 deletions
@@ -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) |