From bff20600581dfed11fcae12dd026bfcc555c4622 Mon Sep 17 00:00:00 2001 From: tomasklaen Date: Wed, 24 Aug 2022 12:23:59 +0200 Subject: [PATCH] style: let language server handle code formatting This is not complete, as I currently can't get the formatter to recognize `.editorconfig` file. Or at least it seems to ignore most of the options in it, so a lot of formatting doesn't adhere to the config. Will need another pass when that gets fixed. --- .editorconfig | 78 ++++++++ .vscode/settings.json | 8 +- uosc.lua | 448 ++++++++++++++++++++++++------------------ 3 files changed, 337 insertions(+), 197 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..4bac1cb --- /dev/null +++ b/.editorconfig @@ -0,0 +1,78 @@ +[*.lua] +# see https://github.com/CppCXY/EmmyLuaCodeStyle + +# [basic] + +indent_style = space +tab_width = 4 +# none/single/double +quote_style = single +continuation_indent_size = 4 +max_line_length = 120 +# crlf/lf/cr/auto +end_of_line = lf +detect_end_of_line = false +insert_final_newline = true + +# [function] + +# true/false/only_after_more_indention_statement/only_not_exist_cross_row_expression +align_call_args = false +align_function_define_params = true +remove_expression_list_finish_comma = true +# keep/remove/remove_table_only/remove_string_only/unambiguous_remove_string_only +call_arg_parentheses = keep + +# [table] + +# none/comma/semicolon +table_separator_style = comma +# keep/never/always/smart +trailing_table_separator = smart +# align equal signs in tables +continuous_assign_table_field_align_to_equal_sign = false +# if true "local t = { 1, 2, 3 }" +keep_one_space_between_table_and_bracket = false + +# [statement] + +align_chained_expression_statement = false +max_continuous_line_distance = 1 +# align equal signs in value assignments +continuous_assign_statement_align_to_equal_sign = false +if_condition_align_with_each_other = false +local_assign_continuation_align_to_first_expression = false +statement_inline_comment_space = 1 + +# [indentation] + +# labels (e.g.::continue::) will not be intended +label_no_indent = false +# no indentation for do statement +do_statement_no_indent = false +# no indentation for conditions of an if statement when on new line +if_condition_no_continuation_indent = false +if_branch_comments_after_block_no_indent = false + +# [space] + +# if true, t[#t+1] will not space wrapper '+' +table_append_expression_no_space = false +long_chain_expression_allow_one_space_after_colon = false +remove_empty_header_and_footer_lines_in_function = true +space_before_function_open_parenthesis = false +space_before_open_square_bracket = false +# format like this "local t = 1" +keep_one_space_between_namedef_and_attribute = false + +# [row_layout] +# Each can be: minLine:${n}, keepLine, keepLine:${n}, maxLine:${n} + +keep_line_after_if_statement = keepLine +keep_line_after_do_statement = keepLine +keep_line_after_while_statement = keepLine +keep_line_after_repeat_statement = keepLine +keep_line_after_for_statement = keepLine +keep_line_after_local_or_assign_statement = keepLine +keep_line_after_function_define_statement = keepLine +keep_line_after_expression_statement = keepLine diff --git a/.vscode/settings.json b/.vscode/settings.json index f003d13..fb797c9 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,8 +1,4 @@ { - "Lua.diagnostics.disable": [ - "lowercase-global" - ], - "Lua.diagnostics.globals": [ - "mp" - ] + "Lua.diagnostics.disable": ["lowercase-global"], + "Lua.diagnostics.globals": ["mp"] } diff --git a/uosc.lua b/uosc.lua index 9f3a4c2..5b3203b 100644 --- a/uosc.lua +++ b/uosc.lua @@ -81,7 +81,7 @@ local options = { window_border_size = 1, window_border_opacity = 0.8, - ui_scale=1, + ui_scale = 1, pause_on_click_shorter_than = 0, flash_duration = 1000, proximity_in = 40, @@ -108,7 +108,7 @@ opt.read_options(options, 'uosc') local config = { -- sets max rendering frequency in case the -- native rendering frequency could not be detected - render_delay = 1/60, + render_delay = 1 / 60, font = mp.get_property('options/osd-font'), } local bold_tag = options.font_bold and '\\b1' or '' @@ -126,7 +126,7 @@ local state = { os = (function() if os.getenv('windir') ~= nil then return 'windows' end local homedir = os.getenv('HOME') - if homedir ~= nil and string.sub(homedir,1,6) == '/Users' then return 'macos' end + if homedir ~= nil and string.sub(homedir, 1, 6) == '/Users' then return 'macos' end return 'linux' end)(), cwd = mp.get_property('working-directory'), @@ -178,13 +178,13 @@ function split(str, pattern) local last_end = 1 local start_index, end_index, capture = str:find(full_pattern, 1) while start_index do - list[#list +1] = capture + list[#list + 1] = capture last_end = end_index + 1 start_index, end_index, capture = str:find(full_pattern, last_end) end if last_end <= (#str + 1) then capture = str:sub(last_end) - list[#list +1] = capture + list[#list + 1] = capture end return list end @@ -265,7 +265,7 @@ local word_order_comparator = (function() default_order = 21 end - return function (a, b) + return function(a, b) a = a:lower() b = b:lower() for i = 1, math.max(#a, #b) do @@ -294,10 +294,12 @@ function tween(from, to, setter, speed, callback) callback = speed speed = 0.3 end + local timeout local getTo = type(to) == 'function' and to or function() return to end local cutoff = math.abs(getTo() - from) * 0.01 - function tick() + + local function tick() from = from + ((getTo() - from) * speed) local is_end = math.abs(getTo() - from) <= cutoff setter(is_end and getTo() or from) @@ -308,8 +310,10 @@ function tween(from, to, setter, speed, callback) timeout:resume() end end + timeout = mp.add_timeout(0.016, tick) tick() + return function() timeout:kill() call_me_maybe(callback) @@ -355,11 +359,11 @@ end function get_point_to_rectangle_proximity(point, rect) local dx = math.max(rect.ax - point.x, 0, point.x - rect.bx + 1) local dy = math.max(rect.ay - point.y, 0, point.y - rect.by + 1) - return math.sqrt(dx*dx + dy*dy); + return math.sqrt(dx * dx + dy * dy); end function text_width_estimate(text, font_size) - if not text or text == "" then return 0 end + if not text or text == '' then return 0 end local text_width = 0 for _, _, width in utf8_iter(text) do text_width = text_width + width @@ -377,7 +381,7 @@ function utf8_iter(string) local char_byte = string.byte(string, byte_start) byte_count = 1; - if char_byte < 192 then byte_count = 1 + if char_byte < 192 then byte_count = 1 elseif char_byte < 224 then byte_count = 2 elseif char_byte < 240 then byte_count = 3 elseif char_byte < 248 then byte_count = 4 @@ -430,13 +434,13 @@ function wrap_text(text, line_width_requested) before_removed_width = remove and char_width or 0 else if (line_width_requested - before_width) < - (line_width_after_remove - line_width_requested) then - lines[#lines+1] = text.sub(text, line_start, before_end) + (line_width_after_remove - line_width_requested) then + lines[#lines + 1] = text.sub(text, line_start, before_end) line_start = before_line_start line_width = line_width - before_width - before_removed_width if before_width > max_width then max_width = before_width end else - lines[#lines+1] = text.sub(text, line_start, remove and char_start - 1 or char_end) + lines[#lines + 1] = text.sub(text, line_start, remove and char_start - 1 or char_end) line_start = char_end + 1 line_width = remove and line_width - char_width or line_width if line_width > max_width then max_width = line_width end @@ -448,7 +452,7 @@ function wrap_text(text, line_width_requested) end end if #text >= line_start then - lines[#lines+1] = string.sub(text, line_start) + lines[#lines + 1] = string.sub(text, line_start) if line_width > max_width then max_width = line_width end end return table.concat(lines, '\n'), max_width @@ -456,19 +460,19 @@ end -- Escape a string for verbatim display on the OSD function ass_escape(str) - -- There is no escape for '\' in ASS (I think?) but '\' is used verbatim if - -- it isn't followed by a recognised character, so add a zero-width - -- non-breaking space - str = str:gsub('\\', '\\\239\187\191') - str = str:gsub('{', '\\{') - str = str:gsub('}', '\\}') - -- Precede newlines with a ZWNBSP to prevent ASS's weird collapsing of - -- consecutive newlines - str = str:gsub('\n', '\239\187\191\\N') - -- Turn leading spaces into hard spaces to prevent ASS from stripping them - str = str:gsub('\\N ', '\\N\\h') - str = str:gsub('^ ', '\\h') - return str + -- There is no escape for '\' in ASS (I think?) but '\' is used verbatim if + -- it isn't followed by a recognised character, so add a zero-width + -- non-breaking space + str = str:gsub('\\', '\\\239\187\191') + str = str:gsub('{', '\\{') + str = str:gsub('}', '\\}') + -- Precede newlines with a ZWNBSP to prevent ASS's weird collapsing of + -- consecutive newlines + str = str:gsub('\n', '\239\187\191\\N') + -- Turn leading spaces into hard spaces to prevent ASS from stripping them + str = str:gsub('\\N ', '\\N\\h') + str = str:gsub('^ ', '\\h') + return str end ---@param seconds number @@ -476,8 +480,8 @@ end function format_time(seconds) local human = mp.format_time(seconds) if options.time_precision > 0 then - local formatted = string.format('%.'..options.time_precision..'f', math.abs(seconds) % 1) - human = human..'.'..string.sub(formatted, 3) + local formatted = string.format('%.' .. options.time_precision .. 'f', math.abs(seconds) % 1) + human = human .. '.' .. string.sub(formatted, 3) end return human end @@ -520,7 +524,7 @@ function normalize_path(path) if state.os == 'windows' then -- Drive letters on windows need trailing backslash if path:sub(#path) == ':' then - path = path..'\\' + path = path .. '\\' end return path:gsub('/', '\\') @@ -549,7 +553,9 @@ function serialize_path(path) local working_path = normal_path:sub(#normal_path) == '\\' and normal_path:sub(1, #normal_path - 1) or normal_path local parts = split(working_path, '[\\/]+') local basename = parts and parts[#parts] or working_path - local dirname = #parts > 1 and table.concat(itable_slice(parts, 1, #parts - 1), state.os == 'windows' and '\\' or '/') or nil + local dirname = #parts > 1 + and table.concat(itable_slice(parts, 1, #parts - 1), state.os == 'windows' and '\\' or '/') + or nil local dot_split = split(basename, '%.') return { @@ -566,7 +572,7 @@ function get_files_in_directory(directory, allowed_types) local files, error = utils.readdir(directory, 'files') if not files then - msg.error('Retrieving files failed: '..(error or '')) + msg.error('Retrieving files failed: ' .. (error or '')) return end @@ -593,10 +599,14 @@ function get_adjacent_file(file_path, direction, allowed_types) if current_file.basename == file then if direction == 'forward' then if files[index + 1] then return utils.join_path(current_file.dirname, files[index + 1]) end - if options.directory_navigation_loops and files[1] then return utils.join_path(current_file.dirname, files[1]) end + if options.directory_navigation_loops and files[1] then + return utils.join_path(current_file.dirname, files[1]) + end else if files[index - 1] then return utils.join_path(current_file.dirname, files[index - 1]) end - if options.directory_navigation_loops and files[#files] then return utils.join_path(current_file.dirname, files[#files]) end + if options.directory_navigation_loops and files[#files] then + return utils.join_path(current_file.dirname, files[#files]) + end end -- This is the only file in directory @@ -609,7 +619,13 @@ end -- Returns `result, error`, result is table of `status:number(<0=error), stdout, stderr, error_string, killed_by_us:boolean` function delete_file(file_path) local args = state.os == 'windows' and {'cmd', '/C', 'del', file_path} or {'rm', file_path} - return mp.command_native({name = 'subprocess', args = args, playback_only = false, capture_stdout = true, capture_stderr = true}) + return mp.command_native({ + name = 'subprocess', + args = args, + playback_only = false, + capture_stdout = true, + capture_stderr = true + }) end -- Ensures chapters are in chronological order @@ -628,7 +644,7 @@ function get_normalized_chapters() end function is_element_persistent(name) - local option_name = name..'_persistency'; + local option_name = name .. '_persistency'; return (options[option_name].audio and state.is_audio) or (options[option_name].paused and state.pause) end @@ -638,11 +654,11 @@ Signature: { -- element rectangle coordinates ax = 0, ay = 0, bx = 0, by = 0, - -- cursor<>element relative proximity as a 0-1 floating number + -- cursor<->element relative proximity as a 0-1 floating number -- where 0 = completely away, and 1 = touching/hovering -- so it's easy to work with and throw into equations proximity = 0, - -- raw cursor<>element proximity in pixels + -- raw cursor<->element proximity in pixels proximity_raw = infinity, -- called when element is created ?init = function(this), @@ -681,6 +697,7 @@ function Element.new(props) end function Element:init() end + function Element:destroy() end -- Call method if it exists @@ -690,8 +707,11 @@ end -- Tween helpers function Element:tween(...) tween_element(self, ...) end + function Element:tween_property(...) tween_element_property(self, ...) end + function Element:tween_stop() tween_element_stop(self) end + function Element:is_tweening() tween_element_is_tweening(self) end -- Event listeners @@ -704,13 +724,15 @@ function Element:on(name, handler) self._eventListeners[name][#self._eventListeners[name] + 1] = handler end end + function Element:off(name, handler) if self._eventListeners[name] == nil then return end local index = itable_find(self._eventListeners, handler) if index then table.remove(self._eventListeners, index) end end + function Element:trigger(name, ...) - self:maybe('on_'..name, ...) + self:maybe('on_' .. name, ...) if self._eventListeners[name] == nil then return end for _, handler in ipairs(self._eventListeners[name]) do handler(...) end request_render() @@ -762,6 +784,7 @@ function Elements:trigger(name, ...) end function Elements:has(name) return self[name] ~= nil end + function Elements:ipairs() return ipairs(self.itable) end -- MENU @@ -887,15 +910,15 @@ function Menu:open(items, open_item, opts) local hint_icon = item.hint or (has_submenu and 'M' or nil) local hint_icon_size = item.hint and this.font_size_hint or this.font_size local estimated_width = text_width_estimate(item.title, this.font_size) - + text_width_estimate(hint_icon, hint_icon_size) - + (this.item_content_spacing * spacings_in_item) + + text_width_estimate(hint_icon, hint_icon_size) + + (this.item_content_spacing * spacings_in_item) if estimated_width > estimated_max_width then estimated_max_width = estimated_width end end -- Also check menu title - local menu_title = this.title and this.title or "" + local menu_title = this.title and this.title or '' local estimated_menu_title_width = text_width_estimate(menu_title, this.font_size) if estimated_menu_title_width > estimated_max_width then estimated_max_width = estimated_menu_title_width @@ -1157,38 +1180,38 @@ function Menu:enable_key_bindings() menu.key_bindings = {} -- The `mp.set_key_bindings()` method would be easier here, but that -- doesn't support 'repeatable' flag, so we are stuck with this monster. - menu:add_key_binding('up', 'menu-prev1', self:create_action('prev'), 'repeatable') - menu:add_key_binding('down', 'menu-next1', self:create_action('next'), 'repeatable') - menu:add_key_binding('left', 'menu-back1', self:create_action('back')) - menu:add_key_binding('right', 'menu-select1', self:create_action('open_selected_item')) - menu:add_key_binding('shift+right', 'menu-select-soft1', self:create_action('open_selected_item_soft')) - menu:add_key_binding('shift+mbtn_left', 'menu-select-soft', self:create_action('open_selected_item_soft')) + menu:add_key_binding('up', 'menu-prev1', self:create_action('prev'), 'repeatable') + menu:add_key_binding('down', 'menu-next1', self:create_action('next'), 'repeatable') + menu:add_key_binding('left', 'menu-back1', self:create_action('back')) + menu:add_key_binding('right', 'menu-select1', self:create_action('open_selected_item')) + menu:add_key_binding('shift+right', 'menu-select-soft1', self:create_action('open_selected_item_soft')) + menu:add_key_binding('shift+mbtn_left', 'menu-select-soft', self:create_action('open_selected_item_soft')) if options.menu_wasd_navigation then - menu:add_key_binding('w', 'menu-prev2', self:create_action('prev'), 'repeatable') - menu:add_key_binding('a', 'menu-back2', self:create_action('back')) - menu:add_key_binding('s', 'menu-next2', self:create_action('next'), 'repeatable') - menu:add_key_binding('d', 'menu-select2', self:create_action('open_selected_item')) + menu:add_key_binding('w', 'menu-prev2', self:create_action('prev'), 'repeatable') + menu:add_key_binding('a', 'menu-back2', self:create_action('back')) + menu:add_key_binding('s', 'menu-next2', self:create_action('next'), 'repeatable') + menu:add_key_binding('d', 'menu-select2', self:create_action('open_selected_item')) menu:add_key_binding('shift+d', 'menu-select-soft2', self:create_action('open_selected_item_soft')) end if options.menu_hjkl_navigation then - menu:add_key_binding('h', 'menu-back3', self:create_action('back')) - menu:add_key_binding('j', 'menu-next3', self:create_action('next'), 'repeatable') - menu:add_key_binding('k', 'menu-prev3', self:create_action('prev'), 'repeatable') - menu:add_key_binding('l', 'menu-select3', self:create_action('open_selected_item')) + menu:add_key_binding('h', 'menu-back3', self:create_action('back')) + menu:add_key_binding('j', 'menu-next3', self:create_action('next'), 'repeatable') + menu:add_key_binding('k', 'menu-prev3', self:create_action('prev'), 'repeatable') + menu:add_key_binding('l', 'menu-select3', self:create_action('open_selected_item')) menu:add_key_binding('shift+l', 'menu-select-soft3', self:create_action('open_selected_item_soft')) end - menu:add_key_binding('mbtn_back', 'menu-back-alt3', self:create_action('back')) - menu:add_key_binding('bs', 'menu-back-alt4', self:create_action('back')) - menu:add_key_binding('enter', 'menu-select-alt3', self:create_action('open_selected_item')) - menu:add_key_binding('kp_enter', 'menu-select-alt4', self:create_action('open_selected_item')) - menu:add_key_binding('esc', 'menu-close', self:create_action('close')) - menu:add_key_binding('pgup', 'menu-page-up', self:create_action('on_pgup')) - menu:add_key_binding('pgdwn', 'menu-page-down', self:create_action('on_pgdwn')) - menu:add_key_binding('home', 'menu-home', self:create_action('on_home')) - menu:add_key_binding('end', 'menu-end', self:create_action('on_end')) + menu:add_key_binding('mbtn_back', 'menu-back-alt3', self:create_action('back')) + menu:add_key_binding('bs', 'menu-back-alt4', self:create_action('back')) + menu:add_key_binding('enter', 'menu-select-alt3', self:create_action('open_selected_item')) + menu:add_key_binding('kp_enter', 'menu-select-alt4', self:create_action('open_selected_item')) + menu:add_key_binding('esc', 'menu-close', self:create_action('close')) + menu:add_key_binding('pgup', 'menu-page-up', self:create_action('on_pgup')) + menu:add_key_binding('pgdwn', 'menu-page-down', self:create_action('on_pgdwn')) + menu:add_key_binding('home', 'menu-home', self:create_action('on_home')) + menu:add_key_binding('end', 'menu-end', self:create_action('on_end')) end function Menu:disable_key_bindings() @@ -1206,7 +1229,7 @@ function Menu:close(immediate, callback) if type(immediate) ~= 'boolean' then callback = immediate end if elements:has('menu') and not menu.is_closing then - function close() + local function close() elements.menu:maybe('on_close') elements.menu:destroy() elements:remove('menu') @@ -1244,8 +1267,8 @@ local icons = {} function icon(name, icon_x, icon_y, icon_size, shad_x, shad_y, shad_size, backdrop, opacity, clip) local ass = assdraw.ass_new() local icon_path = icons[name](icon_x, icon_y, icon_size) - local icon_color = options['color_'..backdrop..'_text'] - local shad_color = options['color_'..backdrop] + local icon_color = options['color_' .. backdrop .. '_text'] + local shad_color = options['color_' .. backdrop] local use_border = (shad_x + shad_y) == 0 local icon_border = use_border and shad_size or 0 @@ -1258,7 +1281,7 @@ function icon(name, icon_x, icon_y, icon_size, shad_x, shad_y, shad_size, backdr if not use_border then ass:new_event() - ass:append('{\\blur0\\bord0\\shad0\\1c&H'..shad_color..'\\iclip('..ass.scale..', '..icon_path..')}') + ass:append('{\\blur0\\bord0\\shad0\\1c&H' .. shad_color .. '\\iclip(' .. ass.scale .. ', ' .. icon_path .. ')}') ass:append(ass_opacity(opacity)) ass:pos(shad_x + shad_size, shad_y + shad_size) ass:draw_start() @@ -1267,7 +1290,7 @@ function icon(name, icon_x, icon_y, icon_size, shad_x, shad_y, shad_size, backdr end ass:new_event() - ass:append('{\\blur0\\bord'..icon_border..'\\shad0\\1c&H'..icon_color..'\\3c&H'..shad_color..clip..'}') + ass:append('{\\blur0\\bord' .. icon_border .. '\\shad0\\1c&H' .. icon_color .. '\\3c&H' .. shad_color .. clip .. '}') ass:append(ass_opacity(opacity)) ass:pos(0, 0) ass:draw_start() @@ -1280,8 +1303,8 @@ end function icons._volume(muted, pos_x, pos_y, size) local ass = assdraw.ass_new() local scale = size / 200 - function x(number) return pos_x + (number * scale) end - function y(number) return pos_y + (number * scale) end + local function x(number) return pos_x + (number * scale) end + local function y(number) return pos_y + (number * scale) end ass:move_to(x(-85), y(-35)) ass:line_to(x(-50), y(-35)) ass:line_to(x(-5), y(-75)) @@ -1289,35 +1312,49 @@ function icons._volume(muted, pos_x, pos_y, size) ass:line_to(x(-50), y(35)) ass:line_to(x(-85), y(35)) if muted then - ass:move_to(x(76), y(-35)) ass:line_to(x(50), y(-9)) ass:line_to(x(24), y(-35)) - ass:line_to(x(15), y(-26)) ass:line_to(x(41), y(0)) ass:line_to(x(15), y(26)) - ass:line_to(x(24), y(35)) ass:line_to(x(50), y(9)) ass:line_to(x(76), y(35)) - ass:line_to(x(85), y(26)) ass:line_to(x(59), y(0)) ass:line_to(x(85), y(-26)) + ass:move_to(x(76), y(-35)) + ass:line_to(x(50), y(-9)) + ass:line_to(x(24), y(-35)) + ass:line_to(x(15), y(-26)) + ass:line_to(x(41), y(0)) + ass:line_to(x(15), y(26)) + ass:line_to(x(24), y(35)) + ass:line_to(x(50), y(9)) + ass:line_to(x(76), y(35)) + ass:line_to(x(85), y(26)) + ass:line_to(x(59), y(0)) + ass:line_to(x(85), y(-26)) else - ass:move_to(x(20), y(-30)) ass:line_to(x(20), y(30)) - ass:line_to(x(35), y(30)) ass:line_to(x(35), y(-30)) + ass:move_to(x(20), y(-30)) + ass:line_to(x(20), y(30)) + ass:line_to(x(35), y(30)) + ass:line_to(x(35), y(-30)) - ass:move_to(x(55), y(-60)) ass:line_to(x(55), y(60)) - ass:line_to(x(70), y(60)) ass:line_to(x(70), y(-60)) + ass:move_to(x(55), y(-60)) + ass:line_to(x(55), y(60)) + ass:line_to(x(70), y(60)) + ass:line_to(x(70), y(-60)) end return ass.text end + function icons.volume(pos_x, pos_y, size) return icons._volume(false, pos_x, pos_y, size) end + function icons.volume_muted(pos_x, pos_y, size) return icons._volume(true, pos_x, pos_y, size) end function icons.menu_button(pos_x, pos_y, size) local ass = assdraw.ass_new() local scale = size / 100 - function x(number) return pos_x + (number * scale) end - function y(number) return pos_y + (number * scale) end + local function x(number) return pos_x + (number * scale) end + local function y(number) return pos_y + (number * scale) end local line_height = 14 local line_spacing = 18 for i = -1, 1 do - local offs = i * (line_height + line_spacing) - ass:move_to(x(-50), y(offs - line_height/2)) - ass:line_to(x(50), y(offs - line_height/2)) - ass:line_to(x(50), y(offs + line_height/2)) - ass:line_to(x(-50), y(offs + line_height/2)) + local offs = i * (line_height + line_spacing) + ass:move_to(x(-50), y(offs - line_height / 2)) + ass:line_to(x(50), y(offs - line_height / 2)) + ass:line_to(x(50), y(offs + line_height / 2)) + ass:line_to(x(-50), y(offs + line_height / 2)) end return ass.text end @@ -1325,8 +1362,8 @@ end function icons.arrow_right(pos_x, pos_y, size) local ass = assdraw.ass_new() local scale = size / 200 - function x(number) return pos_x + (number * scale) end - function y(number) return pos_y + (number * scale) end + local function x(number) return pos_x + (number * scale) end + local function y(number) return pos_y + (number * scale) end ass:move_to(x(-22), y(-80)) ass:line_to(x(-45), y(-57)) ass:line_to(x(12), y(0)) @@ -1339,7 +1376,7 @@ end -- STATE UPDATES function update_display_dimensions() - local dpi_scale = mp.get_property_native("display-hidpi-scale", 1.0) + local dpi_scale = mp.get_property_native('display-hidpi-scale', 1.0) dpi_scale = dpi_scale * options.ui_scale local width, height, aspect = mp.get_osd_size() @@ -1362,7 +1399,8 @@ function update_element_cursor_proximity(element) else local range = options.proximity_out - options.proximity_in element.proximity_raw = get_point_to_rectangle_proximity(cursor, element) - element.proximity = menu:is_open() and 0 or 1 - (math.min(math.max(element.proximity_raw - options.proximity_in, 0), range) / range) + element.proximity = menu:is_open() and 0 or + 1 - (math.min(math.max(element.proximity_raw - options.proximity_in, 0), range) / range) end end @@ -1500,12 +1538,12 @@ function render_timeline(this) local time_x = bax + time_padding local time_width = this.width - time_padding * 2 local foreground_size = bby - bay - local foreground_coordinates = fax..','..fay..','..fbx..','..fby -- for clipping + local foreground_coordinates = fax .. ',' .. fay .. ',' .. fbx .. ',' .. fby -- for clipping -- Background ass:new_event() ass:pos(0, 0) - ass:append('{\\blur0\\bord0\\1c&H'..options.color_background..'\\iclip('..foreground_coordinates..')}') + ass:append('{\\blur0\\bord0\\1c&H' .. options.color_background .. '\\iclip(' .. foreground_coordinates .. ')}') ass:append(ass_opacity(math.max(options.timeline_opacity - 0.1, 0))) ass:draw_start() ass:rect_cw(bax, bay, bbx, bby) @@ -1514,7 +1552,7 @@ function render_timeline(this) -- Progress local function render_progress() ass:new_event() - ass:append('{\\blur0\\bord0\\1c&H'..options.color_foreground..'}') + ass:append('{\\blur0\\bord0\\1c&H' .. options.color_foreground .. '}') ass:append(ass_opacity(options.timeline_opacity)) ass:pos(0, 0) ass:draw_start() @@ -1530,7 +1568,7 @@ function render_timeline(this) local rax = time_x + time_width * (range['start'].time / state.duration) local rbx = time_x + time_width * (range['end'].time / state.duration) ass:new_event() - ass:append('{\\blur0\\bord0\\1c&H'..chapter_range.color..'}') + ass:append('{\\blur0\\bord0\\1c&H' .. chapter_range.color .. '}') ass:append(ass_opacity(chapter_range.opacity)) ass:pos(0, 0) ass:draw_start() @@ -1550,12 +1588,12 @@ function render_timeline(this) local function render_chapters() if ( options.timeline_chapters == 'never' - or ( + or ( (state.chapters == nil or #state.chapters == 0) - and state.ab_loop_a == nil - and state.ab_loop_b == nil - ) - ) then return end + and state.ab_loop_a == nil + and state.ab_loop_b == nil + ) + ) then return end local dots = false -- Defaults are for `lines` @@ -1586,7 +1624,7 @@ function render_timeline(this) local color = (fax < chapter_x and chapter_x < fbx) and options.color_background or options.color_foreground ass:new_event() - ass:append('{\\blur0\\bord0\\1c&H'..color..'}') + ass:append('{\\blur0\\bord0\\1c&H' .. color .. '}') ass:append(ass_opacity(options.timeline_chapters_opacity)) ass:pos(0, 0) ass:draw_start() @@ -1642,7 +1680,7 @@ function render_timeline(this) for _, range in ipairs(state.cached_ranges) do ass:new_event() - ass:append('{\\blur0\\bord0\\1c&H'..options.timeline_cached_ranges.color..'}') + ass:append('{\\blur0\\bord0\\1c&H' .. options.timeline_cached_ranges.color .. '}') ass:append(ass_opacity(options.timeline_cached_ranges.opacity)) ass:pos(0, 0) ass:draw_start() @@ -1659,13 +1697,13 @@ function render_timeline(this) if time_padding > 0 then local notch_ay = math.max(range_ay - 2, fay) ass:new_event() - ass:append('{\\blur0\\bord0\\1c&H'..options.timeline_cached_ranges.color..'}') + ass:append('{\\blur0\\bord0\\1c&H' .. options.timeline_cached_ranges.color .. '}') ass:pos(0, 0) ass:draw_start() ass:rect_cw(time_x, notch_ay, time_x + 1, bby) ass:draw_stop() ass:new_event() - ass:append('{\\blur0\\bord0\\1c&H'..options.timeline_cached_ranges.color..'}') + ass:append('{\\blur0\\bord0\\1c&H' .. options.timeline_cached_ranges.color .. '}') ass:pos(0, 0) ass:draw_start() ass:rect_cw(time_x + time_width - 1, notch_ay, time_x + time_width, bby) @@ -1682,13 +1720,16 @@ function render_timeline(this) local elapsed_x = bax + spacing local elapsed_y = fay + (size / 2) ass:new_event() - ass:append('{\\blur0\\bord0\\shad0\\1c&H'..options.color_foreground_text..'\\fn'..config.font..'\\fs'..this.font_size..bold_tag..'\\clip('..foreground_coordinates..')') + ass:append('{\\blur0\\bord0\\shad0\\1c&H' .. options.color_foreground_text .. '\\fn' .. config.font .. + '\\fs' .. this.font_size .. bold_tag .. '\\clip(' .. foreground_coordinates .. ')') ass:append(ass_opacity(math.min(options.timeline_opacity + 0.1, 1), text_opacity)) ass:pos(elapsed_x, elapsed_y) ass:an(4) ass:append(state.time_human) ass:new_event() - ass:append('{\\blur0\\bord0\\shad1\\1c&H'..options.color_background_text..'\\4c&H'..options.color_background..'\\fn'..config.font..'\\fs'..this.font_size..bold_tag..'\\iclip('..foreground_coordinates..')') + ass:append('{\\blur0\\bord0\\shad1\\1c&H' .. options.color_background_text .. + '\\4c&H' .. options.color_background .. '\\fn' .. config.font .. '\\fs' .. this.font_size .. + bold_tag .. '\\iclip(' .. foreground_coordinates .. ')') ass:append(ass_opacity(math.min(options.timeline_opacity + 0.1, 1), text_opacity)) ass:pos(elapsed_x, elapsed_y) ass:an(4) @@ -1700,13 +1741,16 @@ function render_timeline(this) local end_x = bbx - spacing local end_y = fay + (size / 2) ass:new_event() - ass:append('{\\blur0\\bord0\\shad0\\1c&H'..options.color_foreground_text..'\\fn'..config.font..'\\fs'..this.font_size..bold_tag..'\\clip('..foreground_coordinates..')') + ass:append('{\\blur0\\bord0\\shad0\\1c&H' .. options.color_foreground_text .. '\\fn' .. config.font .. + '\\fs' .. this.font_size .. bold_tag .. '\\clip(' .. foreground_coordinates .. ')') ass:append(ass_opacity(math.min(options.timeline_opacity + 0.1, 1), text_opacity)) ass:pos(end_x, end_y) ass:an(6) ass:append(state.duration_or_remaining_time_human) ass:new_event() - ass:append('{\\blur0\\bord0\\shad1\\1c&H'..options.color_background_text..'\\4c&H'..options.color_background..'\\fn'..config.font..'\\fs'..this.font_size..bold_tag..'\\iclip('..foreground_coordinates..')') + ass:append('{\\blur0\\bord0\\shad1\\1c&H' .. options.color_background_text .. + '\\4c&H' .. options.color_background .. '\\fn' .. config.font .. '\\fs' .. this.font_size .. + bold_tag .. '\\iclip(' .. foreground_coordinates .. ')') ass:append(ass_opacity(math.min(options.timeline_opacity + 0.1, 1), text_opacity)) ass:pos(end_x, end_y) ass:an(6) @@ -1752,13 +1796,15 @@ function render_timeline(this) local margin_time = text_width_estimate(time_formatted, this.font_size) / 2 local margin_title = chapter_title_width * this.font_size * options.font_height_to_letter_width_ratio / 2 ass:new_event() - ass:append('{\\blur0\\bord1\\shad0\\1c&H'..options.color_background_text..'\\3c&H'..options.color_background..'\\fn'..config.font..'\\fs'..this.font_size..'\\b1') + ass:append('{\\blur0\\bord1\\shad0\\1c&H' .. options.color_background_text .. + '\\3c&H' .. options.color_background .. '\\fn' .. config.font .. '\\fs' .. this.font_size .. '\\b1') ass:append(ass_opacity(math.min(options.timeline_opacity + 0.1, 1))) ass:pos(math.min(math.max(cursor.x, margin_title), display.width - margin_title), fay - this.font_size * 1.5) ass:an(2) ass:append(chapter_title) ass:new_event() - ass:append('{\\blur0\\bord1\\shad0\\1c&H'..options.color_background_text..'\\3c&H'..options.color_background..'\\fn'..config.font..'\\fs'..this.font_size..bold_tag) + ass:append('{\\blur0\\bord1\\shad0\\1c&H' .. options.color_background_text .. + '\\3c&H' .. options.color_background .. '\\fn' .. config.font .. '\\fs' .. this.font_size .. bold_tag) ass:append(ass_opacity(math.min(options.timeline_opacity + 0.1, 1))) ass:pos(math.min(math.max(cursor.x, margin_time), display.width - margin_time), fay) ass:an(2) @@ -1766,7 +1812,8 @@ function render_timeline(this) -- Cursor line ass:new_event() - ass:append('{\\blur0\\bord0\\xshad-1\\yshad0\\1c&H'..options.color_foreground..'\\4c&H'..options.color_background..'}') + ass:append('{\\blur0\\bord0\\xshad-1\\yshad0\\1c&H' .. options.color_foreground .. + '\\4c&H' .. options.color_background .. '}') ass:append(ass_opacity(0.2)) ass:pos(0, 0) ass:draw_start() @@ -1860,10 +1907,11 @@ function render_top_bar(this) -- Window title if options.top_bar_title and state.media_title then - local clip_coordinates = this.ax..','..this.ay..','..(this.title_bx - this.spacing)..','..this.by + local clip_coordinates = this.ax .. ',' .. this.ay .. ',' .. (this.title_bx - this.spacing) .. ',' .. this.by ass:new_event() - ass:append('{\\q2\\blur0\\bord1\\shad0\\1c&HFFFFFF\\3c&H000000\\fn'..config.font..'\\fs'..this.font_size..bold_tag..'\\clip('..clip_coordinates..')') + ass:append('{\\q2\\blur0\\bord1\\shad0\\1c&HFFFFFF\\3c&H000000\\fn' .. + config.font .. '\\fs' .. this.font_size .. bold_tag .. '\\clip(' .. clip_coordinates .. ')') ass:append(ass_opacity(1, opacity)) ass:pos(this.ax + this.spacing, this.ay + (this.size / 2)) ass:an(4) @@ -1894,7 +1942,8 @@ function render_volume(this) -- Foreground bar coordinates local height_without_border = slider.height - (options.volume_border * 2) local fax = slider.ax + options.volume_border - local fay = slider.ay + (height_without_border * (1 - math.min(state.volume / state.volume_max, 1))) + options.volume_border + local fay = slider.ay + (height_without_border * (1 - math.min(state.volume / state.volume_max, 1))) + + options.volume_border local fbx = slider.bx - options.volume_border local fby = slider.by - options.volume_border @@ -1936,7 +1985,8 @@ function render_volume(this) -- Background ass:new_event() - ass:append('{\\blur0\\bord0\\1c&H'..options.color_background..'\\iclip('..fpath.scale..', '..fpath.text..')}') + ass:append('{\\blur0\\bord0\\1c&H' .. options.color_background .. + '\\iclip(' .. fpath.scale .. ', ' .. fpath.text .. ')}') ass:append(ass_opacity(math.max(options.volume_opacity - 0.1, 0), opacity)) ass:pos(0, 0) ass:draw_start() @@ -1960,7 +2010,7 @@ function render_volume(this) -- Foreground ass:new_event() - ass:append('{\\blur0\\bord0\\1c&H'..options.color_foreground..'}') + ass:append('{\\blur0\\bord0\\1c&H' .. options.color_foreground .. '}') ass:append(ass_opacity(options.volume_opacity, opacity)) ass:pos(0, 0) ass:draw_start() @@ -1972,7 +2022,8 @@ function render_volume(this) local font_size = round(((this.width * 0.6) - (#volume_string * (this.width / 20))) * options.volume_font_scale) if fay < slider.by - slider.spacing then ass:new_event() - ass:append('{\\blur0\\bord0\\shad0\\1c&H'..options.color_foreground_text..'\\fn'..config.font..'\\fs'..font_size..bold_tag..'\\clip('..fpath.scale..', '..fpath.text..')}') + ass:append('{\\blur0\\bord0\\shad0\\1c&H' .. options.color_foreground_text .. '\\fn' .. config.font .. + '\\fs' .. font_size .. bold_tag .. '\\clip(' .. fpath.scale .. ', ' .. fpath.text .. ')}') ass:append(ass_opacity(math.min(options.volume_opacity + 0.1, 1), opacity)) ass:pos(slider.ax + (slider.width / 2), slider.by - slider.spacing) ass:an(2) @@ -1980,7 +2031,9 @@ function render_volume(this) end if fay > slider.by - slider.spacing - font_size then ass:new_event() - ass:append('{\\blur0\\bord0\\shad1\\1c&H'..options.color_background_text..'\\4c&H'..options.color_background..'\\fn'..config.font..'\\fs'..font_size..bold_tag..'\\iclip('..fpath.scale..', '..fpath.text..')}') + ass:append('{\\blur0\\bord0\\shad1\\1c&H' .. options.color_background_text .. + '\\4c&H' .. options.color_background .. '\\fn' .. config.font .. '\\fs' .. font_size .. bold_tag .. + '\\iclip(' .. fpath.scale .. ', ' .. fpath.text .. ')}') ass:append(ass_opacity(math.min(options.volume_opacity + 0.1, 1), opacity)) ass:pos(slider.ax + (slider.width / 2), slider.by - slider.spacing) ass:an(2) @@ -1996,7 +2049,7 @@ function render_volume(this) icon_name, mute.ax + (mute.width / 2), mute.ay + (mute.height / 2), mute.width * 0.7, -- x, y, size 0, 0, options.volume_border, -- shadow_x, shadow_y, shadow_size - 'background', options.volume_opacity * opacity -- backdrop, opacity + 'background', options.volume_opacity * opacity-- backdrop, opacity )) return ass end @@ -2074,9 +2127,10 @@ function render_speed(this) ass:draw_stop() -- Speed value - local speed_text = (round(state.speed * 100) / 100)..'x' + local speed_text = (round(state.speed * 100) / 100) .. 'x' ass:new_event() - ass:append('{\\blur0\\bord1\\shad0\\1c&H'..options.color_background_text..'\\3c&H'..options.color_background..'\\fn'..config.font..'\\fs'..this.font_size..bold_tag..'}') + ass:append('{\\blur0\\bord1\\shad0\\1c&H' .. options.color_background_text .. + '\\3c&H' .. options.color_background .. '\\fn' .. config.font .. '\\fs' .. this.font_size .. bold_tag .. '}') ass:append(ass_opacity(options.speed_opacity, opacity)) ass:pos(half_x, ay) ass:an(8) @@ -2097,10 +2151,10 @@ function render_menu_button(this) local burger = elements.menu_button ass:new_event() ass:append(icon( - 'menu_button', + 'menu_button', burger.ax + (burger.width / 2), burger.ay + (burger.height / 2), burger.width, -- x, y, size 0, 0, options.menu_button_border, -- shadow_x, shadow_y, shadow_size - 'background', options.menu_button_opacity * opacity -- backdrop, opacity + 'background', options.menu_button_opacity * opacity-- backdrop, opacity )) return ass end @@ -2116,7 +2170,7 @@ function render_menu(this) if this.title then -- Background ass:new_event() - ass:append('{\\blur0\\bord0\\1c&H'..options.color_background..'}') + ass:append('{\\blur0\\bord0\\1c&H' .. options.color_background .. '}') ass:append(ass_opacity(options.menu_opacity, this.opacity)) ass:pos(0, 0) ass:draw_start() @@ -2125,14 +2179,16 @@ function render_menu(this) -- Title ass:new_event() - ass:append('{\\blur0\\bord0\\shad1\\b1\\1c&H'..options.color_background_text..'\\4c&H'..options.color_background..'\\fn'..config.font..'\\fs'..this.font_size..'\\q2\\clip('..this.ax..','..this.ay - this.item_height..','..this.bx..','..this.ay..')}') + ass:append('{\\blur0\\bord0\\shad1\\b1\\1c&H' .. options.color_background_text .. + '\\4c&H' .. options.color_background .. '\\fn' .. config.font .. '\\fs' .. this.font_size .. + '\\q2\\clip(' .. this.ax .. ',' .. this.ay - this.item_height .. ',' .. this.bx .. ',' .. this.ay .. ')}') ass:append(ass_opacity(options.menu_opacity, this.opacity)) ass:pos(display.width / 2, this.ay - (this.item_height * 0.5)) ass:an(5) ass:append(this.title) end - local scroll_area_clip = '\\clip('..this.ax..','..this.ay..','..this.bx..','..this.by..')' + local scroll_area_clip = '\\clip(' .. this.ax .. ',' .. this.ay .. ',' .. this.bx .. ',' .. this.by .. ')' for index, item in ipairs(this.items) do local item_ay = this.ay - this.scroll_y + (this.item_height * (index - 1) + this.item_spacing * (index - 1)) @@ -2154,7 +2210,7 @@ function render_menu(this) ass_shadow, ass_shadow_color = '\\shad0', '' else font_color, background_color = options.color_background_text, options.color_background - ass_shadow, ass_shadow_color = '\\shad1', '\\4c&H'..background_color + ass_shadow, ass_shadow_color = '\\shad1', '\\4c&H' .. background_color end local has_submenu = item.items ~= nil @@ -2167,7 +2223,7 @@ function render_menu(this) -- Background ass:new_event() - ass:append('{\\blur0\\bord0\\1c&H'..background_color..item_clip..'}') + ass:append('{\\blur0\\bord0\\1c&H' .. background_color .. item_clip .. '}') ass:append(ass_opacity(options.menu_opacity, this.opacity)) ass:pos(0, 0) ass:draw_start() @@ -2177,7 +2233,7 @@ function render_menu(this) -- Selected highlight if this.selected_index == index then ass:new_event() - ass:append('{\\blur0\\bord0\\1c&H'..options.color_foreground..item_clip..'}') + ass:append('{\\blur0\\bord0\\1c&H' .. options.color_foreground .. item_clip .. '}') ass:append(ass_opacity(0.1, this.opacity)) ass:pos(0, 0) ass:draw_start() @@ -2187,11 +2243,14 @@ function render_menu(this) -- Title if item.title then - item.ass_save_title = item.ass_save_title or item.title:gsub("([{}])","\\%1") + item.ass_save_title = item.ass_save_title or item.title:gsub('([{}])', '\\%1') local title_clip_x = (this.bx - hint_width - this.item_content_spacing) - local title_clip = '\\clip('..this.ax..','..math.max(item_ay, this.ay)..','..title_clip_x..','..math.min(item_by, this.by)..')' + local title_clip = '\\clip(' .. + this.ax .. ',' .. math.max(item_ay, this.ay) .. ',' .. + title_clip_x .. ',' .. math.min(item_by, this.by) .. ')' ass:new_event() - ass:append('{\\blur0\\bord0\\shad1\\1c&H'..font_color..'\\4c&H'..background_color..'\\fn'..config.font..'\\fs'..this.font_size..bold_tag..title_clip..'\\q2}') + ass:append('{\\blur0\\bord0\\shad1\\1c&H' .. font_color .. '\\4c&H' .. background_color .. + '\\fn' .. config.font .. '\\fs' .. this.font_size .. bold_tag .. title_clip .. '\\q2}') ass:append(ass_opacity(options.menu_opacity, this.opacity)) ass:pos(this.ax + this.item_content_spacing, item_ay + (this.item_height / 2)) ass:an(4) @@ -2200,9 +2259,10 @@ function render_menu(this) -- Hint if item.hint then - item.ass_save_hint = item.ass_save_hint or item.hint:gsub("([{}])","\\%1") + item.ass_save_hint = item.ass_save_hint or item.hint:gsub('([{}])', '\\%1') ass:new_event() - ass:append('{\\blur0\\bord0'..ass_shadow..'\\1c&H'..font_color..''..ass_shadow_color..'\\fn'..config.font..'\\fs'..this.font_size_hint..bold_tag..item_clip..'}') + ass:append('{\\blur0\\bord0' .. ass_shadow .. '\\1c&H' .. font_color .. '' .. ass_shadow_color .. + '\\fn' .. config.font .. '\\fs' .. this.font_size_hint .. bold_tag .. item_clip .. '}') ass:append(ass_opacity(options.menu_opacity * (has_submenu and 1 or 0.5), this.opacity)) ass:pos(this.bx - this.item_content_spacing, item_ay + (this.item_height / 2)) ass:an(6) @@ -2228,7 +2288,7 @@ function render_menu(this) local thumb_height = math.max((this.height / (this.scroll_height + this.height)) * groove_height, 40) local thumb_y = this.ay + 1 + ((this.scroll_y / this.scroll_height) * (groove_height - thumb_height)) ass:new_event() - ass:append('{\\blur0\\bord0\\1c&H'..options.color_foreground..'}') + ass:append('{\\blur0\\bord0\\1c&H' .. options.color_foreground .. '}') ass:append(ass_opacity(options.menu_opacity, this.opacity * 0.8)) ass:pos(0, 0) ass:draw_start() @@ -2294,16 +2354,18 @@ elements:add('window_border', Element.new({ this:update_size(); end, update_size = function(this) - this.size = options.window_border_size > 0 and not state.fullormaxed and not state.border and options.window_border_size or 0 + this.size = options.window_border_size > 0 and not state.fullormaxed and not state.border and + options.window_border_size or 0 end, on_prop_border = function(this) this:update_size() end, on_prop_fullormaxed = function(this) this:update_size() end, render = function(this) if this.size > 0 then local ass = assdraw.ass_new() - local clip_coordinates = this.size..','..this.size..','..(display.width - this.size)..','..(display.height - this.size) + local clip_coordinates = this.size .. + ',' .. this.size .. ',' .. (display.width - this.size) .. ',' .. (display.height - this.size) ass:new_event() - ass:append('{\\blur0\\bord0\\1c&H'..options.color_background..'\\iclip('..clip_coordinates..')}') + ass:append('{\\blur0\\bord0\\1c&H' .. options.color_background .. '\\iclip(' .. clip_coordinates .. ')}') ass:append(ass_opacity(options.window_border_opacity)) ass:pos(0, 0) ass:draw_start() @@ -2361,7 +2423,7 @@ elements:add('pause_indicator', Element.new({ -- Background fadeout if is_static then ass:new_event() - ass:append('{\\blur0\\bord0\\1c&H'..options.color_background..'}') + ass:append('{\\blur0\\bord0\\1c&H' .. options.color_background .. '}') ass:append(ass_opacity(0.3, this.opacity)) ass:pos(0, 0) ass:draw_start() @@ -2376,7 +2438,7 @@ elements:add('pause_indicator', Element.new({ if this.paused then ass:new_event() - ass:append('{\\blur0\\bord1\\1c&H'..options.color_foreground..'\\3c&H'..options.color_background..'}') + ass:append('{\\blur0\\bord1\\1c&H' .. options.color_foreground .. '\\3c&H' .. options.color_background .. '}') ass:append(ass_opacity(this.base_icon_opacity, this.opacity)) ass:pos(display.width / 2, display.height / 2) ass:draw_start() @@ -2384,7 +2446,7 @@ elements:add('pause_indicator', Element.new({ ass:draw_stop() ass:new_event() - ass:append('{\\blur0\\bord1\\1c&H'..options.color_foreground..'\\3c&H'..options.color_background..'}') + ass:append('{\\blur0\\bord1\\1c&H' .. options.color_foreground .. '\\3c&H' .. options.color_background .. '}') ass:append(ass_opacity(this.base_icon_opacity, this.opacity)) ass:pos(display.width / 2, display.height / 2) ass:draw_start() @@ -2392,7 +2454,7 @@ elements:add('pause_indicator', Element.new({ ass:draw_stop() else ass:new_event() - ass:append('{\\blur0\\bord1\\1c&H'..options.color_foreground..'\\3c&H'..options.color_background..'}') + ass:append('{\\blur0\\bord1\\1c&H' .. options.color_foreground .. '\\3c&H' .. options.color_background .. '}') ass:append(ass_opacity(this.base_icon_opacity, this.opacity)) ass:pos(display.width / 2, display.height / 2) ass:draw_start() @@ -2651,7 +2713,8 @@ if itable_find({'center', 'bottom-bar'}, options.menu_button) then if options.menu_button == 'bottom-bar' then this.ax = 15 this.bx = this.ax + this.width - this.by = display.height - 10 - elements.window_border.size - elements.timeline.size_max - elements.timeline.top_border + this.by = display.height - 10 - elements.window_border.size - elements.timeline.size_max - + elements.timeline.top_border this.ay = this.by - this.height else this.ax = round((display.width - this.width) / 2) @@ -2679,7 +2742,7 @@ if options.speed then if up then return speed * options.speed_step else - return speed * 1/options.speed_step + return speed * 1 / options.speed_step end else if up then @@ -2689,6 +2752,7 @@ if options.speed then end end end + elements:add('speed', Element.new({ dragging = nil, width = 0, @@ -2795,7 +2859,7 @@ elements:add('curtain', Element.new({ if this.opacity > 0 and options.curtain_opacity > 0 then local ass = assdraw.ass_new() ass:new_event() - ass:append('{\\blur0\\bord0\\1c&H'..options.color_background..'}') + ass:append('{\\blur0\\bord0\\1c&H' .. options.color_background .. '}') ass:append(ass_opacity(options.curtain_opacity, this.opacity)) ass:pos(0, 0) ass:draw_start() @@ -2810,7 +2874,10 @@ elements:add('curtain', Element.new({ -- Parse `chapter_ranges` option into workable data structure for _, definition in ipairs(split(options.chapter_ranges, ' *,+ *')) do - local start_patterns, color, opacity, end_patterns = string.match(definition, '([^<]+)<(%x%x%x%x%x%x):(%d?%.?%d*)>([^>]+)') + local start_patterns, color, opacity, end_patterns = string.match( + definition, + '([^<]+)<(%x%x%x%x%x%x):(%d?%.?%d*)>([^>]+)' + ) -- Valid definition if start_patterns then @@ -2834,20 +2901,20 @@ for _, definition in ipairs(split(options.chapter_ranges, ' *,+ *')) do chapter_range.end_patterns = itable_remove(chapter_range.end_patterns, '{eof}') end - chapter_range['serialize'] = function (chapters) + chapter_range['serialize'] = function(chapters) chapter_range.ranges = {} local current_range = nil -- bof and eof should be used only once per timeline -- eof is only used when last range is missing end local bof_used = false - function start_range(chapter) + local function start_range(chapter) -- If there is already a range started, should we append or overwrite? -- I chose overwrite here. current_range = {['start'] = chapter} end - function end_range(chapter) + local function end_range(chapter) current_range['end'] = chapter chapter_range.ranges[#chapter_range.ranges + 1] = current_range -- Mark both chapter objects @@ -2964,7 +3031,7 @@ state.context_menu_items = (function() -- If command is already in menu, just append the key to it if target_menu.items_by_command[command] then local hint = target_menu.items_by_command[command].hint - target_menu.items_by_command[command].hint = hint and hint..', '..key or key + target_menu.items_by_command[command].hint = hint and hint .. ', ' .. key or key else local item = { title = title_part, @@ -2987,7 +3054,7 @@ end)() function create_state_setter(name) return function(_, value) state[name] = value - elements:trigger('prop_'..name, value) + elements:trigger('prop_' .. name, value) request_render() end end @@ -3001,7 +3068,7 @@ function update_cursor_position() cursor.y = infinity end - local dpi_scale = mp.get_property_native("display-hidpi-scale", 1.0) + local dpi_scale = mp.get_property_native('display-hidpi-scale', 1.0) dpi_scale = dpi_scale * options.ui_scale cursor.x = cursor.x / dpi_scale @@ -3054,19 +3121,19 @@ function handle_mouse_move() end function navigate_directory(direction) - local path = mp.get_property_native("path") + local path = mp.get_property_native('path') if not path or is_protocol(path) then return end local next_file = get_adjacent_file(path, direction, options.media_types) if next_file then - mp.commandv("loadfile", utils.join_path(serialize_path(path).dirname, next_file)) + mp.commandv('loadfile', utils.join_path(serialize_path(path).dirname, next_file)) end end function load_file_in_current_directory(index) - local path = mp.get_property_native("path") + local path = mp.get_property_native('path') if not path or is_protocol(path) then return end @@ -3077,13 +3144,13 @@ function load_file_in_current_directory(index) if index < 0 then index = #files + index + 1 end if files[index] then - mp.commandv("loadfile", utils.join_path(dirname, files[index])) + mp.commandv('loadfile', utils.join_path(dirname, files[index])) end end function update_render_delay(name, fps) if fps then - state.render_delay = 1/fps + state.render_delay = 1 / fps end end @@ -3159,23 +3226,23 @@ function create_select_tracklist_type_menu_opener(menu_title, track_type, track_ local hint_vals = { track.lang and track.lang:upper() or nil, track['demux-h'] and (track['demux-w'] and track['demux-w'] .. 'x' .. track['demux-h'] - or track['demux-h'] .. 'p'), + or track['demux-h'] .. 'p'), track['demux-fps'] and string.format('%.5gfps', track['demux-fps']) or nil, track.codec, track['audio-channels'] and track['audio-channels'] .. ' channels' or nil, - track['demux-samplerate'] and string.format('%.3gkHz', track['demux-samplerate']/1000) or nil, + track['demux-samplerate'] and string.format('%.3gkHz', track['demux-samplerate'] / 1000) or nil, track.forced and 'forced' or nil, track.default and 'default' or nil, } local hint_vals_filtered = {} for i = 1, #hint_vals do if hint_vals[i] then - hint_vals_filtered[#hint_vals_filtered+1] = hint_vals[i] + hint_vals_filtered[#hint_vals_filtered + 1] = hint_vals[i] end end items[#items + 1] = { - title = (track.title and track.title or 'Track '..track.id), + title = (track.title and track.title or 'Track ' .. track.id), hint = table.concat(hint_vals_filtered, ', '), value = track.id } @@ -3223,7 +3290,7 @@ function open_file_navigation_menu(directory_path, handle_select, menu_options) menu_options = menu_options or {} if not directory then - msg.error('Couldn\'t serialize path "'..directory_path..'.') + msg.error('Couldn\'t serialize path "' .. directory_path .. '.') return end @@ -3232,7 +3299,7 @@ function open_file_navigation_menu(directory_path, handle_select, menu_options) local is_root = not directory.dirname if not files or not directories then - msg.error('Retrieving files from '..directory..' failed: '..(dirs_error or files_error or '')) + msg.error('Retrieving files from ' .. directory .. ' failed: ' .. (dirs_error or files_error or '')) return end @@ -3292,7 +3359,7 @@ function open_file_navigation_menu(directory_path, handle_select, menu_options) local inherit_title = false if menu_options.title == nil then - menu_options.title = directory.basename..'/' + menu_options.title = directory.basename .. '/' else inherit_title = true end @@ -3335,7 +3402,7 @@ function open_drives_menu(handle_select, menu_options) if process.status == 0 then for _, value in ipairs(split(process.stdout, '\n')) do - local drive = string.match(value, "Name=([A-Z]:)") + local drive = string.match(value, 'Name=([A-Z]:)') if drive then local drive_path = normalize_path(drive) items[#items + 1] = {title = drive, hint = 'Drive', value = drive_path} @@ -3358,7 +3425,8 @@ end -- VALUE SERIALIZATION/NORMALIZATION options.proximity_out = math.max(options.proximity_out, options.proximity_in + 1) -options.timeline_chapters = itable_find({'dots', 'lines', 'lines-top', 'lines-bottom'}, options.timeline_chapters) and options.timeline_chapters or 'never' +options.timeline_chapters = itable_find({'dots', 'lines', 'lines-top', 'lines-bottom'}, options.timeline_chapters) and + options.timeline_chapters or 'never' options.media_types = split(options.media_types, ' *, *') options.subtitle_types = split(options.subtitle_types, ' *, *') options.stream_quality_options = split(options.stream_quality_options, ' *, *') @@ -3368,7 +3436,7 @@ options.timeline_cached_ranges = (function() return parts[1] and {color = parts[1], opacity = tonumber(parts[2])} or nil end)() for _, name in ipairs({'timeline', 'volume', 'top_bar', 'speed'}) do - local option_name = name..'_persistency' + local option_name = name .. '_persistency' local flags = {} for _, state in ipairs(split(options[option_name], ' *, *')) do flags[state] = true @@ -3471,17 +3539,17 @@ if options.pause_on_click_shorter_than > 0 then end); click_timer:kill() base_keybinds[#base_keybinds + 1] = {'mbtn_left', function() - if mp.get_time() - last_down_event < duration_seconds then - click_timer:resume() - end - end, function() - if click_timer:is_enabled() then - click_timer:kill() - last_down_event = 0 - else - last_down_event = mp.get_time() - end + if mp.get_time() - last_down_event < duration_seconds then + click_timer:resume() end + end, function() + if click_timer:is_enabled() then + click_timer:kill() + last_down_event = 0 + else + last_down_event = mp.get_time() + end + end } end mp.set_key_bindings(base_keybinds, 'mouse_movement', 'force') @@ -3490,13 +3558,13 @@ mp.enable_key_bindings('mouse_movement', 'allow-vo-dragging+allow-hide-cursor') -- Context based key bind groups forced_key_bindings = (function() - function create_mouse_event_dispatcher(name) + local function create_mouse_event_dispatcher(name) return function(...) for _, element in pairs(elements) do if element.proximity_raw == 0 then element:trigger(name, ...) end - element:trigger('global_'..name, ...) + element:trigger('global_' .. name, ...) end end end @@ -3566,12 +3634,10 @@ end) mp.add_key_binding(nil, 'decide-pause-indicator', function() elements.pause_indicator:decide() end) -function menu_key_binding() - toggle_menu_with_items(state.context_menu_items) -end +function menu_key_binding() toggle_menu_with_items(state.context_menu_items) end mp.add_key_binding(nil, 'menu', menu_key_binding) mp.register_script_message('show-submenu', function(name) - local path = split(name, " *>+ *") + local path = split(name, ' *>+ *') local items = state.context_menu_items local last_menu_title = nil @@ -3587,7 +3653,7 @@ mp.register_script_message('show-submenu', function(name) local _, submenu_item = itable_find(items, function(_, item) return item.title == menu_title end) if not submenu_item then - msg.error('Can\'t find submenu: '..menu_title) + msg.error('Can\'t find submenu: ' .. menu_title) return end @@ -3609,7 +3675,7 @@ mp.add_key_binding(nil, 'load-subtitles', function() end end if not path then - path = os.getenv("HOME") --[[@as string]] + path = os.getenv('HOME') --[[@as string]] end open_file_navigation_menu( path, @@ -3710,9 +3776,9 @@ mp.add_key_binding(nil, 'stream-quality', function() local formats = {} for index, height in ipairs(options.stream_quality_options) do - local format = 'bestvideo[height<=?'..height..']+bestaudio/best[height<=?'..height..']' + local format = 'bestvideo[height<=?' .. height .. ']+bestaudio/best[height<=?' .. height .. ']' formats[#formats + 1] = { - title = height..'p', + title = height .. 'p', value = format } if format == ytdl_format then active_index = index end @@ -3771,12 +3837,12 @@ mp.add_key_binding(nil, 'open-file', function() end if not directory then - msg.error('Couldn\'t serialize path "'..path..'".') + msg.error('Couldn\'t serialize path "' .. path .. '".') return end -- Update selected file in directory navigation menu - function handle_file_loaded() + local function handle_file_loaded() if menu:is_open('open-file') then local path = normalize_path(mp.get_property_native('path')) elements.menu:activate_value(path) @@ -3789,7 +3855,7 @@ mp.add_key_binding(nil, 'open-file', function() function(path) mp.commandv('loadfile', path) end, { type = 'open-file', - allowed_types = options.media_types --[[@as table]], + allowed_types = options.media_types --[[@as table]] , active_path = active_file, on_open = function() mp.register_event('file-loaded', handle_file_loaded) end, on_close = function() mp.unregister_event(handle_file_loaded) end, @@ -3884,6 +3950,6 @@ mp.add_key_binding(nil, 'open-config-directory', function() utils.subprocess_detached({args = args, cancellable = false}) else - msg.error('Couldn\'t serialize config path "'..config_path..'".') + msg.error('Couldn\'t serialize config path "' .. config_path .. '".') end end)