summaryrefslogtreecommitdiff
path: root/mac/.config/mpv/script-modules
diff options
context:
space:
mode:
Diffstat (limited to 'mac/.config/mpv/script-modules')
-rw-r--r--mac/.config/mpv/script-modules/extended-menu.lua1214
-rw-r--r--mac/.config/mpv/script-modules/gallery.lua581
-rw-r--r--mac/.config/mpv/script-modules/input-console.lua935
-rw-r--r--mac/.config/mpv/script-modules/mpvSockets.lua36
-rw-r--r--mac/.config/mpv/script-modules/scroll-list.lua293
-rw-r--r--mac/.config/mpv/script-modules/sha1.lua334
-rw-r--r--mac/.config/mpv/script-modules/user-input-module.lua126
-rw-r--r--mac/.config/mpv/script-modules/utf8/LICENSE21
-rw-r--r--mac/.config/mpv/script-modules/utf8/README.md93
-rw-r--r--mac/.config/mpv/script-modules/utf8/begins/compiletime/parser.lua17
-rw-r--r--mac/.config/mpv/script-modules/utf8/begins/compiletime/vanilla.lua60
-rw-r--r--mac/.config/mpv/script-modules/utf8/charclass/compiletime/builder.lua128
-rw-r--r--mac/.config/mpv/script-modules/utf8/charclass/compiletime/parser.lua21
-rw-r--r--mac/.config/mpv/script-modules/utf8/charclass/compiletime/range.lua44
-rw-r--r--mac/.config/mpv/script-modules/utf8/charclass/compiletime/stub.lua9
-rw-r--r--mac/.config/mpv/script-modules/utf8/charclass/compiletime/vanilla.lua131
-rw-r--r--mac/.config/mpv/script-modules/utf8/charclass/runtime/base.lua184
-rw-r--r--mac/.config/mpv/script-modules/utf8/charclass/runtime/dummy.lua41
-rw-r--r--mac/.config/mpv/script-modules/utf8/charclass/runtime/init.lua22
-rw-r--r--mac/.config/mpv/script-modules/utf8/charclass/runtime/native.lua47
-rw-r--r--mac/.config/mpv/script-modules/utf8/context/compiletime.lua18
-rw-r--r--mac/.config/mpv/script-modules/utf8/context/runtime.lua112
-rw-r--r--mac/.config/mpv/script-modules/utf8/ends/compiletime/parser.lua17
-rw-r--r--mac/.config/mpv/script-modules/utf8/ends/compiletime/vanilla.lua46
-rw-r--r--mac/.config/mpv/script-modules/utf8/functions/lua53.lua152
-rw-r--r--mac/.config/mpv/script-modules/utf8/init.lua71
-rw-r--r--mac/.config/mpv/script-modules/utf8/modifier/compiletime/frontier.lua50
-rw-r--r--mac/.config/mpv/script-modules/utf8/modifier/compiletime/parser.lua20
-rw-r--r--mac/.config/mpv/script-modules/utf8/modifier/compiletime/simple.lua23
-rw-r--r--mac/.config/mpv/script-modules/utf8/modifier/compiletime/stub.lua28
-rw-r--r--mac/.config/mpv/script-modules/utf8/modifier/compiletime/vanilla.lua270
-rw-r--r--mac/.config/mpv/script-modules/utf8/primitives/dummy.lua555
-rw-r--r--mac/.config/mpv/script-modules/utf8/primitives/init.lua23
-rw-r--r--mac/.config/mpv/script-modules/utf8/primitives/native.lua57
-rw-r--r--mac/.config/mpv/script-modules/utf8/primitives/tarantool.lua13
-rw-r--r--mac/.config/mpv/script-modules/utf8/regex_parser.lua80
-rwxr-xr-xmac/.config/mpv/script-modules/utf8/test.sh23
-rw-r--r--mac/.config/mpv/script-modules/utf8/test/charclass_compiletime.lua165
-rw-r--r--mac/.config/mpv/script-modules/utf8/test/charclass_runtime.lua116
-rw-r--r--mac/.config/mpv/script-modules/utf8/test/context_runtime.lua82
-rw-r--r--mac/.config/mpv/script-modules/utf8/test/strict.lua42
-rw-r--r--mac/.config/mpv/script-modules/utf8/test/test.lua205
-rw-r--r--mac/.config/mpv/script-modules/utf8/test/test_compat.lua109
-rw-r--r--mac/.config/mpv/script-modules/utf8/test/test_pm.lua392
-rw-r--r--mac/.config/mpv/script-modules/utf8/test/test_utf8data.lua15
-rw-r--r--mac/.config/mpv/script-modules/utf8/test/util.lua75
-rw-r--r--mac/.config/mpv/script-modules/utf8/util.lua64
-rw-r--r--mac/.config/mpv/script-modules/utf8_data.lua1865
48 files changed, 9025 insertions, 0 deletions
diff --git a/mac/.config/mpv/script-modules/extended-menu.lua b/mac/.config/mpv/script-modules/extended-menu.lua
new file mode 100644
index 0000000..b663e93
--- /dev/null
+++ b/mac/.config/mpv/script-modules/extended-menu.lua
@@ -0,0 +1,1214 @@
+local mp = require("mp")
+local utils = require("mp.utils")
+local assdraw = require("mp.assdraw")
+
+-- create namespace with default values
+local em = {
+
+ -- customisable values ------------------------------------------------------
+
+ loop_when_navigating = false, -- Loop when navigating through list
+ lines_to_show = 17, -- NOT including search line
+ pause_on_open = true,
+ resume_on_exit = "only-if-was-paused", -- another possible value is true
+
+ -- styles (earlyer it was a table, but required many more steps to pass def-s
+ -- here from .conf file)
+ font_size = 21,
+ --font size scales by window
+ scale_by_window = false,
+ -- cursor 'width', useful to change if you have hidpi monitor
+ cursor_x_border = 0.3,
+ line_bottom_margin = 1, -- basically space between lines
+ text_color = {
+ default = "ffffff",
+ accent = "d8a07b",
+ current = "aaaaaa",
+ comment = "636363",
+ },
+ menu_x_padding = 5, -- this padding for now applies only to 'left', not x
+ menu_y_padding = 2, -- but this one applies to both - top & bottom
+
+ -- values that should be passed from main script ----------------------------
+
+ search_heading = "Default search heading",
+ -- 'full' is required from main script, 'current_i' is optional
+ -- others are 'private'
+ list = {
+ full = {},
+ filtered = {},
+ current_i = nil,
+ pointer_i = 1,
+ show_from_to = {},
+ },
+ -- field to compare with when searching for 'current value' by 'current_i'
+ index_field = "index",
+ -- fields to use when searching for string match / any other custom searching
+ -- if value has 0 length, then search list item itself
+ filter_by_fields = {},
+
+ -- 'private' values that are not supposed to be changed from the outside ----
+
+ is_active = false,
+ -- https://mpv.io/manual/master/#lua-scripting-mp-create-osd-overlay(format)
+ ass = mp.create_osd_overlay("ass-events"),
+ was_paused = false, -- flag that indicates that vid was paused by this script
+
+ line = "",
+ -- if there was no cursor it wouldn't have been needed, but for now we need
+ -- variable below only to compare it with 'line' and see if we need to filter
+ prev_line = "",
+ cursor = 1,
+ history = {},
+ history_pos = 1,
+ key_bindings = {},
+ insert_mode = false,
+
+ -- used only in 'update' func to get error text msgs
+ error_codes = {
+ no_match = "Match required",
+ no_submit_provided = "No submit function provided",
+ },
+}
+
+-- PRIVATE METHODS ------------------------------------------------------------
+
+-- declare constructor function
+function em:new(o)
+ o = o or {}
+ setmetatable(o, self)
+ self.__index = self
+
+ -- some options might be customised by user in .conf file and read as strings
+ -- in that case parse those
+ if type(o.filter_by_fields) == "string" then
+ o.filter_by_fields = utils.parse_json(o.filter_by_fields)
+ end
+
+ if type(o.text_color) == "string" then
+ o.text_color = utils.parse_json(o.text_color)
+ end
+
+ return o
+end
+
+-- this func is just a getter of a current list depending on search line
+function em:current()
+ return self.line == "" and self.list.full or self.list.filtered
+end
+
+-- REVIEW: how to get rid of this wrapper and handle filter func sideeffects
+-- in a more elegant way?
+function em:filter_wrapper()
+ -- handles sideeffect that are needed to be run on filtering list
+ -- cuz the filter func may be redefined in main script and therefore needs
+ -- to be straight forward - only doing filtering and returning the table
+
+ -- passing current query just in case, so ppl can use it in their custom funcs
+ self.list.filtered = self:filter(self.line)
+
+ self.prev_line = self.line
+ self.list.pointer_i = 1
+ self:set_from_to(true)
+end
+
+function em:set_from_to(reset_flag)
+ -- additional variables just for shorter var name
+ local i = self.list.pointer_i
+ local to_show = self.lines_to_show
+ local total = #self:current()
+
+ if reset_flag or to_show >= total then
+ self.list.show_from_to = { 1, math.min(to_show, total) }
+ return
+ end
+
+ -- If menu is opened with something already selected we want this 'selected'
+ -- to be displayed close to the middle of the menu. That's why 'show_from_to'
+ -- is not initially set, so we can know - if show_from_to length is 0 - it is
+ -- first call of this func in cur. init
+ if #self.list.show_from_to == 0 then
+ -- set show_from_to so chosen item will be displayed close to middle
+ local half_list = math.ceil(to_show / 2)
+ if i < half_list then
+ self.list.show_from_to = { 1, to_show }
+ elseif total - i < half_list then
+ self.list.show_from_to = { total - to_show + 1, total }
+ else
+ self.list.show_from_to = { i - half_list + 1, i - half_list + to_show }
+ end
+ else
+ table.unpack = table.unpack or unpack -- 5.1 compatibility
+ local first, last = table.unpack(self.list.show_from_to)
+
+ -- handle cursor moving towards start / end bondary
+ if first ~= 1 and i - first < 2 then
+ self.list.show_from_to = { first - 1, last - 1 }
+ end
+ if last ~= total and last - i < 2 then
+ self.list.show_from_to = { first + 1, last + 1 }
+ end
+
+ -- handle index jumps from beginning to end and backwards
+ if i > last then
+ self.list.show_from_to = { i - to_show + 1, i }
+ end
+ if i < first then
+ self.list.show_from_to = { 1, to_show }
+ end
+ end
+end
+
+function em:change_selected_index(num)
+ self.list.pointer_i = self.list.pointer_i + num
+ if self.loop_when_navigating then
+ if self.list.pointer_i < 1 then
+ self.list.pointer_i = #self:current()
+ elseif self.list.pointer_i > #self:current() then
+ self.list.pointer_i = 1
+ end
+ else
+ if self.list.pointer_i < 1 then
+ self.list.pointer_i = 1
+ elseif self.list.pointer_i > #self:current() then
+ self.list.pointer_i = #self:current()
+ end
+ end
+ self:set_from_to()
+ self:update()
+end
+
+-- Render the REPL and console as an ASS OSD
+function em:update(err_code)
+ -- ASS tags documentation here - https://aegi.vmoe.info/docs/3.0/ASS_Tags/
+
+ -- do not bother if function was called to close the menu..
+ if not self.is_active then
+ em.ass:remove()
+ return
+ end
+
+ local line_height = self.font_size + self.line_bottom_margin
+ local _, h, aspect = mp.get_osd_size()
+ local wh = self.scale_by_window and 720 or h
+ local ww = wh * aspect
+
+ -- '+ 1' below is a search string
+ local menu_y_pos = wh - (line_height * (self.lines_to_show + 1) + self.menu_y_padding * 2)
+
+ -- didn't find better place to handle filtered list update
+ if self.line ~= self.prev_line then
+ self:filter_wrapper()
+ end
+
+ local function get_background()
+ local a = self:ass_new_wrapper()
+ a:append("{\\1c&H1c1c1c\\1a&H19}") -- background color & opacity
+ a:pos(0, 0)
+ a:draw_start()
+ a:rect_cw(0, menu_y_pos, ww, wh)
+ a:draw_stop()
+ return a.text
+ end
+
+ local function get_search_header()
+ local a = self:ass_new_wrapper()
+
+ a:pos(self.menu_x_padding, menu_y_pos + self.menu_y_padding)
+
+ local search_prefix = table.concat({
+ self:get_font_color("accent"),
+ (#self:current() ~= 0 and self.list.pointer_i or "!"),
+ "/",
+ #self:current(),
+ "\\h\\h",
+ self.search_heading,
+ ":\\h",
+ })
+
+ a:append(search_prefix)
+ -- reset font color after search prefix
+ a:append(self:get_font_color("default"))
+
+ -- Create the cursor glyph as an ASS drawing. ASS will draw the cursor
+ -- inline with the surrounding text, but it sets the advance to the width
+ -- of the drawing. So the cursor doesn't affect layout too much, make it as
+ -- thin as possible and make it appear to be 1px wide by giving it 0.5px
+ -- horizontal borders.
+ local cheight = self.font_size * 8
+ -- TODO: maybe do it using draw_rect from ass?
+ local cglyph = "{\\r" -- styles reset
+ .. "\\1c&Hffffff&\\3c&Hffffff" -- font color and border color
+ .. "\\xbord"
+ .. self.cursor_x_border
+ .. "\\p4\\pbo24}" -- xborder, scale x8 and baseline offset
+ .. "m 0 0 l 0 "
+ .. cheight -- drawing just a line
+ .. "{\\p0\\r}" -- finish drawing and reset styles
+ local before_cur = self:ass_escape(self.line:sub(1, self.cursor - 1))
+ local after_cur = self:ass_escape(self.line:sub(self.cursor))
+
+ a:append(table.concat({
+ before_cur,
+ cglyph,
+ self:reset_styles(),
+ self:get_font_color("default"),
+ after_cur,
+ (err_code and "\\h" .. self.error_codes[err_code] or ""),
+ }))
+
+ return a.text
+
+ -- NOTE: perhaps this commented code will some day help me in coding cursor
+ -- like in M-x emacs menu:
+ -- Redraw the cursor with the REPL text invisible. This will make the
+ -- cursor appear in front of the text.
+ -- ass:new_event()
+ -- ass:an(1)
+ -- ass:append(style .. '{\\alpha&HFF&}> ' .. before_cur)
+ -- ass:append(cglyph)
+ -- ass:append(style .. '{\\alpha&HFF&}' .. after_cur)
+ end
+
+ local function get_list()
+ local a = assdraw.ass_new()
+
+ local function apply_highlighting(y)
+ a:new_event()
+ a:append(self:reset_styles())
+ a:append("{\\1c&Hffffff\\1a&HE6}") -- background color & opacity
+ a:pos(0, 0)
+ a:draw_start()
+ a:rect_cw(0, y, ww, y + self.font_size)
+ a:draw_stop()
+ end
+
+ -- REVIEW: maybe make another function 'get_line_str' and move there
+ -- everything from this for loop?
+ -- REVIEW: how to use something like table.unpack below?
+ for i = self.list.show_from_to[1], self.list.show_from_to[2] do
+ local value = assert(self:current()[i], "no value with index " .. i)
+ local y_offset = menu_y_pos + self.menu_y_padding + (line_height * (i - self.list.show_from_to[1] + 1))
+
+ if i == self.list.pointer_i then
+ apply_highlighting(y_offset)
+ end
+
+ a:new_event()
+ a:append(self:reset_styles())
+ a:pos(self.menu_x_padding, y_offset)
+ a:append(self:get_line(i, value))
+ end
+
+ return a.text
+ end
+
+ em.ass.res_x = ww
+ em.ass.res_y = wh
+ em.ass.data = table.concat({
+ get_background(),
+ get_search_header(),
+ get_list(),
+ }, "\n")
+
+ em.ass:update()
+end
+
+-- params:
+-- - data : {list: {}, [current_i] : num}
+function em:init(data)
+ self.list.full = data.list or {}
+ self.list.current_i = data.current_i or nil
+ self.list.pointer_i = data.current_i or 1
+ self:set_active(true)
+end
+
+function em:exit()
+ self:undefine_key_bindings()
+ collectgarbage()
+end
+
+-- TODO: write some idle func like this
+-- function idle()
+-- if pending_selection then
+-- gallery:set_selection(pending_selection)
+-- pending_selection = nil
+-- end
+-- if ass_changed or geometry_changed then
+-- local ww, wh = mp.get_osd_size()
+-- if geometry_changed then
+-- geometry_changed = false
+-- compute_geometry(ww, wh)
+-- end
+-- if ass_changed then
+-- ass_changed = false
+-- mp.set_osd_ass(ww, wh, ass)
+-- end
+-- end
+-- end
+-- ...
+-- and handle it as follows
+-- init():
+-- mp.register_idle(idle)
+-- idle()
+-- exit():
+-- mp.unregister_idle(idle)
+-- idle()
+-- And in these observers he is setting a flag, that's being checked in func above
+-- mp.observe_property("osd-width", "native", mark_geometry_stale)
+-- mp.observe_property("osd-height", "native", mark_geometry_stale)
+
+-- PRIVATE METHODS END --------------------------------------------------------
+
+-- PUBLIC METHODS -------------------------------------------------------------
+
+function em:filter()
+ -- default filter func, might be redefined in main script
+ local result = {}
+
+ local function get_full_search_str(v)
+ local str = ""
+ for _, key in ipairs(self.filter_by_fields) do
+ str = str .. (v[key] or "")
+ end
+ return str
+ end
+
+ for _, v in ipairs(self.list.full) do
+ -- if filter_by_fields has 0 length, then search list item itself
+ if #self.filter_by_fields == 0 then
+ if self:search_method(v) then
+ table.insert(result, v)
+ end
+ else
+ -- NOTE: we might use search_method on fiels separately like this:
+ -- for _,key in ipairs(self.filter_by_fields) do
+ -- if self:search_method(v[key]) then table.insert(result, v) end
+ -- end
+ -- But since im planning to implement fuzzy search in future i need full
+ -- search string here
+ if self:search_method(get_full_search_str(v)) then
+ table.insert(result, v)
+ end
+ end
+ end
+ return result
+end
+
+-- TODO: implement fuzzy search and maybe match highlights
+function em:search_method(str)
+ -- also might be redefined by main script
+
+ -- convert to string just to make sure..
+ return tostring(str):lower():find(self.line:lower(), 1, true)
+end
+
+-- this module requires submit function to be defined in main script
+function em:submit()
+ self:update("no_submit_provided")
+end
+
+function em:update_list(list)
+ -- for now this func doesn't handle cases when we have 'current_i' to update
+ -- it
+ self.list.full = list
+ if self.line ~= self.prev_line then
+ self:filter_wrapper()
+ end
+end
+
+-- PUBLIC METHODS END ---------------------------------------------------------
+
+-- HELPER METHODS -------------------------------------------------------------
+
+function em:get_line(_, v) -- [i]ndex, [v]alue
+ -- this func might be redefined in main script to get a custom-formatted line
+ -- default implementation of this func supposes that value.content field is a
+ -- String
+ local a = assdraw.ass_new()
+ local style = (self.list.current_i == v[self.index_field]) and "current" or "default"
+
+ a:append(self:reset_styles())
+ a:append(self:get_font_color(style))
+ -- content as default field, which is holding string
+ -- no point in moving it to main object since content itself is being
+ -- composed in THIS function, that might (and most likely, should) be
+ -- redefined in main script
+ a:append(v.content or "Something is off in `get_line` func")
+ return a.text
+end
+
+-- REVIEW: for now i don't see normal way of mergin this func with below one
+-- but it's being used only once
+function em:reset_styles()
+ local a = assdraw.ass_new()
+ -- alignment top left, no word wrapping, border 0, shadow 0
+ a:append("{\\an7\\q2\\bord0\\shad0}")
+ a:append("{\\fs" .. self.font_size .. "}")
+ return a.text
+end
+
+-- function to get rid of some copypaste
+function em:ass_new_wrapper()
+ local a = assdraw.ass_new()
+ a:new_event()
+ a:append(self:reset_styles())
+ return a
+end
+
+function em:get_font_color(style)
+ return "{\\1c&H" .. self.text_color[style] .. "}"
+end
+
+-- HELPER METHODS END ---------------------------------------------------------
+
+--[[
+ The below code is a modified implementation of text input from mpv's console.lua:
+ https://github.com/mpv-player/mpv/blob/87c9eefb2928252497f6141e847b74ad1158bc61/player/lua/console.lua
+
+ I was too lazy to list all modifications i've done to the script, but if u
+ rly need to see those - do diff with the original code
+]]
+--
+
+-------------------------------------------------------------------------------
+-- START ORIGINAL MPV CODE --
+-------------------------------------------------------------------------------
+
+-- Copyright (C) 2019 the mpv developers
+--
+-- Permission to use, copy, modify, and/or distribute this software for any
+-- purpose with or without fee is hereby granted, provided that the above
+-- copyright notice and this permission notice appear in all copies.
+--
+-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+-- SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+-- OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+-- CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+function em:detect_platform()
+ local o = {}
+ -- Kind of a dumb way of detecting the platform but whatever
+ if mp.get_property_native("options/vo-mmcss-profile", o) ~= o then
+ return "windows"
+ elseif mp.get_property_native("options/macos-force-dedicated-gpu", o) ~= o then
+ return "macos"
+ elseif os.getenv("WAYLAND_DISPLAY") then
+ return "wayland"
+ end
+ return "x11"
+end
+
+-- Escape a string for verbatim display on the OSD
+function em: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
+end
+
+-- Set the REPL visibility ("enable", Esc)
+function em:set_active(active)
+ if active == self.is_active then
+ return
+ end
+ if active then
+ self.is_active = true
+ self.insert_mode = false
+ mp.enable_messages("terminal-default")
+ self:define_key_bindings()
+
+ -- set flag 'was_paused' only if vid wasn't paused before EM init
+ if self.pause_on_open and not mp.get_property_bool("pause", false) then
+ mp.set_property_bool("pause", true)
+ self.was_paused = true
+ end
+
+ self:set_from_to()
+ self:update()
+ else
+ -- no need to call 'update' in this block cuz 'clear' method is calling it
+ self.is_active = false
+ self:undefine_key_bindings()
+
+ if self.resume_on_exit == true or (self.resume_on_exit == "only-if-was-paused" and self.was_paused) then
+ mp.set_property_bool("pause", false)
+ end
+
+ self:clear()
+ collectgarbage()
+ end
+end
+
+-- Naive helper function to find the next UTF-8 character in 'str' after 'pos'
+-- by skipping continuation bytes. Assumes 'str' contains valid UTF-8.
+function em:next_utf8(str, pos)
+ if pos > str:len() then
+ return pos
+ end
+ repeat
+ pos = pos + 1
+ until pos > str:len() or str:byte(pos) < 0x80 or str:byte(pos) > 0xbf
+ return pos
+end
+
+-- As above, but finds the previous UTF-8 charcter in 'str' before 'pos'
+function em:prev_utf8(str, pos)
+ if pos <= 1 then
+ return pos
+ end
+ repeat
+ pos = pos - 1
+ until pos <= 1 or str:byte(pos) < 0x80 or str:byte(pos) > 0xbf
+ return pos
+end
+
+-- Insert a character at the current cursor position (any_unicode)
+function em:handle_char_input(c)
+ if self.insert_mode then
+ self.line = self.line:sub(1, self.cursor - 1) .. c .. self.line:sub(self:next_utf8(self.line, self.cursor))
+ else
+ self.line = self.line:sub(1, self.cursor - 1) .. c .. self.line:sub(self.cursor)
+ end
+ self.cursor = self.cursor + #c
+ self:update()
+end
+
+-- Remove the character behind the cursor (Backspace)
+function em:handle_backspace()
+ if self.cursor <= 1 then
+ return
+ end
+ local prev = self:prev_utf8(self.line, self.cursor)
+ self.line = self.line:sub(1, prev - 1) .. self.line:sub(self.cursor)
+ self.cursor = prev
+ self:update()
+end
+
+-- Remove the character in front of the cursor (Del)
+function em:handle_del()
+ if self.cursor > self.line:len() then
+ return
+ end
+ self.line = self.line:sub(1, self.cursor - 1) .. self.line:sub(self:next_utf8(self.line, self.cursor))
+ self:update()
+end
+
+-- Toggle insert mode (Ins)
+function em:handle_ins()
+ self.insert_mode = not self.insert_mode
+end
+
+-- Move the cursor to the next character (Right)
+function em:next_char()
+ self.cursor = self:next_utf8(self.line, self.cursor)
+ self:update()
+end
+
+-- Move the cursor to the previous character (Left)
+function em:prev_char()
+ self.cursor = self:prev_utf8(self.line, self.cursor)
+ self:update()
+end
+
+-- Clear the current line (Ctrl+C)
+function em:clear()
+ self.line = ""
+ self.prev_line = ""
+
+ self.list.current_i = nil
+ self.list.pointer_i = 1
+ self.list.filtered = {}
+ self.list.show_from_to = {}
+
+ self.was_paused = false
+
+ self.cursor = 1
+ self.insert_mode = false
+ self.history_pos = #self.history + 1
+
+ self:update()
+end
+
+-- Run the current command and clear the line (Enter)
+function em:handle_enter()
+ if #self:current() == 0 then
+ self:update("no_match")
+ return
+ end
+
+ if self.history[#self.history] ~= self.line then
+ self.history[#self.history + 1] = self.line
+ end
+
+ self:submit(self:current()[self.list.pointer_i])
+ self:set_active(false)
+end
+
+-- Go to the specified position in the command history
+function em:go_history(new_pos)
+ local old_pos = self.history_pos
+ self.history_pos = new_pos
+
+ -- Restrict the position to a legal value
+ if self.history_pos > #self.history + 1 then
+ self.history_pos = #self.history + 1
+ elseif self.history_pos < 1 then
+ self.history_pos = 1
+ end
+
+ -- Do nothing if the history position didn't actually change
+ if self.history_pos == old_pos then
+ return
+ end
+
+ -- If the user was editing a non-history line, save it as the last history
+ -- entry. This makes it much less frustrating to accidentally hit Up/Down
+ -- while editing a line.
+ if old_pos == #self.history + 1 and self.line ~= "" and self.history[#self.history] ~= self.line then
+ self.history[#self.history + 1] = self.line
+ end
+
+ -- Now show the history line (or a blank line for #history + 1)
+ if self.history_pos <= #self.history then
+ self.line = self.history[self.history_pos]
+ else
+ self.line = ""
+ end
+ self.cursor = self.line:len() + 1
+ self.insert_mode = false
+ self:update()
+end
+
+-- Go to the specified relative position in the command history (Up, Down)
+function em:move_history(amount)
+ self:go_history(self.history_pos + amount)
+end
+
+-- Go to the first command in the command history (PgUp)
+function em:handle_pgup()
+ -- Determine the number of items to move up (half a page)
+ local half_page = math.ceil(self.lines_to_show / 2)
+
+ -- Move the history position up by half a page
+ self:change_selected_index(-half_page)
+end
+
+-- Stop browsing history and start editing a blank line (PgDown)
+function em:handle_pgdown()
+ -- Determine the number of items to move down (half a page)
+ local half_page = math.ceil(self.lines_to_show / 2)
+
+ -- Move the history position down by half a page
+ self:change_selected_index(half_page)
+end
+
+-- Move to the start of the current word, or if already at the start, the start
+-- of the previous word. (Ctrl+Left)
+function em:prev_word()
+ -- This is basically the same as next_word() but backwards, so reverse the
+ -- string in order to do a "backwards" find. This wouldn't be as annoying
+ -- to do if Lua didn't insist on 1-based indexing.
+ self.cursor = self.line:len()
+ - select(2, self.line:reverse():find("%s*[^%s]*", self.line:len() - self.cursor + 2))
+ + 1
+ self:update()
+end
+
+-- Move to the end of the current word, or if already at the end, the end of
+-- the next word. (Ctrl+Right)
+function em:next_word()
+ self.cursor = select(2, self.line:find("%s*[^%s]*", self.cursor)) + 1
+ self:update()
+end
+
+-- Move the cursor to the beginning of the line (HOME)
+function em:go_home()
+ self.cursor = 1
+ self:update()
+end
+
+-- Move the cursor to the end of the line (END)
+function em:go_end()
+ self.cursor = self.line:len() + 1
+ self:update()
+end
+
+-- Delete from the cursor to the beginning of the word (Ctrl+Backspace)
+function em:del_word()
+ local before_cur = self.line:sub(1, self.cursor - 1)
+ local after_cur = self.line:sub(self.cursor)
+
+ before_cur = before_cur:gsub("[^%s]+%s*$", "", 1)
+ self.line = before_cur .. after_cur
+ self.cursor = before_cur:len() + 1
+ self:update()
+end
+
+-- Delete from the cursor to the end of the word (Ctrl+Del)
+function em:del_next_word()
+ if self.cursor > self.line:len() then
+ return
+ end
+
+ local before_cur = self.line:sub(1, self.cursor - 1)
+ local after_cur = self.line:sub(self.cursor)
+
+ after_cur = after_cur:gsub("^%s*[^%s]+", "", 1)
+ self.line = before_cur .. after_cur
+ self:update()
+end
+
+-- Delete from the cursor to the end of the line (Ctrl+K)
+function em:del_to_eol()
+ self.line = self.line:sub(1, self.cursor - 1)
+ self:update()
+end
+
+-- Delete from the cursor back to the start of the line (Ctrl+U)
+function em:del_to_start()
+ self.line = self.line:sub(self.cursor)
+ self.cursor = 1
+ self:update()
+end
+
+-- Returns a string of UTF-8 text from the clipboard (or the primary selection)
+function em:get_clipboard(clip)
+ -- Pick a better default font for Windows and macOS
+ local platform = self:detect_platform()
+
+ if platform == "x11" then
+ local res = utils.subprocess({
+ args = { "xclip", "-selection", clip and "clipboard" or "primary", "-out" },
+ playback_only = false,
+ })
+ if not res.error then
+ return res.stdout
+ end
+ elseif platform == "wayland" then
+ local res = utils.subprocess({
+ args = { "wl-paste", clip and "-n" or "-np" },
+ playback_only = false,
+ })
+ if not res.error then
+ return res.stdout
+ end
+ elseif platform == "windows" then
+ local res = utils.subprocess({
+ args = {
+ "powershell",
+ "-NoProfile",
+ "-Command",
+ [[& {
+ Trap {
+ Write-Error -ErrorRecord $_
+ Exit 1
+ }
+
+ $clip = ""
+ if (Get-Command "Get-Clipboard" -errorAction SilentlyContinue) {
+ $clip = Get-Clipboard -Raw -Format Text -TextFormatType UnicodeText
+ } else {
+ Add-Type -AssemblyName PresentationCore
+ $clip = [Windows.Clipboard]::GetText()
+ }
+
+ $clip = $clip -Replace "`r",""
+ $u8clip = [System.Text.Encoding]::UTF8.GetBytes($clip)
+ [Console]::OpenStandardOutput().Write($u8clip, 0, $u8clip.Length)
+ }]],
+ },
+ playback_only = false,
+ })
+ if not res.error then
+ return res.stdout
+ end
+ elseif platform == "macos" then
+ local res = utils.subprocess({
+ args = { "pbpaste" },
+ playback_only = false,
+ })
+ if not res.error then
+ return res.stdout
+ end
+ end
+ return ""
+end
+
+-- Paste text from the window-system's clipboard. 'clip' determines whether the
+-- clipboard or the primary selection buffer is used (on X11 and Wayland only.)
+function em:paste(clip)
+ local text = self:get_clipboard(clip)
+ local before_cur = self.line:sub(1, self.cursor - 1)
+ local after_cur = self.line:sub(self.cursor)
+ self.line = before_cur .. text .. after_cur
+ self.cursor = self.cursor + text:len()
+ self:update()
+end
+
+-- List of input bindings. This is a weird mashup between common GUI text-input
+-- bindings and readline bindings.
+function em:get_bindings()
+ local bindings = {
+ {
+ "ctrl+[",
+ function()
+ self:set_active(false)
+ end,
+ },
+ {
+ "ctrl+g",
+ function()
+ self:set_active(false)
+ end,
+ },
+ {
+ "esc",
+ function()
+ self:set_active(false)
+ end,
+ },
+ {
+ "enter",
+ function()
+ self:handle_enter()
+ end,
+ },
+ {
+ "kp_enter",
+ function()
+ self:handle_enter()
+ end,
+ },
+ {
+ "ctrl+m",
+ function()
+ self:handle_enter()
+ end,
+ },
+ {
+ "bs",
+ function()
+ self:handle_backspace()
+ end,
+ },
+ {
+ "shift+bs",
+ function()
+ self:handle_backspace()
+ end,
+ },
+ {
+ "ctrl+h",
+ function()
+ self:handle_backspace()
+ end,
+ },
+ {
+ "del",
+ function()
+ self:handle_del()
+ end,
+ },
+ {
+ "shift+del",
+ function()
+ self:handle_del()
+ end,
+ },
+ {
+ "ins",
+ function()
+ self:handle_ins()
+ end,
+ },
+ {
+ "shift+ins",
+ function()
+ self:paste(false)
+ end,
+ },
+ {
+ "mbtn_mid",
+ function()
+ self:paste(false)
+ end,
+ },
+ {
+ "left",
+ function()
+ self:prev_char()
+ end,
+ },
+ {
+ "ctrl+b",
+ function()
+ self:prev_char()
+ end,
+ },
+ {
+ "right",
+ function()
+ self:next_char()
+ end,
+ },
+ {
+ "ctrl+f",
+ function()
+ self:next_char()
+ end,
+ },
+ {
+ "ctrl+k",
+ function()
+ self:change_selected_index(-1)
+ end,
+ },
+ {
+ "ctrl+p",
+ function()
+ self:change_selected_index(-1)
+ end,
+ },
+ {
+ "ctrl+j",
+ function()
+ self:change_selected_index(1)
+ end,
+ },
+ {
+ "ctrl+n",
+ function()
+ self:change_selected_index(1)
+ end,
+ },
+ {
+ "up",
+ function()
+ self:move_history(-1)
+ end,
+ },
+ {
+ "alt+p",
+ function()
+ self:move_history(-1)
+ end,
+ },
+ {
+ "wheel_up",
+ function()
+ self:move_history(-1)
+ end,
+ },
+ {
+ "down",
+ function()
+ self:move_history(1)
+ end,
+ },
+ {
+ "alt+n",
+ function()
+ self:move_history(1)
+ end,
+ },
+ {
+ "wheel_down",
+ function()
+ self:move_history(1)
+ end,
+ },
+ { "wheel_left", function() end },
+ { "wheel_right", function() end },
+ {
+ "ctrl+left",
+ function()
+ self:prev_word()
+ end,
+ },
+ {
+ "alt+b",
+ function()
+ self:prev_word()
+ end,
+ },
+ {
+ "ctrl+right",
+ function()
+ self:next_word()
+ end,
+ },
+ {
+ "alt+f",
+ function()
+ self:next_word()
+ end,
+ },
+ {
+ "ctrl+a",
+ function()
+ self:go_home()
+ end,
+ },
+ {
+ "home",
+ function()
+ self:go_home()
+ end,
+ },
+ {
+ "ctrl+e",
+ function()
+ self:go_end()
+ end,
+ },
+ {
+ "end",
+ function()
+ self:go_end()
+ end,
+ },
+ {
+ "ctrl+shift+f",
+ function()
+ self:handle_pgdown()
+ end,
+ },
+ {
+ "ctrl+shift+b",
+ function()
+ self:handle_pgup()
+ end,
+ },
+ {
+ "pgdwn",
+ function()
+ self:handle_pgdown()
+ end,
+ },
+ {
+ "pgup",
+ function()
+ self:handle_pgup()
+ end,
+ },
+ {
+ "ctrl+c",
+ function()
+ self:clear()
+ end,
+ },
+ {
+ "ctrl+d",
+ function()
+ self:handle_del()
+ end,
+ },
+ {
+ "ctrl+u",
+ function()
+ self:del_to_start()
+ end,
+ },
+ {
+ "ctrl+v",
+ function()
+ self:paste(true)
+ end,
+ },
+ {
+ "meta+v",
+ function()
+ self:paste(true)
+ end,
+ },
+ {
+ "ctrl+bs",
+ function()
+ self:del_word()
+ end,
+ },
+ {
+ "ctrl+w",
+ function()
+ self:del_word()
+ end,
+ },
+ {
+ "ctrl+del",
+ function()
+ self:del_next_word()
+ end,
+ },
+ {
+ "alt+d",
+ function()
+ self:del_next_word()
+ end,
+ },
+ {
+ "kp_dec",
+ function()
+ self:handle_char_input(".")
+ end,
+ },
+ }
+
+ for i = 0, 9 do
+ bindings[#bindings + 1] = {
+ "kp" .. i,
+ function()
+ self:handle_char_input("" .. i)
+ end,
+ }
+ end
+
+ return bindings
+end
+
+function em:text_input(info)
+ if info.key_text and (info.event == "press" or info.event == "down" or info.event == "repeat") then
+ self:handle_char_input(info.key_text)
+ end
+end
+
+function em:define_key_bindings()
+ if #self.key_bindings > 0 then
+ return
+ end
+ for _, bind in ipairs(self:get_bindings()) do
+ -- Generate arbitrary name for removing the bindings later.
+ local name = "search_" .. (#self.key_bindings + 1)
+ self.key_bindings[#self.key_bindings + 1] = name
+ mp.add_forced_key_binding(bind[1], name, bind[2], { repeatable = true })
+ end
+ mp.add_forced_key_binding("any_unicode", "search_input", function(...)
+ self:text_input(...)
+ end, { repeatable = true, complex = true })
+ self.key_bindings[#self.key_bindings + 1] = "search_input"
+end
+
+function em:undefine_key_bindings()
+ for _, name in ipairs(self.key_bindings) do
+ mp.remove_key_binding(name)
+ end
+ self.key_bindings = {}
+end
+
+-------------------------------------------------------------------------------
+-- END ORIGINAL MPV CODE --
+-------------------------------------------------------------------------------
+
+return em
diff --git a/mac/.config/mpv/script-modules/gallery.lua b/mac/.config/mpv/script-modules/gallery.lua
new file mode 100644
index 0000000..ee0be42
--- /dev/null
+++ b/mac/.config/mpv/script-modules/gallery.lua
@@ -0,0 +1,581 @@
+local utils = require("mp.utils")
+local msg = require("mp.msg")
+local assdraw = require("mp.assdraw")
+
+local gallery_mt = {}
+gallery_mt.__index = gallery_mt
+
+function gallery_new()
+ local gallery = setmetatable({
+ -- public, can be modified by user
+ items = {},
+ item_to_overlay_path = function(index, item)
+ return ""
+ end,
+ item_to_thumbnail_params = function(index, item)
+ return "", 0
+ end,
+ item_to_text = function(index, item)
+ return "", true
+ end,
+ item_to_border = function(index, item)
+ return 0, ""
+ end,
+ ass_show = function(ass) end,
+ config = {
+ background_color = "333333",
+ background_opacity = "33",
+ background_roundness = 5,
+ scrollbar = true,
+ scrollbar_left_side = false,
+ scrollbar_min_size = 10,
+ overlay_range = 0,
+ max_thumbnails = 64,
+ show_placeholders = true,
+ always_show_placeholders = false,
+ placeholder_color = "222222",
+ text_size = 28,
+ align_text = true,
+ accurate = false,
+ generate_thumbnails_with_mpv = false,
+ },
+
+ -- private, can be read but should not be modified
+ active = false,
+ geometry = {
+ ok = false,
+ position = { 0, 0 },
+ size = { 0, 0 },
+ min_spacing = { 0, 0 },
+ thumbnail_size = { 0, 0 },
+ rows = 0,
+ columns = 0,
+ effective_spacing = { 0, 0 },
+ },
+ view = { -- 1-based indices into the "playlist" array
+ first = 0, -- must be equal to N*columns
+ last = 0, -- must be > first and <= first + rows*columns
+ },
+ overlays = {
+ active = {}, -- array of <=64 strings indicating the file associated to the current overlay (false if nothing)
+ missing = {}, -- associative array of thumbnail path to view index it should be shown at
+ },
+ selection = nil,
+ ass = {
+ background = "",
+ selection = "",
+ scrollbar = "",
+ placeholders = "",
+ },
+ generators = {}, -- list of generator scripts
+ }, gallery_mt)
+
+ for i = 1, gallery.config.max_thumbnails do
+ gallery.overlays.active[i] = false
+ end
+ return gallery
+end
+
+function gallery_mt.show_overlay(gallery, index_1, thumb_path)
+ local g = gallery.geometry
+ gallery.overlays.active[index_1] = thumb_path
+ local index_0 = index_1 - 1
+ local x, y = gallery:view_index_position(index_0)
+ mp.commandv(
+ "overlay-add",
+ tostring(index_0 + gallery.config.overlay_range),
+ tostring(math.floor(x + 0.5)),
+ tostring(math.floor(y + 0.5)),
+ thumb_path,
+ "0",
+ "bgra",
+ tostring(g.thumbnail_size[1]),
+ tostring(g.thumbnail_size[2]),
+ tostring(4 * g.thumbnail_size[1])
+ )
+ mp.osd_message(" ", 0.01)
+end
+
+function gallery_mt.remove_overlays(gallery)
+ for view_index, _ in pairs(gallery.overlays.active) do
+ mp.commandv("overlay-remove", gallery.config.overlay_range + view_index - 1)
+ gallery.overlays.active[view_index] = false
+ end
+ gallery.overlays.missing = {}
+end
+
+local function file_exists(path)
+ local info = utils.file_info(path)
+ return info ~= nil and info.is_file
+end
+
+function gallery_mt.refresh_overlays(gallery, force)
+ local todo = {}
+ local o = gallery.overlays
+ local g = gallery.geometry
+ o.missing = {}
+ for view_index = 1, g.rows * g.columns do
+ local index = gallery.view.first + view_index - 1
+ local active = o.active[view_index]
+ if index > 0 and index <= #gallery.items then
+ local thumb_path = gallery.item_to_overlay_path(index, gallery.items[index])
+ if not force and active == thumb_path then
+ -- nothing to do
+ elseif file_exists(thumb_path) then
+ gallery:show_overlay(view_index, thumb_path)
+ else
+ -- need to generate that thumbnail
+ o.active[view_index] = false
+ mp.commandv("overlay-remove", gallery.config.overlay_range + view_index - 1)
+ o.missing[thumb_path] = view_index
+ todo[#todo + 1] = { index = index, output = thumb_path }
+ end
+ else
+ -- might happen if we're close to the end of gallery.items
+ if active ~= false then
+ o.active[view_index] = false
+ mp.commandv("overlay-remove", gallery.config.overlay_range + view_index - 1)
+ end
+ end
+ end
+ if #gallery.generators >= 1 then
+ -- reverse iterate so that the first thumbnail is at the top of the stack
+ for i = #todo, 1, -1 do
+ local generator = gallery.generators[i % #gallery.generators + 1]
+ local t = todo[i]
+ local input_path, time = gallery.item_to_thumbnail_params(t.index, gallery.items[t.index])
+ mp.commandv(
+ "script-message-to",
+ generator,
+ "push-thumbnail-front",
+ mp.get_script_name(),
+ input_path,
+ tostring(g.thumbnail_size[1]),
+ tostring(g.thumbnail_size[2]),
+ time,
+ t.output,
+ gallery.config.accurate and "true" or "false",
+ gallery.config.generate_thumbnails_with_mpv and "true" or "false"
+ )
+ end
+ end
+end
+
+function gallery_mt.index_at(gallery, mx, my)
+ local g = gallery.geometry
+ if mx < g.position[1] or my < g.position[2] then
+ return nil
+ end
+ mx = mx - g.position[1]
+ my = my - g.position[2]
+ if mx > g.size[1] or my > g.size[2] then
+ return nil
+ end
+ mx = mx - g.effective_spacing[1]
+ my = my - g.effective_spacing[2]
+ local on_column = (mx % (g.thumbnail_size[1] + g.effective_spacing[1])) < g.thumbnail_size[1]
+ local on_row = (my % (g.thumbnail_size[2] + g.effective_spacing[2])) < g.thumbnail_size[2]
+ if on_column and on_row then
+ local column = math.floor(mx / (g.thumbnail_size[1] + g.effective_spacing[1]))
+ local row = math.floor(my / (g.thumbnail_size[2] + g.effective_spacing[2]))
+ local index = gallery.view.first + row * g.columns + column
+ if index > 0 and index <= gallery.view.last then
+ return index
+ end
+ end
+ return nil
+end
+
+function gallery_mt.compute_internal_geometry(gallery)
+ local g = gallery.geometry
+ g.rows = math.floor((g.size[2] - g.min_spacing[2]) / (g.thumbnail_size[2] + g.min_spacing[2]))
+ g.columns = math.floor((g.size[1] - g.min_spacing[1]) / (g.thumbnail_size[1] + g.min_spacing[1]))
+ if g.rows <= 0 or g.columns <= 0 then
+ g.rows = 0
+ g.columns = 0
+ g.effective_spacing[1] = g.size[1]
+ g.effective_spacing[2] = g.size[2]
+ return
+ end
+ if g.rows * g.columns > gallery.config.max_thumbnails then
+ local r = math.sqrt(g.rows * g.columns / gallery.config.max_thumbnails)
+ g.rows = math.floor(g.rows / r)
+ g.columns = math.floor(g.columns / r)
+ end
+ g.effective_spacing[1] = (g.size[1] - g.columns * g.thumbnail_size[1]) / (g.columns + 1)
+ g.effective_spacing[2] = (g.size[2] - g.rows * g.thumbnail_size[2]) / (g.rows + 1)
+end
+
+-- makes sure that view.first and view.last are valid with regards to the playlist
+-- and that selection is within the view
+-- to be called after the playlist, view or selection was modified somehow
+function gallery_mt.ensure_view_valid(gallery)
+ local g = gallery.geometry
+ if #gallery.items == 0 or g.rows == 0 or g.columns == 0 then
+ gallery.view.first = 0
+ gallery.view.last = 0
+ return
+ end
+ local v = gallery.view
+ local selection_row = math.floor((gallery.selection - 1) / g.columns)
+ local max_thumbs = g.rows * g.columns
+ local changed = false
+
+ if v.last >= #gallery.items then
+ v.last = #gallery.items
+ if g.rows == 1 then
+ v.first = math.max(1, v.last - g.columns + 1)
+ else
+ local last_row = math.floor((v.last - 1) / g.columns)
+ local first_row = math.max(0, last_row - g.rows + 1)
+ v.first = 1 + first_row * g.columns
+ end
+ changed = true
+ elseif v.first == 0 or v.last == 0 or v.last - v.first + 1 ~= max_thumbs then
+ -- special case: the number of possible thumbnails was changed
+ -- just recreate the view such that the selection is in the middle row
+ local max_row = (#gallery.items - 1) / g.columns + 1
+ local row_first = selection_row - math.floor((g.rows - 1) / 2)
+ local row_last = selection_row + math.floor((g.rows - 1) / 2) + g.rows % 2
+ if row_first < 0 then
+ row_first = 0
+ elseif row_last > max_row then
+ row_first = max_row - g.rows + 1
+ end
+ v.first = 1 + row_first * g.columns
+ v.last = math.min(#gallery.items, v.first - 1 + max_thumbs)
+ return true
+ end
+
+ if gallery.selection < v.first then
+ -- the selection is now on the first line
+ v.first = (g.rows == 1) and gallery.selection or selection_row * g.columns + 1
+ v.last = math.min(#gallery.items, v.first + max_thumbs - 1)
+ changed = true
+ elseif gallery.selection > v.last then
+ v.last = (g.rows == 1) and gallery.selection or (selection_row + 1) * g.columns
+ v.first = math.max(1, v.last - max_thumbs + 1)
+ v.last = math.min(#gallery.items, v.last)
+ changed = true
+ end
+ return changed
+end
+
+-- ass related stuff
+function gallery_mt.refresh_background(gallery)
+ local g = gallery.geometry
+ local a = assdraw.ass_new()
+ a:new_event()
+ a:append("{\\an7}")
+ a:append("{\\bord0}")
+ a:append("{\\shad0}")
+ a:append("{\\1c&" .. gallery.config.background_color .. "}")
+ a:append("{\\1a&" .. gallery.config.background_opacity .. "}")
+ a:pos(0, 0)
+ a:draw_start()
+ a:round_rect_cw(
+ g.position[1],
+ g.position[2],
+ g.position[1] + g.size[1],
+ g.position[2] + g.size[2],
+ gallery.config.background_roundness
+ )
+ a:draw_stop()
+ gallery.ass.background = a.text
+end
+
+function gallery_mt.refresh_placeholders(gallery)
+ if not gallery.config.show_placeholders then
+ return
+ end
+ if gallery.view.first == 0 then
+ gallery.ass.placeholders = ""
+ return
+ end
+ local g = gallery.geometry
+ local a = assdraw.ass_new()
+ a:new_event()
+ a:append("{\\an7}")
+ a:append("{\\bord0}")
+ a:append("{\\shad0}")
+ a:append("{\\1c&" .. gallery.config.placeholder_color .. "}")
+ a:pos(0, 0)
+ a:draw_start()
+ for i = 0, gallery.view.last - gallery.view.first do
+ if gallery.config.always_show_placeholders or not gallery.overlays.active[i + 1] then
+ local x, y = gallery:view_index_position(i)
+ a:rect_cw(x, y, x + g.thumbnail_size[1], y + g.thumbnail_size[2])
+ end
+ end
+ a:draw_stop()
+ gallery.ass.placeholders = a.text
+end
+
+function gallery_mt.refresh_scrollbar(gallery)
+ if not gallery.config.scrollbar then
+ return
+ end
+ gallery.ass.scrollbar = ""
+ if gallery.view.first == 0 then
+ return
+ end
+ local g = gallery.geometry
+ local before = (gallery.view.first - 1) / #gallery.items
+ local after = (#gallery.items - gallery.view.last) / #gallery.items
+ -- don't show the scrollbar if everything is visible
+ if before + after == 0 then
+ return
+ end
+ local p = gallery.config.scrollbar_min_size / 100
+ if before + after > 1 - p then
+ if before == 0 then
+ after = (1 - p)
+ elseif after == 0 then
+ before = (1 - p)
+ else
+ before, after =
+ before / after * (1 - p) / (1 + before / after), after / before * (1 - p) / (1 + after / before)
+ end
+ end
+ local dist_from_edge = g.size[2] * 0.015
+ local y1 = g.position[2] + dist_from_edge + before * (g.size[2] - 2 * dist_from_edge)
+ local y2 = g.position[2] + g.size[2] - (dist_from_edge + after * (g.size[2] - 2 * dist_from_edge))
+ local x1, x2
+ if gallery.config.scrollbar_left_side then
+ x1 = g.position[1] + g.effective_spacing[1] / 2 - 2
+ else
+ x1 = g.position[1] + g.size[1] - g.effective_spacing[1] / 2 - 2
+ end
+ x2 = x1 + 4
+ local scrollbar = assdraw.ass_new()
+ scrollbar:new_event()
+ scrollbar:append("{\\an7}")
+ scrollbar:append("{\\bord0}")
+ scrollbar:append("{\\shad0}")
+ scrollbar:append("{\\1c&AAAAAA&}")
+ scrollbar:pos(0, 0)
+ scrollbar:draw_start()
+ scrollbar:rect_cw(x1, y1, x2, y2)
+ scrollbar:draw_stop()
+ gallery.ass.scrollbar = scrollbar.text
+end
+
+function gallery_mt.refresh_selection(gallery)
+ local v = gallery.view
+ if v.first == 0 then
+ gallery.ass.selection = ""
+ return
+ end
+ local selection_ass = assdraw.ass_new()
+ local g = gallery.geometry
+ local draw_frame = function(index, size, color)
+ local x, y = gallery:view_index_position(index - v.first)
+ selection_ass:new_event()
+ selection_ass:append("{\\an7}")
+ selection_ass:append("{\\bord" .. size .. "}")
+ selection_ass:append("{\\3c&" .. color .. "&}")
+ selection_ass:append("{\\1a&FF&}")
+ selection_ass:pos(0, 0)
+ selection_ass:draw_start()
+ selection_ass:rect_cw(x, y, x + g.thumbnail_size[1], y + g.thumbnail_size[2])
+ selection_ass:draw_stop()
+ end
+ for i = v.first, v.last do
+ local size, color = gallery.item_to_border(i, gallery.items[i])
+ if size > 0 then
+ draw_frame(i, size, color)
+ end
+ end
+
+ for index = v.first, v.last do
+ local text = gallery.item_to_text(index, gallery.items[index])
+ if text ~= "" then
+ selection_ass:new_event()
+ local an = 5
+ local x, y = gallery:view_index_position(index - v.first)
+ x = x + g.thumbnail_size[1] / 2
+ y = y + g.thumbnail_size[2] + gallery.config.text_size * 0.75
+ if gallery.config.align_text then
+ local col = (index - v.first) % g.columns
+ if g.columns > 1 then
+ if col == 0 then
+ x = x - g.thumbnail_size[1] / 2
+ an = 4
+ elseif col == g.columns - 1 then
+ x = x + g.thumbnail_size[1] / 2
+ an = 6
+ end
+ end
+ end
+ selection_ass:an(an)
+ selection_ass:pos(x, y)
+ selection_ass:append(string.format("{\\fs%d}", gallery.config.text_size))
+ selection_ass:append("{\\bord0}")
+ selection_ass:append(text)
+ end
+ end
+ gallery.ass.selection = selection_ass.text
+end
+
+function gallery_mt.ass_refresh(gallery, selection, scrollbar, placeholders, background)
+ if not gallery.active then
+ return
+ end
+ if selection then
+ gallery:refresh_selection()
+ end
+ if scrollbar then
+ gallery:refresh_scrollbar()
+ end
+ if placeholders then
+ gallery:refresh_placeholders()
+ end
+ if background then
+ gallery:refresh_background()
+ end
+ gallery.ass_show(table.concat({
+ gallery.ass.background,
+ gallery.ass.placeholders,
+ gallery.ass.selection,
+ gallery.ass.scrollbar,
+ }, "\n"))
+end
+
+function gallery_mt.set_selection(gallery, selection)
+ if not selection or selection ~= selection then
+ return
+ end
+ local new_selection = math.max(1, math.min(selection, #gallery.items))
+ if gallery.selection == new_selection then
+ return
+ end
+ gallery.selection = new_selection
+ if gallery.active then
+ if gallery:ensure_view_valid() then
+ gallery:refresh_overlays(false)
+ gallery:ass_refresh(true, true, true, false)
+ else
+ gallery:ass_refresh(true, false, false, false)
+ end
+ end
+end
+
+function gallery_mt.set_geometry(gallery, x, y, w, h, sw, sh, tw, th)
+ if w <= 0 or h <= 0 or tw <= 0 or th <= 0 then
+ msg.warn("Invalid coordinates")
+ return
+ end
+ gallery.geometry.position = { x, y }
+ gallery.geometry.size = { w, h }
+ gallery.geometry.min_spacing = { sw, sh }
+ gallery.geometry.thumbnail_size = { tw, th }
+ gallery.geometry.ok = true
+ if not gallery.active then
+ return
+ end
+ if not gallery:enough_space() then
+ msg.warn("Not enough space to display something")
+ end
+ local old_total = gallery.geometry.rows * gallery.geometry.columns
+ gallery:compute_internal_geometry()
+ gallery:ensure_view_valid()
+ local new_total = gallery.geometry.rows * gallery.geometry.columns
+ for view_index = new_total + 1, old_total do
+ if gallery.overlays.active[view_index] then
+ mp.commandv("overlay-remove", gallery.config.overlay_range + view_index - 1)
+ gallery.overlays.active[view_index] = false
+ end
+ end
+ gallery:refresh_overlays(true)
+ gallery:ass_refresh(true, true, true, true)
+end
+
+function gallery_mt.items_changed(gallery, new_sel)
+ gallery.selection = math.max(1, math.min(new_sel, #gallery.items))
+ if not gallery.active then
+ return
+ end
+ gallery:ensure_view_valid()
+ gallery:refresh_overlays(false)
+ gallery:ass_refresh(true, true, true, false)
+end
+
+function gallery_mt.thumbnail_generated(gallery, thumb_path)
+ if not gallery.active then
+ return
+ end
+ local view_index = gallery.overlays.missing[thumb_path]
+ if view_index == nil then
+ return
+ end
+ gallery:show_overlay(view_index, thumb_path)
+ if not gallery.config.always_show_placeholders then
+ gallery:ass_refresh(false, false, true, false)
+ end
+ gallery.overlays.missing[thumb_path] = nil
+end
+
+function gallery_mt.add_generator(gallery, generator_name)
+ for _, g in ipairs(gallery.generators) do
+ if generator_name == g then
+ return
+ end
+ end
+ gallery.generators[#gallery.generators + 1] = generator_name
+end
+
+function gallery_mt.view_index_position(gallery, index_0)
+ local g = gallery.geometry
+ return math.floor(
+ g.position[1] + g.effective_spacing[1] + (g.effective_spacing[1] + g.thumbnail_size[1]) * (index_0 % g.columns)
+ ),
+ math.floor(
+ g.position[2]
+ + g.effective_spacing[2]
+ + (g.effective_spacing[2] + g.thumbnail_size[2]) * math.floor(index_0 / g.columns)
+ )
+end
+
+function gallery_mt.enough_space(gallery)
+ if gallery.geometry.size[1] < gallery.geometry.thumbnail_size[1] + 2 * gallery.geometry.min_spacing[1] then
+ return false
+ end
+ if gallery.geometry.size[2] < gallery.geometry.thumbnail_size[2] + 2 * gallery.geometry.min_spacing[2] then
+ return false
+ end
+ return true
+end
+
+function gallery_mt.activate(gallery)
+ if gallery.active then
+ return false
+ end
+ if not gallery:enough_space() then
+ msg.warn("Not enough space, refusing to start")
+ return false
+ end
+ if not gallery.geometry.ok then
+ msg.warn("Gallery geometry unitialized, refusing to start")
+ return false
+ end
+ gallery.active = true
+ if not gallery.selection then
+ gallery:set_selection(1)
+ end
+ gallery:compute_internal_geometry()
+ gallery:ensure_view_valid()
+ gallery:refresh_overlays(false)
+ gallery:ass_refresh(true, true, true, true)
+ return true
+end
+
+function gallery_mt.deactivate(gallery)
+ if not gallery.active then
+ return
+ end
+ gallery.active = false
+ gallery:remove_overlays()
+ gallery.ass_show("")
+end
+
+return { gallery_new = gallery_new }
diff --git a/mac/.config/mpv/script-modules/input-console.lua b/mac/.config/mpv/script-modules/input-console.lua
new file mode 100644
index 0000000..9128cba
--- /dev/null
+++ b/mac/.config/mpv/script-modules/input-console.lua
@@ -0,0 +1,935 @@
+-- copied from here: https://github.com/mpv-player/mpv/blob/ebaf6a6cfa24a78d9041389974568b9db7df6a71/player/lua/console.lua
+
+-- Copyright (C) 2019 the mpv developers
+--
+-- Permission to use, copy, modify, and/or distribute this software for any
+-- purpose with or without fee is hereby granted, provided that the above
+-- copyright notice and this permission notice appear in all copies.
+--
+-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+-- SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+-- OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+-- CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+local utils = require("mp.utils")
+local options = require("mp.options")
+local assdraw = require("mp.assdraw")
+
+-- Default options
+local opts = {
+ -- All drawing is scaled by this value, including the text borders and the
+ -- cursor. Change it if you have a high-DPI display.
+ scale = 1.3,
+ -- Set the font used for the REPL and the console. This probably doesn't
+ -- have to be a monospaced font.
+ font = "",
+ -- Set the font size used for the REPL and the console. This will be
+ -- multiplied by "scale."
+ font_size = 16,
+}
+
+function detect_platform()
+ local o = {}
+ -- Kind of a dumb way of detecting the platform but whatever
+ if mp.get_property_native("options/vo-mmcss-profile", o) ~= o then
+ return "windows"
+ elseif mp.get_property_native("options/macos-force-dedicated-gpu", o) ~= o then
+ return "macos"
+ elseif os.getenv("WAYLAND_DISPLAY") then
+ return "wayland"
+ end
+ return "x11"
+end
+
+-- Pick a better default font for Windows and macOS
+local platform = detect_platform()
+if platform == "windows" then
+ opts.font = "Consolas"
+elseif platform == "macos" then
+ opts.font = "Menlo"
+else
+ opts.font = "monospace"
+end
+
+-- Apply user-set options
+options.read_options(opts)
+
+local repl_active = false
+local insert_mode = false
+local pending_update = false
+local line = ""
+local cursor = 1
+local history = {}
+local history_pos = 1
+local log_buffer = {}
+local key_bindings = {}
+local global_margin_y = 0
+
+local update_timer = nil
+update_timer = mp.add_periodic_timer(0.05, function()
+ if pending_update then
+ update()
+ else
+ update_timer:kill()
+ end
+end)
+update_timer:kill()
+
+if utils.shared_script_property_observe then
+ utils.shared_script_property_observe("osc-margins", function(_, val)
+ if val then
+ -- formatted as "%f,%f,%f,%f" with left, right, top, bottom, each
+ -- value being the border size as ratio of the window size (0.0-1.0)
+ local vals = {}
+ for v in string.gmatch(val, "[^,]+") do
+ vals[#vals + 1] = tonumber(v)
+ end
+ global_margin_y = vals[4] -- bottom
+ else
+ global_margin_y = 0
+ end
+ update()
+ end)
+else
+ mp.observe_property("user-data/osc/margins", "native", function(_, val)
+ if val then
+ global_margin_y = val.b
+ else
+ global_margin_y = 0
+ end
+ end)
+end
+
+-- Add a line to the log buffer (which is limited to 100 lines)
+function log_add(style, text)
+ log_buffer[#log_buffer + 1] = { style = style, text = text }
+ if #log_buffer > 100 then
+ table.remove(log_buffer, 1)
+ end
+
+ if repl_active then
+ if not update_timer:is_enabled() then
+ update()
+ update_timer:resume()
+ else
+ pending_update = true
+ end
+ end
+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
+end
+
+-- Render the REPL and console as an ASS OSD
+function update()
+ pending_update = false
+
+ local dpi_scale = mp.get_property_native("display-hidpi-scale", 1.0)
+
+ dpi_scale = dpi_scale * opts.scale
+
+ local screenx, screeny, aspect = mp.get_osd_size()
+ screenx = screenx / dpi_scale
+ screeny = screeny / dpi_scale
+
+ -- Clear the OSD if the REPL is not active
+ if not repl_active then
+ mp.set_osd_ass(screenx, screeny, "")
+ return
+ end
+
+ local ass = assdraw.ass_new()
+ local style = "{\\r"
+ .. "\\1a&H00&\\3a&H00&\\4a&H99&"
+ .. "\\1c&Heeeeee&\\3c&H111111&\\4c&H000000&"
+ .. "\\fn"
+ .. opts.font
+ .. "\\fs"
+ .. opts.font_size
+ .. "\\bord1\\xshad0\\yshad1\\fsp0\\q1}"
+ -- Create the cursor glyph as an ASS drawing. ASS will draw the cursor
+ -- inline with the surrounding text, but it sets the advance to the width
+ -- of the drawing. So the cursor doesn't affect layout too much, make it as
+ -- thin as possible and make it appear to be 1px wide by giving it 0.5px
+ -- horizontal borders.
+ local cheight = opts.font_size * 8
+ local cglyph = "{\\r"
+ .. "\\1a&H44&\\3a&H44&\\4a&H99&"
+ .. "\\1c&Heeeeee&\\3c&Heeeeee&\\4c&H000000&"
+ .. "\\xbord0.5\\ybord0\\xshad0\\yshad1\\p4\\pbo24}"
+ .. "m 0 0 l 1 0 l 1 "
+ .. cheight
+ .. " l 0 "
+ .. cheight
+ .. "{\\p0}"
+ local before_cur = ass_escape(line:sub(1, cursor - 1))
+ local after_cur = ass_escape(line:sub(cursor))
+
+ -- Render log messages as ASS. This will render at most screeny / font_size
+ -- messages.
+ local log_ass = ""
+ local log_messages = #log_buffer
+ local log_max_lines = math.ceil(screeny / opts.font_size)
+ if log_max_lines < log_messages then
+ log_messages = log_max_lines
+ end
+ for i = #log_buffer - log_messages + 1, #log_buffer do
+ log_ass = log_ass .. style .. log_buffer[i].style .. ass_escape(log_buffer[i].text)
+ end
+
+ ass:new_event()
+ ass:an(1)
+ ass:pos(2, screeny - 2 - global_margin_y * screeny)
+ ass:append(log_ass .. "\\N")
+ ass:append(style .. "> " .. before_cur)
+ ass:append(cglyph)
+ ass:append(style .. after_cur)
+
+ -- Redraw the cursor with the REPL text invisible. This will make the
+ -- cursor appear in front of the text.
+ ass:new_event()
+ ass:an(1)
+ ass:pos(2, screeny - 2 - global_margin_y * screeny)
+ ass:append(style .. "{\\alpha&HFF&}> " .. before_cur)
+ ass:append(cglyph)
+ ass:append(style .. "{\\alpha&HFF&}" .. after_cur)
+
+ mp.set_osd_ass(screenx, screeny, ass.text)
+end
+
+-- Set the REPL visibility ("enable", Esc)
+function set_active(active)
+ if active == repl_active then
+ return
+ end
+ if active then
+ repl_active = true
+ insert_mode = false
+ mp.enable_key_bindings("console-input", "allow-hide-cursor+allow-vo-dragging")
+ mp.enable_messages("terminal-default")
+ define_key_bindings()
+ else
+ repl_active = false
+ undefine_key_bindings()
+ mp.enable_messages("silent:terminal-default")
+ collectgarbage()
+ end
+ update()
+end
+
+-- Show the repl if hidden and replace its contents with 'text'
+-- (script-message-to repl type)
+function show_and_type(text, cursor_pos)
+ text = text or ""
+ cursor_pos = tonumber(cursor_pos)
+
+ -- Save the line currently being edited, just in case
+ if line ~= text and line ~= "" and history[#history] ~= line then
+ history[#history + 1] = line
+ end
+
+ line = text
+ if cursor_pos ~= nil and cursor_pos >= 1 and cursor_pos <= line:len() + 1 then
+ cursor = math.floor(cursor_pos)
+ else
+ cursor = line:len() + 1
+ end
+ history_pos = #history + 1
+ insert_mode = false
+ if repl_active then
+ update()
+ else
+ set_active(true)
+ end
+end
+
+-- Naive helper function to find the next UTF-8 character in 'str' after 'pos'
+-- by skipping continuation bytes. Assumes 'str' contains valid UTF-8.
+function next_utf8(str, pos)
+ if pos > str:len() then
+ return pos
+ end
+ repeat
+ pos = pos + 1
+ until pos > str:len() or str:byte(pos) < 0x80 or str:byte(pos) > 0xbf
+ return pos
+end
+
+-- As above, but finds the previous UTF-8 character in 'str' before 'pos'
+function prev_utf8(str, pos)
+ if pos <= 1 then
+ return pos
+ end
+ repeat
+ pos = pos - 1
+ until pos <= 1 or str:byte(pos) < 0x80 or str:byte(pos) > 0xbf
+ return pos
+end
+
+-- Insert a character at the current cursor position (any_unicode)
+function handle_char_input(c)
+ if insert_mode then
+ line = line:sub(1, cursor - 1) .. c .. line:sub(next_utf8(line, cursor))
+ else
+ line = line:sub(1, cursor - 1) .. c .. line:sub(cursor)
+ end
+ cursor = cursor + #c
+ update()
+end
+
+-- Remove the character behind the cursor (Backspace)
+function handle_backspace()
+ if cursor <= 1 then
+ return
+ end
+ local prev = prev_utf8(line, cursor)
+ line = line:sub(1, prev - 1) .. line:sub(cursor)
+ cursor = prev
+ update()
+end
+
+-- Remove the character in front of the cursor (Del)
+function handle_del()
+ if cursor > line:len() then
+ return
+ end
+ line = line:sub(1, cursor - 1) .. line:sub(next_utf8(line, cursor))
+ update()
+end
+
+-- Toggle insert mode (Ins)
+function handle_ins()
+ insert_mode = not insert_mode
+end
+
+-- Move the cursor to the next character (Right)
+function next_char(amount)
+ cursor = next_utf8(line, cursor)
+ update()
+end
+
+-- Move the cursor to the previous character (Left)
+function prev_char(amount)
+ cursor = prev_utf8(line, cursor)
+ update()
+end
+
+-- Clear the current line (Ctrl+C)
+function clear()
+ line = ""
+ cursor = 1
+ insert_mode = false
+ history_pos = #history + 1
+ update()
+end
+
+-- Close the REPL if the current line is empty, otherwise delete the next
+-- character (Ctrl+D)
+function maybe_exit()
+ if line == "" then
+ set_active(false)
+ else
+ handle_del()
+ end
+end
+
+function help_command(param)
+ local cmdlist = mp.get_property_native("command-list")
+ local error_style = "{\\1c&H7a77f2&}"
+ local output = ""
+ if param == "" then
+ output = "Available commands:\n"
+ for _, cmd in ipairs(cmdlist) do
+ output = output .. " " .. cmd.name
+ end
+ output = output .. "\n"
+ output = output .. 'Use "help command" to show information about a command.\n'
+ output = output .. "ESC or Ctrl+d exits the console.\n"
+ else
+ local cmd = nil
+ for _, curcmd in ipairs(cmdlist) do
+ if curcmd.name:find(param, 1, true) then
+ cmd = curcmd
+ if curcmd.name == param then
+ break -- exact match
+ end
+ end
+ end
+ if not cmd then
+ log_add(error_style, 'No command matches "' .. param .. '"!')
+ return
+ end
+ output = output .. 'Command "' .. cmd.name .. '"\n'
+ for _, arg in ipairs(cmd.args) do
+ output = output .. " " .. arg.name .. " (" .. arg.type .. ")"
+ if arg.optional then
+ output = output .. " (optional)"
+ end
+ output = output .. "\n"
+ end
+ if cmd.vararg then
+ output = output .. "This command supports variable arguments.\n"
+ end
+ end
+ log_add("", output)
+end
+
+local enter_handler = nil
+
+-- Run the current command and clear the line (Enter)
+function handle_enter()
+ if line == "" then
+ return
+ end
+
+ if history[#history] ~= line then
+ history[#history + 1] = line
+ end
+
+ if enter_handler then
+ enter_handler(line)
+ end
+
+ set_active(false)
+
+ clear()
+end
+
+-- Go to the specified position in the command history
+function go_history(new_pos)
+ local old_pos = history_pos
+ history_pos = new_pos
+
+ -- Restrict the position to a legal value
+ if history_pos > #history + 1 then
+ history_pos = #history + 1
+ elseif history_pos < 1 then
+ history_pos = 1
+ end
+
+ -- Do nothing if the history position didn't actually change
+ if history_pos == old_pos then
+ return
+ end
+
+ -- If the user was editing a non-history line, save it as the last history
+ -- entry. This makes it much less frustrating to accidentally hit Up/Down
+ -- while editing a line.
+ if old_pos == #history + 1 and line ~= "" and history[#history] ~= line then
+ history[#history + 1] = line
+ end
+
+ -- Now show the history line (or a blank line for #history + 1)
+ if history_pos <= #history then
+ line = history[history_pos]
+ else
+ line = ""
+ end
+ cursor = line:len() + 1
+ insert_mode = false
+ update()
+end
+
+-- Go to the specified relative position in the command history (Up, Down)
+function move_history(amount)
+ go_history(history_pos + amount)
+end
+
+-- Go to the first command in the command history (PgUp)
+function handle_pgup()
+ go_history(1)
+end
+
+-- Stop browsing history and start editing a blank line (PgDown)
+function handle_pgdown()
+ go_history(#history + 1)
+end
+
+-- Move to the start of the current word, or if already at the start, the start
+-- of the previous word. (Ctrl+Left)
+function prev_word()
+ -- This is basically the same as next_word() but backwards, so reverse the
+ -- string in order to do a "backwards" find. This wouldn't be as annoying
+ -- to do if Lua didn't insist on 1-based indexing.
+ cursor = line:len() - select(2, line:reverse():find("%s*[^%s]*", line:len() - cursor + 2)) + 1
+ update()
+end
+
+-- Move to the end of the current word, or if already at the end, the end of
+-- the next word. (Ctrl+Right)
+function next_word()
+ cursor = select(2, line:find("%s*[^%s]*", cursor)) + 1
+ update()
+end
+
+-- List of tab-completions:
+-- pattern: A Lua pattern used in string:find. Should return the start and
+-- end positions of the word to be completed in the first and second
+-- capture groups (using the empty parenthesis notation "()")
+-- list: A list of candidate completion values.
+-- append: An extra string to be appended to the end of a successful
+-- completion. It is only appended if 'list' contains exactly one
+-- match.
+function build_completers()
+ -- Build a list of commands, properties and options for tab-completion
+ local option_info = {
+ "name",
+ "type",
+ "set-from-commandline",
+ "set-locally",
+ "default-value",
+ "min",
+ "max",
+ "choices",
+ }
+ local cmd_list = {}
+ for i, cmd in ipairs(mp.get_property_native("command-list")) do
+ cmd_list[i] = cmd.name
+ end
+ local prop_list = mp.get_property_native("property-list")
+ for _, opt in ipairs(mp.get_property_native("options")) do
+ prop_list[#prop_list + 1] = "options/" .. opt
+ prop_list[#prop_list + 1] = "file-local-options/" .. opt
+ prop_list[#prop_list + 1] = "option-info/" .. opt
+ for _, p in ipairs(option_info) do
+ prop_list[#prop_list + 1] = "option-info/" .. opt .. "/" .. p
+ end
+ end
+
+ return {
+ { pattern = "^%s*()[%w_-]+()$", list = cmd_list, append = " " },
+ { pattern = "^%s*set%s+()[%w_/-]+()$", list = prop_list, append = " " },
+ { pattern = '^%s*set%s+"()[%w_/-]+()$', list = prop_list, append = '" ' },
+ { pattern = "^%s*add%s+()[%w_/-]+()$", list = prop_list, append = " " },
+ { pattern = '^%s*add%s+"()[%w_/-]+()$', list = prop_list, append = '" ' },
+ { pattern = "^%s*cycle%s+()[%w_/-]+()$", list = prop_list, append = " " },
+ { pattern = '^%s*cycle%s+"()[%w_/-]+()$', list = prop_list, append = '" ' },
+ { pattern = "^%s*multiply%s+()[%w_/-]+()$", list = prop_list, append = " " },
+ { pattern = '^%s*multiply%s+"()[%w_/-]+()$', list = prop_list, append = '" ' },
+ { pattern = "${()[%w_/-]+()$", list = prop_list, append = "}" },
+ }
+end
+
+-- Use 'list' to find possible tab-completions for 'part.' Returns the longest
+-- common prefix of all the matching list items and a flag that indicates
+-- whether the match was unique or not.
+function complete_match(part, list)
+ local completion = nil
+ local full_match = false
+
+ for _, candidate in ipairs(list) do
+ if candidate:sub(1, part:len()) == part then
+ if completion and completion ~= candidate then
+ local prefix_len = part:len()
+ while completion:sub(1, prefix_len + 1) == candidate:sub(1, prefix_len + 1) do
+ prefix_len = prefix_len + 1
+ end
+ completion = candidate:sub(1, prefix_len)
+ full_match = false
+ else
+ completion = candidate
+ full_match = true
+ end
+ end
+ end
+
+ return completion, full_match
+end
+
+-- Complete the option or property at the cursor (TAB)
+function complete()
+ local before_cur = line:sub(1, cursor - 1)
+ local after_cur = line:sub(cursor)
+
+ -- Try the first completer that works
+ for _, completer in ipairs(build_completers()) do
+ -- Completer patterns should return the start and end of the word to be
+ -- completed as the first and second capture groups
+ local _, _, s, e = before_cur:find(completer.pattern)
+ if not s then
+ -- Multiple input commands can be separated by semicolons, so all
+ -- completions that are anchored at the start of the string with
+ -- '^' can start from a semicolon as well. Replace ^ with ; and try
+ -- to match again.
+ _, _, s, e = before_cur:find(completer.pattern:gsub("^^", ";"))
+ end
+ if s then
+ -- If the completer's pattern found a word, check the completer's
+ -- list for possible completions
+ local part = before_cur:sub(s, e)
+ local c, full = complete_match(part, completer.list)
+ if c then
+ -- If there was only one full match from the list, add
+ -- completer.append to the final string. This is normally a
+ -- space or a quotation mark followed by a space.
+ if full and completer.append then
+ c = c .. completer.append
+ end
+
+ -- Insert the completion and update
+ before_cur = before_cur:sub(1, s - 1) .. c
+ cursor = before_cur:len() + 1
+ line = before_cur .. after_cur
+ update()
+ return
+ end
+ end
+ end
+end
+
+-- Move the cursor to the beginning of the line (HOME)
+function go_home()
+ cursor = 1
+ update()
+end
+
+-- Move the cursor to the end of the line (END)
+function go_end()
+ cursor = line:len() + 1
+ update()
+end
+
+-- Delete from the cursor to the beginning of the word (Ctrl+Backspace)
+function del_word()
+ local before_cur = line:sub(1, cursor - 1)
+ local after_cur = line:sub(cursor)
+
+ before_cur = before_cur:gsub("[^%s]+%s*$", "", 1)
+ line = before_cur .. after_cur
+ cursor = before_cur:len() + 1
+ update()
+end
+
+-- Delete from the cursor to the end of the word (Ctrl+Del)
+function del_next_word()
+ if cursor > line:len() then
+ return
+ end
+
+ local before_cur = line:sub(1, cursor - 1)
+ local after_cur = line:sub(cursor)
+
+ after_cur = after_cur:gsub("^%s*[^%s]+", "", 1)
+ line = before_cur .. after_cur
+ update()
+end
+
+-- Delete from the cursor to the end of the line (Ctrl+K)
+function del_to_eol()
+ line = line:sub(1, cursor - 1)
+ update()
+end
+
+-- Delete from the cursor back to the start of the line (Ctrl+U)
+function del_to_start()
+ line = line:sub(cursor)
+ cursor = 1
+ update()
+end
+
+-- Empty the log buffer of all messages (Ctrl+L)
+function clear_log_buffer()
+ log_buffer = {}
+ update()
+end
+
+-- Returns a string of UTF-8 text from the clipboard (or the primary selection)
+function get_clipboard(clip)
+ if platform == "x11" then
+ local res = utils.subprocess({
+ args = { "xclip", "-selection", clip and "clipboard" or "primary", "-out" },
+ playback_only = false,
+ })
+ if not res.error then
+ return res.stdout
+ end
+ elseif platform == "wayland" then
+ local res = utils.subprocess({
+ args = { "wl-paste", clip and "-n" or "-np" },
+ playback_only = false,
+ })
+ if not res.error then
+ return res.stdout
+ end
+ elseif platform == "windows" then
+ local res = utils.subprocess({
+ args = {
+ "powershell",
+ "-NoProfile",
+ "-Command",
+ [[& {
+ Trap {
+ Write-Error -ErrorRecord $_
+ Exit 1
+ }
+
+ $clip = ""
+ if (Get-Command "Get-Clipboard" -errorAction SilentlyContinue) {
+ $clip = Get-Clipboard -Raw -Format Text -TextFormatType UnicodeText
+ } else {
+ Add-Type -AssemblyName PresentationCore
+ $clip = [Windows.Clipboard]::GetText()
+ }
+
+ $clip = $clip -Replace "`r",""
+ $u8clip = [System.Text.Encoding]::UTF8.GetBytes($clip)
+ [Console]::OpenStandardOutput().Write($u8clip, 0, $u8clip.Length)
+ }]],
+ },
+ playback_only = false,
+ })
+ if not res.error then
+ return res.stdout
+ end
+ elseif platform == "macos" then
+ local res = utils.subprocess({
+ args = { "pbpaste" },
+ playback_only = false,
+ })
+ if not res.error then
+ return res.stdout
+ end
+ end
+ return ""
+end
+
+-- Paste text from the window-system's clipboard. 'clip' determines whether the
+-- clipboard or the primary selection buffer is used (on X11 and Wayland only.)
+function paste(clip)
+ local text = get_clipboard(clip)
+ local before_cur = line:sub(1, cursor - 1)
+ local after_cur = line:sub(cursor)
+ line = before_cur .. text .. after_cur
+ cursor = cursor + text:len()
+ update()
+end
+
+-- List of input bindings. This is a weird mashup between common GUI text-input
+-- bindings and readline bindings.
+function get_bindings()
+ local bindings = {
+ {
+ "esc",
+ function()
+ set_active(false)
+ end,
+ },
+ { "enter", handle_enter },
+ { "kp_enter", handle_enter },
+ {
+ "shift+enter",
+ function()
+ handle_char_input("\n")
+ end,
+ },
+ { "ctrl+j", handle_enter },
+ { "ctrl+m", handle_enter },
+ { "bs", handle_backspace },
+ { "shift+bs", handle_backspace },
+ { "ctrl+h", handle_backspace },
+ { "del", handle_del },
+ { "shift+del", handle_del },
+ { "ins", handle_ins },
+ {
+ "shift+ins",
+ function()
+ paste(false)
+ end,
+ },
+ {
+ "mbtn_mid",
+ function()
+ paste(false)
+ end,
+ },
+ {
+ "left",
+ function()
+ prev_char()
+ end,
+ },
+ {
+ "ctrl+b",
+ function()
+ prev_char()
+ end,
+ },
+ {
+ "right",
+ function()
+ next_char()
+ end,
+ },
+ {
+ "ctrl+f",
+ function()
+ next_char()
+ end,
+ },
+ {
+ "up",
+ function()
+ move_history(-1)
+ end,
+ },
+ {
+ "ctrl+p",
+ function()
+ move_history(-1)
+ end,
+ },
+ {
+ "wheel_up",
+ function()
+ move_history(-1)
+ end,
+ },
+ {
+ "down",
+ function()
+ move_history(1)
+ end,
+ },
+ {
+ "ctrl+n",
+ function()
+ move_history(1)
+ end,
+ },
+ {
+ "wheel_down",
+ function()
+ move_history(1)
+ end,
+ },
+ { "wheel_left", function() end },
+ { "wheel_right", function() end },
+ { "ctrl+left", prev_word },
+ { "alt+b", prev_word },
+ { "ctrl+right", next_word },
+ { "alt+f", next_word },
+ { "tab", complete },
+ { "ctrl+i", complete },
+ { "ctrl+a", go_home },
+ { "home", go_home },
+ { "ctrl+e", go_end },
+ { "end", go_end },
+ { "pgup", handle_pgup },
+ { "pgdwn", handle_pgdown },
+ { "ctrl+c", clear },
+ { "ctrl+d", maybe_exit },
+ { "ctrl+k", del_to_eol },
+ { "ctrl+l", clear_log_buffer },
+ { "ctrl+u", del_to_start },
+ {
+ "ctrl+v",
+ function()
+ paste(true)
+ end,
+ },
+ {
+ "meta+v",
+ function()
+ paste(true)
+ end,
+ },
+ { "ctrl+bs", del_word },
+ { "ctrl+w", del_word },
+ { "ctrl+del", del_next_word },
+ { "alt+d", del_next_word },
+ {
+ "kp_dec",
+ function()
+ handle_char_input(".")
+ end,
+ },
+ }
+
+ for i = 0, 9 do
+ bindings[#bindings + 1] = {
+ "kp" .. i,
+ function()
+ handle_char_input("" .. i)
+ end,
+ }
+ end
+
+ return bindings
+end
+
+local function text_input(info)
+ if info.key_text and (info.event == "press" or info.event == "down" or info.event == "repeat") then
+ handle_char_input(info.key_text)
+ end
+end
+
+function define_key_bindings()
+ if #key_bindings > 0 then
+ return
+ end
+ for _, bind in ipairs(get_bindings()) do
+ -- Generate arbitrary name for removing the bindings later.
+ local name = "_console_" .. (#key_bindings + 1)
+ key_bindings[#key_bindings + 1] = name
+ mp.add_forced_key_binding(bind[1], name, bind[2], { repeatable = true })
+ end
+ mp.add_forced_key_binding("any_unicode", "_console_text", text_input, { repeatable = true, complex = true })
+ key_bindings[#key_bindings + 1] = "_console_text"
+end
+
+function undefine_key_bindings()
+ for _, name in ipairs(key_bindings) do
+ mp.remove_key_binding(name)
+ end
+ key_bindings = {}
+end
+
+-- Add a global binding for enabling the REPL. While it's enabled, its bindings
+-- will take over and it can be closed with ESC.
+mp.add_key_binding(nil, "enable", function()
+ set_active(true)
+end)
+
+-- Add a script-message to show the REPL and fill it with the provided text
+mp.register_script_message("type", function(text, cursor_pos)
+ show_and_type(text, cursor_pos)
+end)
+
+-- Redraw the REPL when the OSD size changes. This is needed because the
+-- PlayRes of the OSD will need to be adjusted.
+mp.observe_property("osd-width", "native", update)
+mp.observe_property("osd-height", "native", update)
+mp.observe_property("display-hidpi-scale", "native", update)
+
+-- Enable log messages. In silent mode, mpv will queue log messages in a buffer
+-- until enable_messages is called again without the silent: prefix.
+mp.enable_messages("silent:terminal-default")
+
+collectgarbage()
+
+return {
+ set_active = set_active,
+ is_repl_active = function()
+ return repl_active
+ end,
+ set_enter_handler = function(callback)
+ enter_handler = callback
+ end,
+}
diff --git a/mac/.config/mpv/script-modules/mpvSockets.lua b/mac/.config/mpv/script-modules/mpvSockets.lua
new file mode 100644
index 0000000..d745540
--- /dev/null
+++ b/mac/.config/mpv/script-modules/mpvSockets.lua
@@ -0,0 +1,36 @@
+-- mpvSockets, one socket per instance, removes socket on exit
+
+local utils = require("mp.utils")
+
+local function get_temp_path()
+ local directory_seperator = package.config:match("([^\n]*)\n?")
+ local example_temp_file_path = os.tmpname()
+
+ -- remove generated temp file
+ pcall(os.remove, example_temp_file_path)
+
+ local seperator_idx = example_temp_file_path:reverse():find(directory_seperator)
+ local temp_path_length = #example_temp_file_path - seperator_idx
+
+ return example_temp_file_path:sub(1, temp_path_length)
+end
+
+tempDir = get_temp_path()
+
+function join_paths(...)
+ local arg = { ... }
+ path = ""
+ for i, v in ipairs(arg) do
+ path = utils.join_path(path, tostring(v))
+ end
+ return path
+end
+
+ppid = utils.getpid()
+os.execute("mkdir " .. join_paths(tempDir, "mpvSockets") .. " 2>/dev/null")
+mp.set_property("options/input-ipc-server", join_paths(tempDir, "mpvSockets", ppid))
+
+function shutdown_handler()
+ os.remove(join_paths(tempDir, "mpvSockets", ppid))
+end
+mp.register_event("shutdown", shutdown_handler)
diff --git a/mac/.config/mpv/script-modules/scroll-list.lua b/mac/.config/mpv/script-modules/scroll-list.lua
new file mode 100644
index 0000000..5d8f9fa
--- /dev/null
+++ b/mac/.config/mpv/script-modules/scroll-list.lua
@@ -0,0 +1,293 @@
+local mp = require 'mp'
+local scroll_list = {
+ global_style = [[]],
+ header_style = [[{\q2\fs35\c&00ccff&}]],
+ list_style = [[{\q2\fs25\c&Hffffff&}]],
+ wrapper_style = [[{\c&00ccff&\fs16}]],
+ cursor_style = [[{\c&00ccff&}]],
+ selected_style = [[{\c&Hfce788&}]],
+
+ cursor = [[➤\h]],
+ indent = [[\h\h\h\h]],
+
+ num_entries = 16,
+ wrap = false,
+ empty_text = "no entries"
+}
+
+--formats strings for ass handling
+--this function is based on a similar function from https://github.com/mpv-player/mpv/blob/master/player/lua/console.lua#L110
+function scroll_list.ass_escape(str, replace_newline)
+ if replace_newline == true then replace_newline = "\\\239\187\191n" end
+
+ --escape the invalid single characters
+ str = str:gsub('[\\{}\n]', {
+ -- 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
+ ['\\'] = '\\\239\187\191',
+ ['{'] = '\\{',
+ ['}'] = '\\}',
+ -- Precede newlines with a ZWNBSP to prevent ASS's weird collapsing of
+ -- consecutive newlines
+ ['\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')
+
+ if replace_newline then
+ str = str:gsub("\\N", replace_newline)
+ end
+ return str
+end
+
+--format and return the header string
+function scroll_list:format_header_string(str)
+ return str
+end
+
+--appends the entered text to the overlay
+function scroll_list:append(text)
+ if text == nil then return end
+ self.ass.data = self.ass.data .. text
+ end
+
+--appends a newline character to the osd
+function scroll_list:newline()
+ self.ass.data = self.ass.data .. '\\N'
+end
+
+--re-parses the list into an ass string
+--if the list is closed then it flags an update on the next open
+function scroll_list:update()
+ if self.hidden then self.flag_update = true
+ else self:update_ass() end
+end
+
+--prints the header to the overlay
+function scroll_list:format_header()
+ self:append(self.header_style)
+ self:append(self:format_header_string(self.header))
+ self:newline()
+end
+
+--formats each line of the list and prints it to the overlay
+function scroll_list:format_line(index, item)
+ self:append(self.list_style)
+
+ if index == self.selected then self:append(self.cursor_style..self.cursor..self.selected_style)
+ else self:append(self.indent) end
+
+ self:append(item.style)
+ self:append(item.ass)
+ self:newline()
+end
+
+--refreshes the ass text using the contents of the list
+function scroll_list:update_ass()
+ self.ass.data = self.global_style
+ self:format_header()
+
+ if #self.list < 1 then
+ self:append(self.empty_text)
+ self.ass:update()
+ return
+ end
+
+ local start = 1
+ local finish = start+self.num_entries-1
+
+ --handling cursor positioning
+ local mid = math.ceil(self.num_entries/2)+1
+ if self.selected+mid > finish then
+ local offset = self.selected - finish + mid
+
+ --if we've overshot the end of the list then undo some of the offset
+ if finish + offset > #self.list then
+ offset = offset - ((finish+offset) - #self.list)
+ end
+
+ start = start + offset
+ finish = finish + offset
+ end
+
+ --making sure that we don't overstep the boundaries
+ if start < 1 then start = 1 end
+ local overflow = finish < #self.list
+ --this is necessary when the number of items in the dir is less than the max
+ if not overflow then finish = #self.list end
+
+ --adding a header to show there are items above in the list
+ if start > 1 then self:append(self.wrapper_style..(start-1)..' item(s) above\\N\\N') end
+
+ for i=start, finish do
+ self:format_line(i, self.list[i])
+ end
+
+ if overflow then self:append('\\N'..self.wrapper_style..#self.list-finish..' item(s) remaining') end
+ self.ass:update()
+end
+
+--moves the selector down the list
+function scroll_list:scroll_down()
+ if self.selected < #self.list then
+ self.selected = self.selected + 1
+ self:update_ass()
+ elseif self.wrap then
+ self.selected = 1
+ self:update_ass()
+ end
+end
+
+--moves the selector up the list
+function scroll_list:scroll_up()
+ if self.selected > 1 then
+ self.selected = self.selected - 1
+ self:update_ass()
+ elseif self.wrap then
+ self.selected = #self.list
+ self:update_ass()
+ end
+end
+
+--moves the selector to the list next page
+function scroll_list:move_pagedown()
+ if #self.list > self.num_entries then
+ self.selected = self.selected + self.num_entries
+ if self.selected > #self.list then self.selected = #self.list end
+ self:update_ass()
+ end
+end
+
+--moves the selector to the list previous page
+function scroll_list:move_pageup()
+ if #self.list > self.num_entries then
+ self.selected = self.selected - self.num_entries
+ if self.selected < 1 then self.selected = 1 end
+ self:update_ass()
+ end
+end
+
+--moves the selector to the list begin
+function scroll_list:move_begin()
+ if #self.list > 1 then
+ self.selected = 1
+ self:update_ass()
+ end
+end
+
+--moves the selector to the list end
+function scroll_list:move_end()
+ if #self.list > 1 then
+ self.selected = #self.list
+ self:update_ass()
+ end
+end
+
+--adds the forced keybinds
+function scroll_list:add_keybinds()
+ for _,v in ipairs(self.keybinds) do
+ mp.add_forced_key_binding(v[1], 'dynamic/'..self.ass.id..'/'..v[2], v[3], v[4])
+ end
+end
+
+--removes the forced keybinds
+function scroll_list:remove_keybinds()
+ for _,v in ipairs(self.keybinds) do
+ mp.remove_key_binding('dynamic/'..self.ass.id..'/'..v[2])
+ end
+end
+
+--opens the list and sets the hidden flag
+function scroll_list:open_list()
+ self.hidden = false
+ if not self.flag_update then self.ass:update()
+ else self.flag_update = false ; self:update_ass() end
+end
+
+--closes the list and sets the hidden flag
+function scroll_list:close_list()
+ self.hidden = true
+ self.ass:remove()
+end
+
+--modifiable function that opens the list
+function scroll_list:open()
+ if self.hidden then self:add_keybinds() end
+ self:open_list()
+end
+
+--modifiable function that closes the list
+function scroll_list:close()
+ self:remove_keybinds()
+ self:close_list()
+end
+
+--toggles the list
+function scroll_list:toggle()
+ if self.hidden then self:open()
+ else self:close() end
+end
+
+--clears the list in-place
+function scroll_list:clear()
+ local i = 1
+ while self.list[i] do
+ self.list[i] = nil
+ i = i + 1
+ end
+end
+
+--added alias for ipairs(list.list) for lua 5.1
+function scroll_list:ipairs()
+ return ipairs(self.list)
+end
+
+--append item to the end of the list
+function scroll_list:insert(item)
+ self.list[#self.list + 1] = item
+end
+
+local metatable = {
+ __index = function(t, key)
+ if scroll_list[key] ~= nil then return scroll_list[key]
+ elseif key == "__current" then return t.list[t.selected]
+ elseif type(key) == "number" then return t.list[key] end
+ end,
+ __newindex = function(t, key, value)
+ if type(key) == "number" then rawset(t.list, key, value)
+ else rawset(t, key, value) end
+ end,
+ __scroll_list = scroll_list,
+ __len = function(t) return #t.list end,
+ __ipairs = function(t) return ipairs(t.list) end
+}
+
+--creates a new list object
+function scroll_list:new()
+ local vars
+ vars = {
+ ass = mp.create_osd_overlay('ass-events'),
+ hidden = true,
+ flag_update = true,
+
+ header = "header \\N ----------------------------------------------",
+ list = {},
+ selected = 1,
+
+ keybinds = {
+ {'DOWN', 'scroll_down', function() vars:scroll_down() end, {repeatable = true}},
+ {'UP', 'scroll_up', function() vars:scroll_up() end, {repeatable = true}},
+ {'PGDWN', 'move_pagedown', function() vars:move_pagedown() end, {}},
+ {'PGUP', 'move_pageup', function() vars:move_pageup() end, {}},
+ {'HOME', 'move_begin', function() vars:move_begin() end, {}},
+ {'END', 'move_end', function() vars:move_end() end, {}},
+ {'ESC', 'close_browser', function() vars:close() end, {}}
+ }
+ }
+ return setmetatable(vars, metatable)
+end
+
+return scroll_list:new()
diff --git a/mac/.config/mpv/script-modules/sha1.lua b/mac/.config/mpv/script-modules/sha1.lua
new file mode 100644
index 0000000..6b19396
--- /dev/null
+++ b/mac/.config/mpv/script-modules/sha1.lua
@@ -0,0 +1,334 @@
+-- $Revision: 1.5 $
+-- $Date: 2014-09-10 16:54:25 $
+
+-- This module was originally taken from http://cube3d.de/uploads/Main/sha1.txt.
+
+-------------------------------------------------------------------------------
+-- SHA-1 secure hash computation, and HMAC-SHA1 signature computation,
+-- in pure Lua (tested on Lua 5.1)
+-- License: MIT
+--
+-- Usage:
+-- local hashAsHex = sha1.hex(message) -- returns a hex string
+-- local hashAsData = sha1.bin(message) -- returns raw bytes
+--
+-- local hmacAsHex = sha1.hmacHex(key, message) -- hex string
+-- local hmacAsData = sha1.hmacBin(key, message) -- raw bytes
+--
+--
+-- Pass sha1.hex() a string, and it returns a hash as a 40-character hex string.
+-- For example, the call
+--
+-- local hash = sha1.hex("iNTERFACEWARE")
+--
+-- puts the 40-character string
+--
+-- "e76705ffb88a291a0d2f9710a5471936791b4819"
+--
+-- into the variable 'hash'
+--
+-- Pass sha1.hmacHex() a key and a message, and it returns the signature as a
+-- 40-byte hex string.
+--
+--
+-- The two "bin" versions do the same, but return the 20-byte string of raw
+-- data that the 40-byte hex strings represent.
+--
+-------------------------------------------------------------------------------
+--
+-- Description
+-- Due to the lack of bitwise operations in 5.1, this version uses numbers to
+-- represents the 32bit words that we combine with binary operations. The basic
+-- operations of byte based "xor", "or", "and" are all cached in a combination
+-- table (several 64k large tables are built on startup, which
+-- consumes some memory and time). The caching can be switched off through
+-- setting the local cfg_caching variable to false.
+-- For all binary operations, the 32 bit numbers are split into 8 bit values
+-- that are combined and then merged again.
+--
+-- Algorithm: http://www.itl.nist.gov/fipspubs/fip180-1.htm
+--
+-------------------------------------------------------------------------------
+
+sha1 = {}
+
+-- set this to false if you don't want to build several 64k sized tables when
+-- loading this file (takes a while but grants a boost of factor 13)
+local cfg_caching = false
+
+-- local storing of global functions (minor speedup)
+local floor, modf = math.floor, math.modf
+local char, format, rep = string.char, string.format, string.rep
+
+-- merge 4 bytes to an 32 bit word
+local function bytes_to_w32(a, b, c, d) return a * 0x1000000 + b * 0x10000 + c * 0x100 + d end
+
+-- split a 32 bit word into four 8 bit numbers
+local function w32_to_bytes(i)
+ return floor(i / 0x1000000) % 0x100, floor(i / 0x10000) % 0x100, floor(i / 0x100) % 0x100, i % 0x100
+end
+
+-- shift the bits of a 32 bit word. Don't use negative values for "bits"
+local function w32_rot(bits, a)
+ local b2 = 2 ^ (32 - bits)
+ local a, b = modf(a / b2)
+ return a + b * b2 * (2 ^ (bits))
+end
+
+-- caching function for functions that accept 2 arguments, both of values between
+-- 0 and 255. The function to be cached is passed, all values are calculated
+-- during loading and a function is returned that returns the cached values (only)
+local function cache2arg(fn)
+ if not cfg_caching then return fn end
+ local lut = {}
+ for i = 0, 0xffff do
+ local a, b = floor(i / 0x100), i % 0x100
+ lut[i] = fn(a, b)
+ end
+ return function(a, b)
+ return lut[a * 0x100 + b]
+ end
+end
+
+-- splits an 8-bit number into 8 bits, returning all 8 bits as booleans
+local function byte_to_bits(b)
+ local b = function(n)
+ local b = floor(b / n)
+ return b % 2 == 1
+ end
+ return b(1), b(2), b(4), b(8), b(16), b(32), b(64), b(128)
+end
+
+-- builds an 8bit number from 8 booleans
+local function bits_to_byte(a, b, c, d, e, f, g, h)
+ local function n(b, x) return b and x or 0 end
+
+ return n(a, 1) + n(b, 2) + n(c, 4) + n(d, 8) + n(e, 16) + n(f, 32) + n(g, 64) + n(h, 128)
+end
+
+-- debug function for visualizing bits in a string
+local function bits_to_string(a, b, c, d, e, f, g, h)
+ local function x(b) return b and "1" or "0" end
+
+ return ("%s%s%s%s %s%s%s%s"):format(x(a), x(b), x(c), x(d), x(e), x(f), x(g), x(h))
+end
+
+-- debug function for converting a 8-bit number as bit string
+local function byte_to_bit_string(b)
+ return bits_to_string(byte_to_bits(b))
+end
+
+-- debug function for converting a 32 bit number as bit string
+local function w32_to_bit_string(a)
+ if type(a) == "string" then return a end
+ local aa, ab, ac, ad = w32_to_bytes(a)
+ local s = byte_to_bit_string
+ return ("%s %s %s %s"):format(s(aa):reverse(), s(ab):reverse(), s(ac):reverse(), s(ad):reverse()):reverse()
+end
+
+-- bitwise "and" function for 2 8bit number
+local band = cache2arg(function(a, b)
+ local A, B, C, D, E, F, G, H = byte_to_bits(b)
+ local a, b, c, d, e, f, g, h = byte_to_bits(a)
+ return bits_to_byte(
+ A and a, B and b, C and c, D and d,
+ E and e, F and f, G and g, H and h)
+end)
+
+-- bitwise "or" function for 2 8bit numbers
+local bor = cache2arg(function(a, b)
+ local A, B, C, D, E, F, G, H = byte_to_bits(b)
+ local a, b, c, d, e, f, g, h = byte_to_bits(a)
+ return bits_to_byte(
+ A or a, B or b, C or c, D or d,
+ E or e, F or f, G or g, H or h)
+end)
+
+-- bitwise "xor" function for 2 8bit numbers
+local bxor = cache2arg(function(a, b)
+ local A, B, C, D, E, F, G, H = byte_to_bits(b)
+ local a, b, c, d, e, f, g, h = byte_to_bits(a)
+ return bits_to_byte(
+ A ~= a, B ~= b, C ~= c, D ~= d,
+ E ~= e, F ~= f, G ~= g, H ~= h)
+end)
+
+-- bitwise complement for one 8bit number
+local function bnot(x)
+ return 255 - (x % 256)
+end
+
+-- creates a function to combine to 32bit numbers using an 8bit combination function
+local function w32_comb(fn)
+ return function(a, b)
+ local aa, ab, ac, ad = w32_to_bytes(a)
+ local ba, bb, bc, bd = w32_to_bytes(b)
+ return bytes_to_w32(fn(aa, ba), fn(ab, bb), fn(ac, bc), fn(ad, bd))
+ end
+end
+
+-- create functions for and, xor and or, all for 2 32bit numbers
+local w32_and = w32_comb(band)
+local w32_xor = w32_comb(bxor)
+local w32_or = w32_comb(bor)
+
+-- xor function that may receive a variable number of arguments
+local function w32_xor_n(a, ...)
+ local aa, ab, ac, ad = w32_to_bytes(a)
+ for i = 1, select('#', ...) do
+ local ba, bb, bc, bd = w32_to_bytes(select(i, ...))
+ aa, ab, ac, ad = bxor(aa, ba), bxor(ab, bb), bxor(ac, bc), bxor(ad, bd)
+ end
+ return bytes_to_w32(aa, ab, ac, ad)
+end
+
+-- combining 3 32bit numbers through binary "or" operation
+local function w32_or3(a, b, c)
+ local aa, ab, ac, ad = w32_to_bytes(a)
+ local ba, bb, bc, bd = w32_to_bytes(b)
+ local ca, cb, cc, cd = w32_to_bytes(c)
+ return bytes_to_w32(
+ bor(aa, bor(ba, ca)), bor(ab, bor(bb, cb)), bor(ac, bor(bc, cc)), bor(ad, bor(bd, cd))
+ )
+end
+
+-- binary complement for 32bit numbers
+local function w32_not(a)
+ return 4294967295 - (a % 4294967296)
+end
+
+-- adding 2 32bit numbers, cutting off the remainder on 33th bit
+local function w32_add(a, b) return (a + b) % 4294967296 end
+
+-- adding n 32bit numbers, cutting off the remainder (again)
+local function w32_add_n(a, ...)
+ for i = 1, select('#', ...) do
+ a = (a + select(i, ...)) % 4294967296
+ end
+ return a
+end
+
+-- converting the number to a hexadecimal string
+local function w32_to_hexstring(w) return format("%08x", w) end
+
+-- calculating the SHA1 for some text
+function sha1.hex(msg)
+ local H0, H1, H2, H3, H4 = 0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0
+ local msg_len_in_bits = #msg * 8
+
+ local first_append = char(0x80) -- append a '1' bit plus seven '0' bits
+
+ local non_zero_message_bytes = #msg + 1 + 8 -- the +1 is the appended bit 1, the +8 are for the final appended length
+ local current_mod = non_zero_message_bytes % 64
+ local second_append = current_mod > 0 and rep(char(0), 64 - current_mod) or ""
+
+ -- now to append the length as a 64-bit number.
+ local B1, R1 = modf(msg_len_in_bits / 0x01000000)
+ local B2, R2 = modf(0x01000000 * R1 / 0x00010000)
+ local B3, R3 = modf(0x00010000 * R2 / 0x00000100)
+ local B4 = 0x00000100 * R3
+
+ local L64 = char(0) .. char(0) .. char(0) .. char(0) -- high 32 bits
+ .. char(B1) .. char(B2) .. char(B3) .. char(B4) -- low 32 bits
+
+ msg = msg .. first_append .. second_append .. L64
+
+ assert(#msg % 64 == 0)
+
+ local chunks = #msg / 64
+
+ local W = {}
+ local start, A, B, C, D, E, f, K, TEMP
+ local chunk = 0
+
+ while chunk < chunks do
+ --
+ -- break chunk up into W[0] through W[15]
+ --
+ start, chunk = chunk * 64 + 1, chunk + 1
+
+ for t = 0, 15 do
+ W[t] = bytes_to_w32(msg:byte(start, start + 3))
+ start = start + 4
+ end
+
+ --
+ -- build W[16] through W[79]
+ --
+ for t = 16, 79 do
+ -- For t = 16 to 79 let Wt = S1(Wt-3 XOR Wt-8 XOR Wt-14 XOR Wt-16).
+ W[t] = w32_rot(1, w32_xor_n(W[t - 3], W[t - 8], W[t - 14], W[t - 16]))
+ end
+
+ A, B, C, D, E = H0, H1, H2, H3, H4
+
+ for t = 0, 79 do
+ if t <= 19 then
+ -- (B AND C) OR ((NOT B) AND D)
+ f = w32_or(w32_and(B, C), w32_and(w32_not(B), D))
+ K = 0x5A827999
+ elseif t <= 39 then
+ -- B XOR C XOR D
+ f = w32_xor_n(B, C, D)
+ K = 0x6ED9EBA1
+ elseif t <= 59 then
+ -- (B AND C) OR (B AND D) OR (C AND D
+ f = w32_or3(w32_and(B, C), w32_and(B, D), w32_and(C, D))
+ K = 0x8F1BBCDC
+ else
+ -- B XOR C XOR D
+ f = w32_xor_n(B, C, D)
+ K = 0xCA62C1D6
+ end
+
+ -- TEMP = S5(A) + ft(B,C,D) + E + Wt + Kt;
+ A, B, C, D, E = w32_add_n(w32_rot(5, A), f, E, W[t], K),
+ A, w32_rot(30, B), C, D
+ end
+ -- Let H0 = H0 + A, H1 = H1 + B, H2 = H2 + C, H3 = H3 + D, H4 = H4 + E.
+ H0, H1, H2, H3, H4 = w32_add(H0, A), w32_add(H1, B), w32_add(H2, C), w32_add(H3, D), w32_add(H4, E)
+ end
+ local f = w32_to_hexstring
+ return f(H0) .. f(H1) .. f(H2) .. f(H3) .. f(H4)
+end
+
+local function hex_to_binary(hex)
+ return hex:gsub('..', function(hexval)
+ return string.char(tonumber(hexval, 16))
+ end)
+end
+
+function sha1.bin(msg)
+ return hex_to_binary(sha1.hex(msg))
+end
+
+local xor_with_0x5c = {}
+local xor_with_0x36 = {}
+-- building the lookuptables ahead of time (instead of littering the source code
+-- with precalculated values)
+for i = 0, 0xff do
+ xor_with_0x5c[char(i)] = char(bxor(i, 0x5c))
+ xor_with_0x36[char(i)] = char(bxor(i, 0x36))
+end
+
+local blocksize = 64 -- 512 bits
+
+function sha1.hmacHex(key, text)
+ assert(type(key) == 'string', "key passed to hmacHex should be a string")
+ assert(type(text) == 'string', "text passed to hmacHex should be a string")
+
+ if #key > blocksize then
+ key = sha1.bin(key)
+ end
+
+ local key_xord_with_0x36 = key:gsub('.', xor_with_0x36) .. string.rep(string.char(0x36), blocksize - #key)
+ local key_xord_with_0x5c = key:gsub('.', xor_with_0x5c) .. string.rep(string.char(0x5c), blocksize - #key)
+
+ return sha1.hex(key_xord_with_0x5c .. sha1.bin(key_xord_with_0x36 .. text))
+end
+
+function sha1.hmacBin(key, text)
+ return hex_to_binary(sha1.hmacHex(key, text))
+end
+
+return sha1
diff --git a/mac/.config/mpv/script-modules/user-input-module.lua b/mac/.config/mpv/script-modules/user-input-module.lua
new file mode 100644
index 0000000..f15d5c4
--- /dev/null
+++ b/mac/.config/mpv/script-modules/user-input-module.lua
@@ -0,0 +1,126 @@
+--[[
+ This is a module designed to interface with mpv-user-input
+ https://github.com/CogentRedTester/mpv-user-input
+
+ Loading this script as a module will return a table with two functions to format
+ requests to get and cancel user-input requests. See the README for details.
+
+ Alternatively, developers can just paste these functions directly into their script,
+ however this is not recommended as there is no guarantee that the formatting of
+ these requests will remain the same for future versions of user-input.
+]]
+
+local API_VERSION = "0.1.0"
+
+local mp = require 'mp'
+local msg = require "mp.msg"
+local utils = require 'mp.utils'
+local mod = {}
+
+local name = mp.get_script_name()
+local counter = 1
+
+local function pack(...)
+ local t = {...}
+ t.n = select("#", ...)
+ return t
+end
+
+local request_mt = {}
+
+-- ensures the option tables are correctly formatted based on the input
+local function format_options(options, response_string)
+ return {
+ response = response_string,
+ version = API_VERSION,
+ id = name..'/'..(options.id or ""),
+ source = name,
+ request_text = ("[%s] %s"):format(options.source or name, options.request_text or options.text or "requesting user input:"),
+ default_input = options.default_input,
+ cursor_pos = tonumber(options.cursor_pos),
+ queueable = options.queueable and true,
+ replace = options.replace and true
+ }
+end
+
+-- cancels the request
+function request_mt:cancel()
+ assert(self.uid, "request object missing UID")
+ mp.commandv("script-message-to", "user_input", "cancel-user-input/uid", self.uid)
+end
+
+-- updates the options for the request
+function request_mt:update(options)
+ assert(self.uid, "request object missing UID")
+ options = utils.format_json( format_options(options) )
+ mp.commandv("script-message-to", "user_input", "update-user-input/uid", self.uid, options)
+end
+
+-- sends a request to ask the user for input using formatted options provided
+-- creates a script message to recieve the response and call fn
+function mod.get_user_input(fn, options, ...)
+ options = options or {}
+ local response_string = name.."/__user_input_request/"..counter
+ counter = counter + 1
+
+ local request = {
+ uid = response_string,
+ passthrough_args = pack(...),
+ callback = fn,
+ pending = true
+ }
+
+ -- create a callback for user-input to respond to
+ mp.register_script_message(response_string, function(response)
+ mp.unregister_script_message(response_string)
+ request.pending = false
+
+ response = utils.parse_json(response)
+ request.callback(response.line, response.err, unpack(request.passthrough_args, 1, request.passthrough_args.n))
+ end)
+
+ -- send the input command
+ options = utils.format_json( format_options(options, response_string) )
+ mp.commandv("script-message-to", "user_input", "request-user-input", options)
+
+ return setmetatable(request, { __index = request_mt })
+end
+
+-- runs the request synchronously using coroutines
+-- takes the option table and an optional coroutine resume function
+function mod.get_user_input_co(options, co_resume)
+ local co, main = coroutine.running()
+ assert(not main and co, "get_user_input_co must be run from within a coroutine")
+
+ local uid = {}
+ local request = mod.get_user_input(function(line, err)
+ if co_resume then
+ co_resume(uid, line, err)
+ else
+ local success, er = coroutine.resume(co, uid, line, err)
+ if not success then
+ msg.warn(debug.traceback(co))
+ msg.error(er)
+ end
+ end
+ end, options)
+
+ -- if the uid was not sent then the coroutine was resumed by the user.
+ -- we will treat this as a cancellation request
+ local success, line, err = coroutine.yield(request)
+ if success ~= uid then
+ request:cancel()
+ request.callback = function() end
+ return nil, "cancelled"
+ end
+
+ return line, err
+end
+
+-- sends a request to cancel all input requests with the given id
+function mod.cancel_user_input(id)
+ id = name .. '/' .. (id or "")
+ mp.commandv("script-message-to", "user_input", "cancel-user-input/id", id)
+end
+
+return mod \ No newline at end of file
diff --git a/mac/.config/mpv/script-modules/utf8/LICENSE b/mac/.config/mpv/script-modules/utf8/LICENSE
new file mode 100644
index 0000000..fd3b301
--- /dev/null
+++ b/mac/.config/mpv/script-modules/utf8/LICENSE
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) 2016 Stepets
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/mac/.config/mpv/script-modules/utf8/README.md b/mac/.config/mpv/script-modules/utf8/README.md
new file mode 100644
index 0000000..0c31574
--- /dev/null
+++ b/mac/.config/mpv/script-modules/utf8/README.md
@@ -0,0 +1,93 @@
+# utf8.lua
+pure-lua 5.3 regex library for Lua 5.3, Lua 5.1, LuaJIT
+
+This library provides simple way to add UTF-8 support into your application.
+
+#### Example:
+```Lua
+local utf8 = require('.utf8'):init()
+for k,v in pairs(utf8) do
+ string[k] = v
+end
+
+local str = "пыщпыщ ололоо я водитель нло"
+print(str:find("(.л.+)н"))
+-- 8 26 ололоо я водитель
+
+print(str:gsub("ло+", "보라"))
+-- пыщпыщ о보라보라 я водитель н보라 3
+
+print(str:match("^п[лопыщ ]*я"))
+-- пыщпыщ ололоо я
+```
+
+#### Usage:
+
+This library can be used as drop-in replacement for vanilla string library. It exports all vanilla functions under `raw` sub-object.
+
+```Lua
+local utf8 = require('.utf8'):init()
+local str = "пыщпыщ ололоо я водитель нло"
+utf8.gsub(str, "ло+", "보라")
+-- пыщпыщ о보라보라 я водитель н보라 3
+utf8.raw.gsub(str, "ло+", "보라")
+-- пыщпыщ о보라보라о я водитель н보라 3
+```
+
+It also provides all functions from Lua 5.3 UTF-8 [module](https://www.lua.org/manual/5.3/manual.html#6.5) except `utf8.len (s [, i [, j]])`. If you need to validate your strings use `utf8.validate(str, byte_pos)` or iterate over with `utf8.validator`.
+
+Please note that library assumes regexes are valid UTF-8 strings, if you need to manipulate individual bytes use vanilla functions under `utf8.raw`.
+
+
+#### Installation:
+
+Download repository to your project folder. (no rockspecs yet)
+
+Examples assume library placed under `utf8` subfolder not `utf8.lua`.
+
+As of Lua 5.3 default `utf8` module has precedence over user-provided. In this case you can specify full module path (`.utf8`).
+
+#### Configuration:
+
+Library is highly modular. You can provide your implementation for almost any function used. Library already has several back-ends:
+- [Runtime character class processing](charclass/runtime/init.lua) using hardcoded codepoint ranges or using native functions through `ffi`.
+- [Basic functions](primitives/init.lua) for working with UTF-8 characters have specializations for `ffi`-enabled runtime and for tarantool.
+
+Probably most interesting [customizations](init.lua) are `utf8.config.loadstring` and `utf8.config.cache` if you want to precompile your regexes.
+
+```Lua
+local utf8 = require('.utf8')
+utf8.config = {
+ cache = my_smart_cache,
+}
+utf8:init()
+```
+
+For `lower` and `upper` functions to work in environments where `ffi` cannot be used, you can specify substitution tables ([data example](https://github.com/artemshein/luv/blob/master/utf8data.lua))
+
+```Lua
+local utf8 = require('.utf8')
+utf8.config = {
+ conversion = {
+ uc_lc = utf8_uc_lc,
+ lc_uc = utf8_lc_uc
+ },
+}
+utf8:init()
+```
+Customization is done before initialization. If you want, you can change configuration after `init`, it might work for everything but modules. All of them should be reloaded.
+
+#### [Documentation:](test/test.lua)
+
+#### Issue reporting:
+
+Please provide example script that causes error together with environment description and debug output. Debug output can be obtained like:
+```Lua
+local utf8 = require('.utf8')
+utf8.config = {
+ debug = utf8:require("util").debug
+}
+utf8:init()
+-- your code
+```
+Default logger used is [`io.write`](https://www.lua.org/manual/5.3/manual.html#pdf-io.write) and can be changed by specifying `logger = my_logger` in configuration
diff --git a/mac/.config/mpv/script-modules/utf8/begins/compiletime/parser.lua b/mac/.config/mpv/script-modules/utf8/begins/compiletime/parser.lua
new file mode 100644
index 0000000..c54c0df
--- /dev/null
+++ b/mac/.config/mpv/script-modules/utf8/begins/compiletime/parser.lua
@@ -0,0 +1,17 @@
+return function(utf8)
+
+utf8.config.begins = utf8.config.begins or {
+ utf8:require "begins.compiletime.vanilla"
+}
+
+function utf8.regex.compiletime.begins.parse(regex, c, bs, ctx)
+ for _, m in ipairs(utf8.config.begins) do
+ local functions, move = m.parse(regex, c, bs, ctx)
+ utf8.debug("begins", _, c, bs, move, functions)
+ if functions then
+ return functions, move
+ end
+ end
+end
+
+end
diff --git a/mac/.config/mpv/script-modules/utf8/begins/compiletime/vanilla.lua b/mac/.config/mpv/script-modules/utf8/begins/compiletime/vanilla.lua
new file mode 100644
index 0000000..bcafa17
--- /dev/null
+++ b/mac/.config/mpv/script-modules/utf8/begins/compiletime/vanilla.lua
@@ -0,0 +1,60 @@
+return function(utf8)
+
+local matchers = {
+ sliding = function()
+ return [[
+ add(function(ctx) -- sliding
+ while ctx.pos <= ctx.len do
+ local clone = ctx:clone()
+ -- debug('starting from', clone, "start_pos", clone.pos)
+ clone.result.start = clone.pos
+ clone:next_function()
+ clone:get_function()(clone)
+
+ ctx:next_char()
+ end
+ ctx:terminate()
+ end)
+]]
+ end,
+ fromstart = function(ctx)
+ return [[
+ add(function(ctx) -- fromstart
+ if ctx.byte_pos > ctx.len then
+ return
+ end
+ ctx.result.start = ctx.pos
+ ctx:next_function()
+ ctx:get_function()(ctx)
+ ctx:terminate()
+ end)
+]]
+ end,
+}
+
+local function default()
+ return matchers.sliding()
+end
+
+local function parse(regex, c, bs, ctx)
+ if bs ~= 1 then return end
+
+ local functions
+ local skip = 0
+
+ if c == '^' then
+ functions = matchers.fromstart()
+ skip = 1
+ else
+ functions = matchers.sliding()
+ end
+
+ return functions, skip
+end
+
+return {
+ parse = parse,
+ default = default,
+}
+
+end
diff --git a/mac/.config/mpv/script-modules/utf8/charclass/compiletime/builder.lua b/mac/.config/mpv/script-modules/utf8/charclass/compiletime/builder.lua
new file mode 100644
index 0000000..9d9c603
--- /dev/null
+++ b/mac/.config/mpv/script-modules/utf8/charclass/compiletime/builder.lua
@@ -0,0 +1,128 @@
+return function(utf8)
+
+local byte = utf8.byte
+local unpack = utf8.config.unpack
+
+local builder = {}
+local mt = {__index = builder}
+
+utf8.regex.compiletime.charclass.builder = builder
+
+function builder.new()
+ return setmetatable({}, mt)
+end
+
+function builder:invert()
+ self.inverted = true
+ return self
+end
+
+function builder:internal() -- is it enclosed in []
+ self.internal = true
+ return self
+end
+
+function builder:with_codes(...)
+ local codes = {...}
+ self.codes = self.codes or {}
+
+ for _, v in ipairs(codes) do
+ table.insert(self.codes, type(v) == "number" and v or byte(v))
+ end
+
+ table.sort(self.codes)
+ return self
+end
+
+function builder:with_ranges(...)
+ local ranges = {...}
+ self.ranges = self.ranges or {}
+
+ for _, v in ipairs(ranges) do
+ table.insert(self.ranges, v)
+ end
+
+ return self
+end
+
+function builder:with_classes(...)
+ local classes = {...}
+ self.classes = self.classes or {}
+
+ for _, v in ipairs(classes) do
+ table.insert(self.classes, v)
+ end
+
+ return self
+end
+
+function builder:without_classes(...)
+ local not_classes = {...}
+ self.not_classes = self.not_classes or {}
+
+ for _, v in ipairs(not_classes) do
+ table.insert(self.not_classes, v)
+ end
+
+ return self
+end
+
+function builder:include(b)
+ if not b.inverted then
+ if b.codes then
+ self:with_codes(unpack(b.codes))
+ end
+ if b.ranges then
+ self:with_ranges(unpack(b.ranges))
+ end
+ if b.classes then
+ self:with_classes(unpack(b.classes))
+ end
+ if b.not_classes then
+ self:without_classes(unpack(b.not_classes))
+ end
+ else
+ self.includes = self.includes or {}
+ self.includes[#self.includes + 1] = b
+ end
+ return self
+end
+
+function builder:build()
+ if self.codes and #self.codes == 1 and not self.inverted and not self.ranges and not self.classes and not self.not_classes and not self.includes then
+ return "{test = function(self, cc) return cc == " .. self.codes[1] .. " end}"
+ else
+ local codes_list = table.concat(self.codes or {}, ', ')
+ local ranges_list = ''
+ for i, r in ipairs(self.ranges or {}) do ranges_list = ranges_list .. (i > 1 and ', {' or '{') .. tostring(r[1]) .. ', ' .. tostring(r[2]) .. '}' end
+ local classes_list = ''
+ if self.classes then classes_list = "'" .. table.concat(self.classes, "', '") .. "'" end
+ local not_classes_list = ''
+ if self.not_classes then not_classes_list = "'" .. table.concat(self.not_classes, "', '") .. "'" end
+
+ local subs_list = ''
+ for i, r in ipairs(self.includes or {}) do subs_list = subs_list .. (i > 1 and ', ' or '') .. r:build() .. '' end
+
+ local src = [[cl.new():with_codes(
+ ]] .. codes_list .. [[
+ ):with_ranges(
+ ]] .. ranges_list .. [[
+ ):with_classes(
+ ]] .. classes_list .. [[
+ ):without_classes(
+ ]] .. not_classes_list .. [[
+ ):with_subs(
+ ]] .. subs_list .. [[
+ )]]
+
+ if self.inverted then
+ src = src .. ':invert()'
+ end
+
+ return src
+ end
+end
+
+return builder
+
+end
diff --git a/mac/.config/mpv/script-modules/utf8/charclass/compiletime/parser.lua b/mac/.config/mpv/script-modules/utf8/charclass/compiletime/parser.lua
new file mode 100644
index 0000000..4f1d4a9
--- /dev/null
+++ b/mac/.config/mpv/script-modules/utf8/charclass/compiletime/parser.lua
@@ -0,0 +1,21 @@
+return function(utf8)
+
+utf8.config.compiletime_charclasses = utf8.config.compiletime_charclasses or {
+ utf8:require "charclass.compiletime.vanilla",
+ utf8:require "charclass.compiletime.range",
+ utf8:require "charclass.compiletime.stub",
+}
+
+function utf8.regex.compiletime.charclass.parse(regex, c, bs, ctx)
+ utf8.debug("parse charclass():", regex, c, bs, regex[bs])
+ for _, p in ipairs(utf8.config.compiletime_charclasses) do
+ local charclass, nbs = p(regex, c, bs, ctx)
+ if charclass then
+ ctx.prev_class = charclass:build()
+ utf8.debug("cc", ctx.prev_class, _, c, bs, nbs)
+ return charclass, nbs
+ end
+ end
+end
+
+end
diff --git a/mac/.config/mpv/script-modules/utf8/charclass/compiletime/range.lua b/mac/.config/mpv/script-modules/utf8/charclass/compiletime/range.lua
new file mode 100644
index 0000000..2996234
--- /dev/null
+++ b/mac/.config/mpv/script-modules/utf8/charclass/compiletime/range.lua
@@ -0,0 +1,44 @@
+return function(utf8)
+
+local cl = utf8.regex.compiletime.charclass.builder
+
+local next = utf8.util.next
+
+return function(str, c, bs, ctx)
+ if not ctx.internal then return end
+
+ local nbs = bs
+
+ local r1, r2
+
+ local c, nbs = c, bs
+ if c == '%' then
+ c, nbs = next(str, nbs)
+ r1 = c
+ else
+ r1 = c
+ end
+
+ utf8.debug("range r1", r1, nbs)
+
+ c, nbs = next(str, nbs)
+ if c ~= '-' then return end
+
+ c, nbs = next(str, nbs)
+ if c == '%' then
+ c, nbs = next(str, nbs)
+ r2 = c
+ elseif c ~= '' and c ~= ']' then
+ r2 = c
+ end
+
+ utf8.debug("range r2", r2, nbs)
+
+ if r1 and r2 then
+ return cl.new():with_ranges{utf8.byte(r1), utf8.byte(r2)}, utf8.next(str, nbs) - bs
+ else
+ return
+ end
+end
+
+end
diff --git a/mac/.config/mpv/script-modules/utf8/charclass/compiletime/stub.lua b/mac/.config/mpv/script-modules/utf8/charclass/compiletime/stub.lua
new file mode 100644
index 0000000..395d05c
--- /dev/null
+++ b/mac/.config/mpv/script-modules/utf8/charclass/compiletime/stub.lua
@@ -0,0 +1,9 @@
+return function(utf8)
+
+local cl = utf8.regex.compiletime.charclass.builder
+
+return function(str, c, bs, ctx)
+ return cl.new():with_codes(c), utf8.next(str, bs) - bs
+end
+
+end
diff --git a/mac/.config/mpv/script-modules/utf8/charclass/compiletime/vanilla.lua b/mac/.config/mpv/script-modules/utf8/charclass/compiletime/vanilla.lua
new file mode 100644
index 0000000..8e7f0b3
--- /dev/null
+++ b/mac/.config/mpv/script-modules/utf8/charclass/compiletime/vanilla.lua
@@ -0,0 +1,131 @@
+return function(utf8)
+
+local cl = utf8:require "charclass.compiletime.builder"
+
+local next = utf8.util.next
+
+local token = 1
+
+local function parse(str, c, bs, ctx)
+ local tttt = token
+ token = token + 1
+
+ local class
+ local nbs = bs
+ utf8.debug("cc_parse", tttt, str, c, nbs, next(str, nbs))
+
+ if c == '%' then
+ c, nbs = next(str, bs)
+ if c == '' then
+ error("malformed pattern (ends with '%')")
+ end
+ local _c = utf8.raw.lower(c)
+ local matched
+ if _c == 'a' then
+ matched = ('alpha')
+ elseif _c == 'c' then
+ matched = ('cntrl')
+ elseif _c == 'd' then
+ matched = ('digit')
+ elseif _c == 'g' then
+ matched = ('graph')
+ elseif _c == 'l' then
+ matched = ('lower')
+ elseif _c == 'p' then
+ matched = ('punct')
+ elseif _c == 's' then
+ matched = ('space')
+ elseif _c == 'u' then
+ matched = ('upper')
+ elseif _c == 'w' then
+ matched = ('alnum')
+ elseif _c == 'x' then
+ matched = ('xdigit')
+ end
+
+ if matched then
+ if _c ~= c then
+ class = cl.new():without_classes(matched)
+ else
+ class = cl.new():with_classes(matched)
+ end
+ elseif _c == 'z' then
+ class = cl.new():with_codes(0)
+ if _c ~= c then
+ class = class:invert()
+ end
+ else
+ class = cl.new():with_codes(c)
+ end
+ elseif c == '[' and not ctx.internal then
+ local old_internal = ctx.internal
+ ctx.internal = true
+ class = cl.new()
+ local firstletter = true
+ while true do
+ local prev_nbs = nbs
+ c, nbs = next(str, nbs)
+ utf8.debug("next", tttt, c, nbs)
+ if c == '^' and firstletter then
+ class:invert()
+ local nc, nnbs = next(str, nbs)
+ if nc == ']' then
+ class:with_codes(nc)
+ nbs = nnbs
+ end
+ elseif c == ']' then
+ if firstletter then
+ class:with_codes(c)
+ else
+ utf8.debug('] on pos', tttt, nbs)
+ break
+ end
+ elseif c == '' then
+ error "malformed pattern (missing ']')"
+ else
+ local sub_class, skip = utf8.regex.compiletime.charclass.parse(str, c, nbs, ctx)
+ nbs = prev_nbs + skip
+ utf8.debug("include", tttt, bs, prev_nbs, nbs, skip)
+ class:include(sub_class)
+ end
+ firstletter = false
+ end
+ ctx.internal = old_internal
+ elseif c == '.' then
+ if not ctx.internal then
+ class = cl.new():invert()
+ else
+ class = cl.new():with_codes(c)
+ end
+ end
+
+ return class, utf8.next(str, nbs) - bs
+end
+
+return parse
+
+end
+
+--[[
+ x: (where x is not one of the magic characters ^$()%.[]*+-?) represents the character x itself.
+ .: (a dot) represents all characters.
+ %a: represents all letters.
+ %c: represents all control characters.
+ %d: represents all digits.
+ %g: represents all printable characters except space.
+ %l: represents all lowercase letters.
+ %p: represents all punctuation characters.
+ %s: represents all space characters.
+ %u: represents all uppercase letters.
+ %w: represents all alphanumeric characters.
+ %x: represents all hexadecimal digits.
+ %x: (where x is any non-alphanumeric character) represents the character x. This is the standard way to escape the magic characters. Any non-alphanumeric character (including all punctuation characters, even the non-magical) can be preceded by a '%' when used to represent itself in a pattern.
+ [set]: represents the class which is the union of all characters in set. A range of characters can be specified by separating the end characters of the range, in ascending order, with a '-'. All classes %x described above can also be used as components in set. All other characters in set represent themselves. For example, [%w_] (or [_%w]) represents all alphanumeric characters plus the underscore, [0-7] represents the octal digits, and [0-7%l%-] represents the octal digits plus the lowercase letters plus the '-' character.
+
+ You can put a closing square bracket in a set by positioning it as the first character in the set. You can put a hyphen in a set by positioning it as the first or the last character in the set. (You can also use an escape for both cases.)
+
+ The interaction between ranges and classes is not defined. Therefore, patterns like [%a-z] or [a-%%] have no meaning.
+ [^set]: represents the complement of set, where set is interpreted as above.
+
+For all classes represented by single letters (%a, %c, etc.), the corresponding uppercase letter represents the complement of the class. For instance, %S represents all non-space characters.
+]]
diff --git a/mac/.config/mpv/script-modules/utf8/charclass/runtime/base.lua b/mac/.config/mpv/script-modules/utf8/charclass/runtime/base.lua
new file mode 100644
index 0000000..33d7713
--- /dev/null
+++ b/mac/.config/mpv/script-modules/utf8/charclass/runtime/base.lua
@@ -0,0 +1,184 @@
+return function(utf8)
+
+local class = {}
+local mt = {__index = class}
+
+local utf8gensub = utf8.gensub
+
+function class.new()
+ return setmetatable({}, mt)
+end
+
+function class:invert()
+ self.inverted = true
+ return self
+end
+
+function class:with_codes(...)
+ local codes = {...}
+ self.codes = self.codes or {}
+
+ for _, v in ipairs(codes) do
+ table.insert(self.codes, v)
+ end
+
+ table.sort(self.codes)
+ return self
+end
+
+function class:with_ranges(...)
+ local ranges = {...}
+ self.ranges = self.ranges or {}
+
+ for _, v in ipairs(ranges) do
+ table.insert(self.ranges, v)
+ end
+
+ return self
+end
+
+function class:with_classes(...)
+ local classes = {...}
+ self.classes = self.classes or {}
+
+ for _, v in ipairs(classes) do
+ table.insert(self.classes, v)
+ end
+
+ return self
+end
+
+function class:without_classes(...)
+ local not_classes = {...}
+ self.not_classes = self.not_classes or {}
+
+ for _, v in ipairs(not_classes) do
+ table.insert(self.not_classes, v)
+ end
+
+ return self
+end
+
+function class:with_subs(...)
+ local subs = {...}
+ self.subs = self.subs or {}
+
+ for _, v in ipairs(subs) do
+ table.insert(self.subs, v)
+ end
+
+ return self
+end
+
+function class:in_codes(item)
+ if not self.codes or #self.codes == 0 then return nil end
+
+ local head, tail = 1, #self.codes
+ local mid = math.floor((head + tail)/2)
+ while (tail - head) > 1 do
+ if self.codes[mid] > item then
+ tail = mid
+ else
+ head = mid
+ end
+ mid = math.floor((head + tail)/2)
+ end
+ if self.codes[head] == item then
+ return true, head
+ elseif self.codes[tail] == item then
+ return true, tail
+ else
+ return false
+ end
+end
+
+function class:in_ranges(char_code)
+ if not self.ranges or #self.ranges == 0 then return nil end
+
+ for _,r in ipairs(self.ranges) do
+ if r[1] <= char_code and char_code <= r[2] then
+ return true
+ end
+ end
+ return false
+end
+
+function class:in_classes(char_code)
+ if not self.classes or #self.classes == 0 then return nil end
+
+ for _, class in ipairs(self.classes) do
+ if self:is(class, char_code) then
+ return true
+ end
+ end
+ return false
+end
+
+function class:in_not_classes(char_code)
+ if not self.not_classes or #self.not_classes == 0 then return nil end
+
+ for _, class in ipairs(self.not_classes) do
+ if self:is(class, char_code) then
+ return true
+ end
+ end
+ return false
+end
+
+function class:is(class, char_code)
+ error("not implemented")
+end
+
+function class:in_subs(char_code)
+ if not self.subs or #self.subs == 0 then return nil end
+
+ for _, c in ipairs(self.subs) do
+ if not c:test(char_code) then
+ return false
+ end
+ end
+ return true
+end
+
+function class:test(char_code)
+ local result = self:do_test(char_code)
+ -- utf8.debug('class:test', result, "'" .. (char_code and utf8.char(char_code) or 'nil') .. "'", char_code)
+ return result
+end
+
+function class:do_test(char_code)
+ if not char_code then return false end
+ local in_not_classes = self:in_not_classes(char_code)
+ if in_not_classes then
+ return not not self.inverted
+ end
+ local in_codes = self:in_codes(char_code)
+ if in_codes then
+ return not self.inverted
+ end
+ local in_ranges = self:in_ranges(char_code)
+ if in_ranges then
+ return not self.inverted
+ end
+ local in_classes = self:in_classes(char_code)
+ if in_classes then
+ return not self.inverted
+ end
+ local in_subs = self:in_subs(char_code)
+ if in_subs then
+ return not self.inverted
+ end
+ if (in_codes == nil)
+ and (in_ranges == nil)
+ and (in_classes == nil)
+ and (in_subs == nil)
+ and (in_not_classes == false) then
+ return not self.inverted
+ else
+ return not not self.inverted
+ end
+end
+
+return class
+
+end
diff --git a/mac/.config/mpv/script-modules/utf8/charclass/runtime/dummy.lua b/mac/.config/mpv/script-modules/utf8/charclass/runtime/dummy.lua
new file mode 100644
index 0000000..1faddc1
--- /dev/null
+++ b/mac/.config/mpv/script-modules/utf8/charclass/runtime/dummy.lua
@@ -0,0 +1,41 @@
+return function(utf8)
+
+local base = utf8:require "charclass.runtime.base"
+
+local dummy = setmetatable({}, {__index = base})
+local mt = {__index = dummy}
+
+function dummy.new()
+ return setmetatable({}, mt)
+end
+
+function dummy:with_classes(...)
+ local classes = {...}
+ for _, c in ipairs(classes) do
+ if c == 'alpha' then self:with_ranges({65, 90}, {97, 122})
+ elseif c == 'cntrl' then self:with_ranges({0, 31}):with_codes(127)
+ elseif c == 'digit' then self:with_ranges({48, 57})
+ elseif c == 'graph' then self:with_ranges({1, 8}, {14, 31}, {33, 132}, {134, 159}, {161, 5759}, {5761, 8191}, {8203, 8231}, {8234, 8238}, {8240, 8286}, {8288, 12287})
+ elseif c == 'lower' then self:with_ranges({97, 122})
+ elseif c == 'punct' then self:with_ranges({33, 47}, {58, 64}, {91, 96}, {123, 126})
+ elseif c == 'space' then self:with_ranges({9, 13}):with_codes(32, 133, 160, 5760):with_ranges({8192, 8202}):with_codes(8232, 8233, 8239, 8287, 12288)
+ elseif c == 'upper' then self:with_ranges({65, 90})
+ elseif c == 'alnum' then self:with_ranges({48, 57}, {65, 90}, {97, 122})
+ elseif c == 'xdigit' then self:with_ranges({48, 57}, {65, 70}, {97, 102})
+ end
+ end
+ return self
+end
+
+function dummy:without_classes(...)
+ local classes = {...}
+ if #classes > 0 then
+ return self:with_subs(dummy.new():with_classes(...):invert())
+ else
+ return self
+ end
+end
+
+return dummy
+
+end
diff --git a/mac/.config/mpv/script-modules/utf8/charclass/runtime/init.lua b/mac/.config/mpv/script-modules/utf8/charclass/runtime/init.lua
new file mode 100644
index 0000000..e71d037
--- /dev/null
+++ b/mac/.config/mpv/script-modules/utf8/charclass/runtime/init.lua
@@ -0,0 +1,22 @@
+return function(utf8)
+
+local provided = utf8.config.runtime_charclasses
+
+if provided then
+ if type(provided) == "table" then
+ return provided
+ elseif type(provided) == "function" then
+ return provided(utf8)
+ else
+ return utf8:require(provided)
+ end
+end
+
+local ffi = pcall(require, "ffi")
+if not ffi then
+ return utf8:require "charclass.runtime.dummy"
+else
+ return utf8:require "charclass.runtime.native"
+end
+
+end
diff --git a/mac/.config/mpv/script-modules/utf8/charclass/runtime/native.lua b/mac/.config/mpv/script-modules/utf8/charclass/runtime/native.lua
new file mode 100644
index 0000000..f7b7890
--- /dev/null
+++ b/mac/.config/mpv/script-modules/utf8/charclass/runtime/native.lua
@@ -0,0 +1,47 @@
+return function(utf8)
+
+os.setlocale(utf8.config.locale, "ctype")
+
+local ffi = require("ffi")
+ffi.cdef[[
+ int iswalnum(int c);
+ int iswalpha(int c);
+ int iswascii(int c);
+ int iswblank(int c);
+ int iswcntrl(int c);
+ int iswdigit(int c);
+ int iswgraph(int c);
+ int iswlower(int c);
+ int iswprint(int c);
+ int iswpunct(int c);
+ int iswspace(int c);
+ int iswupper(int c);
+ int iswxdigit(int c);
+]]
+
+local base = utf8:require "charclass.runtime.base"
+
+local native = setmetatable({}, {__index = base})
+local mt = {__index = native}
+
+function native.new()
+ return setmetatable({}, mt)
+end
+
+function native:is(class, char_code)
+ if class == 'alpha' then return ffi.C.iswalpha(char_code) ~= 0
+ elseif class == 'cntrl' then return ffi.C.iswcntrl(char_code) ~= 0
+ elseif class == 'digit' then return ffi.C.iswdigit(char_code) ~= 0
+ elseif class == 'graph' then return ffi.C.iswgraph(char_code) ~= 0
+ elseif class == 'lower' then return ffi.C.iswlower(char_code) ~= 0
+ elseif class == 'punct' then return ffi.C.iswpunct(char_code) ~= 0
+ elseif class == 'space' then return ffi.C.iswspace(char_code) ~= 0
+ elseif class == 'upper' then return ffi.C.iswupper(char_code) ~= 0
+ elseif class == 'alnum' then return ffi.C.iswalnum(char_code) ~= 0
+ elseif class == 'xdigit' then return ffi.C.iswxdigit(char_code) ~= 0
+ end
+end
+
+return native
+
+end
diff --git a/mac/.config/mpv/script-modules/utf8/context/compiletime.lua b/mac/.config/mpv/script-modules/utf8/context/compiletime.lua
new file mode 100644
index 0000000..621204d
--- /dev/null
+++ b/mac/.config/mpv/script-modules/utf8/context/compiletime.lua
@@ -0,0 +1,18 @@
+return function(utf8)
+
+local begins = utf8.config.begins
+local ends = utf8.config.ends
+
+return {
+ new = function()
+ return {
+ prev_class = nil,
+ begins = begins[1].default(),
+ ends = ends[1].default(),
+ funcs = {},
+ internal = false, -- hack for ranges, flags if parser is in []
+ }
+ end
+}
+
+end
diff --git a/mac/.config/mpv/script-modules/utf8/context/runtime.lua b/mac/.config/mpv/script-modules/utf8/context/runtime.lua
new file mode 100644
index 0000000..6fb024c
--- /dev/null
+++ b/mac/.config/mpv/script-modules/utf8/context/runtime.lua
@@ -0,0 +1,112 @@
+return function(utf8)
+
+local utf8unicode = utf8.unicode
+local utf8sub = utf8.sub
+local sub = utf8.raw.sub
+local byte = utf8.raw.byte
+local utf8len = utf8.len
+local utf8next = utf8.next
+local rawgsub = utf8.raw.gsub
+local utf8offset = utf8.offset
+local utf8char = utf8.char
+
+local util = utf8.util
+
+local ctx = {}
+local mt = {
+ __index = ctx,
+ __tostring = function(self)
+ return rawgsub([[str: '${str}', char: ${pos} '${char}', func: ${func_pos}]], "${(.-)}", {
+ str = self.str,
+ pos = self.pos,
+ char = self:get_char(),
+ func_pos = self.func_pos,
+ })
+ end
+}
+
+function ctx.new(obj)
+ obj = obj or {}
+ local res = setmetatable({
+ pos = obj.pos or 1,
+ byte_pos = obj.pos or 1,
+ str = assert(obj.str, "str is required"),
+ len = obj.len,
+ rawlen = obj.rawlen,
+ bytes = obj.bytes,
+ offsets = obj.offsets,
+ starts = obj.starts or nil,
+ functions = obj.functions or {},
+ func_pos = obj.func_pos or 1,
+ ends = obj.ends or nil,
+ result = obj.result and util.copy(obj.result) or {},
+ captures = obj.captures and util.copy(obj.captures, true) or {active = {}},
+ modified = false,
+ }, mt)
+ if not res.bytes then
+ local str = res.str
+ local l = #str
+ local bytes = utf8.config.int32array(l)
+ local offsets = utf8.config.int32array(l)
+ local c, bs, i = nil, 1, 1
+ while bs <= l do
+ bytes[i] = utf8unicode(str, bs, bs)
+ offsets[i] = bs
+ bs = utf8.next(str, bs)
+ i = i + 1
+ end
+ res.bytes = bytes
+ res.offsets = offsets
+ res.byte_pos = res.pos
+ res.len = i
+ res.rawlen = l
+ end
+
+ return res
+end
+
+function ctx:clone()
+ return self:new()
+end
+
+function ctx:next_char()
+ self.pos = self.pos + 1
+ self.byte_pos = self.pos
+end
+
+function ctx:prev_char()
+ self.pos = self.pos - 1
+ self.byte_pos = self.pos
+end
+
+function ctx:get_char()
+ if self.len <= self.pos then return "" end
+ return utf8char(self.bytes[self.pos])
+end
+
+function ctx:get_charcode()
+ if self.len <= self.pos then return nil end
+ return self.bytes[self.pos]
+end
+
+function ctx:next_function()
+ self.func_pos = self.func_pos + 1
+end
+
+function ctx:get_function()
+ return self.functions[self.func_pos]
+end
+
+function ctx:done()
+ utf8.debug('done', self)
+ coroutine.yield(self, self.result, self.captures)
+end
+
+function ctx:terminate()
+ utf8.debug('terminate', self)
+ coroutine.yield(nil)
+end
+
+return ctx
+
+end
diff --git a/mac/.config/mpv/script-modules/utf8/ends/compiletime/parser.lua b/mac/.config/mpv/script-modules/utf8/ends/compiletime/parser.lua
new file mode 100644
index 0000000..f966e94
--- /dev/null
+++ b/mac/.config/mpv/script-modules/utf8/ends/compiletime/parser.lua
@@ -0,0 +1,17 @@
+return function(utf8)
+
+utf8.config.ends = utf8.config.ends or {
+ utf8:require "ends.compiletime.vanilla"
+}
+
+function utf8.regex.compiletime.ends.parse(regex, c, bs, ctx)
+ for _, m in ipairs(utf8.config.ends) do
+ local functions, move = m.parse(regex, c, bs, ctx)
+ utf8.debug("ends", _, c, bs, move, functions)
+ if functions then
+ return functions, move
+ end
+ end
+end
+
+end
diff --git a/mac/.config/mpv/script-modules/utf8/ends/compiletime/vanilla.lua b/mac/.config/mpv/script-modules/utf8/ends/compiletime/vanilla.lua
new file mode 100644
index 0000000..5fe7eb3
--- /dev/null
+++ b/mac/.config/mpv/script-modules/utf8/ends/compiletime/vanilla.lua
@@ -0,0 +1,46 @@
+return function(utf8)
+
+local matchers = {
+ any = function()
+ return [[
+ add(function(ctx) -- any
+ ctx.result.finish = ctx.pos - 1
+ ctx:done()
+ end)
+]]
+ end,
+ toend = function(ctx)
+ return [[
+ add(function(ctx) -- toend
+ ctx.result.finish = ctx.pos - 1
+ ctx.modified = true
+ if ctx.pos == utf8len(ctx.str) + 1 then ctx:done() end
+ end)
+]]
+ end,
+}
+
+local len = utf8.raw.len
+
+local function default()
+ return matchers.any()
+end
+
+local function parse(regex, c, bs, ctx)
+ local functions
+ local skip = 0
+
+ if bs == len(regex) and c == '$' then
+ functions = matchers.toend()
+ skip = 1
+ end
+
+ return functions, skip
+end
+
+return {
+ parse = parse,
+ default = default,
+}
+
+end
diff --git a/mac/.config/mpv/script-modules/utf8/functions/lua53.lua b/mac/.config/mpv/script-modules/utf8/functions/lua53.lua
new file mode 100644
index 0000000..26e6f23
--- /dev/null
+++ b/mac/.config/mpv/script-modules/utf8/functions/lua53.lua
@@ -0,0 +1,152 @@
+return function(utf8)
+
+local utf8sub = utf8.sub
+local utf8gensub = utf8.gensub
+local unpack = utf8.config.unpack
+local generate_matcher_function = utf8:require 'regex_parser'
+
+local
+function get_matcher_function(regex, plain)
+ local res
+ if utf8.config.cache then
+ res = utf8.config.cache[plain and "plain" or "regex"][regex]
+ end
+ if res then
+ return res
+ end
+ res = generate_matcher_function(regex, plain)
+ if utf8.config.cache then
+ utf8.config.cache[plain and "plain" or "regex"][regex] = res
+ end
+ return res
+end
+
+local function utf8find(str, regex, init, plain)
+ local func = get_matcher_function(regex, plain)
+ init = ((init or 1) < 0) and (utf8.len(str) + init + 1) or init
+ local ctx, result, captures = func(str, init, utf8)
+ if not ctx then return nil end
+
+ utf8.debug('ctx:', ctx)
+ utf8.debug('result:', result)
+ utf8.debug('captures:', captures)
+
+ return result.start, result.finish, unpack(captures)
+end
+
+local function utf8match(str, regex, init)
+ local func = get_matcher_function(regex, false)
+ init = ((init or 1) < 0) and (utf8.len(str) + init + 1) or init
+ local ctx, result, captures = func(str, init, utf8)
+ if not ctx then return nil end
+
+ utf8.debug('ctx:', ctx)
+ utf8.debug('result:', result)
+ utf8.debug('captures:', captures)
+
+ if #captures > 0 then return unpack(captures) end
+
+ return utf8sub(str, result.start, result.finish)
+end
+
+local function utf8gmatch(str, regex)
+ regex = (utf8sub(regex,1,1) ~= '^') and regex or '%' .. regex
+ local func = get_matcher_function(regex, false)
+ local ctx, result, captures
+ local continue_pos = 1
+
+ return function()
+ ctx, result, captures = func(str, continue_pos, utf8)
+
+ if not ctx then return nil end
+
+ utf8.debug('ctx:', ctx)
+ utf8.debug('result:', result)
+ utf8.debug('captures:', captures)
+
+ continue_pos = math.max(result.finish + 1, result.start + 1)
+ if #captures > 0 then
+ return unpack(captures)
+ else
+ return utf8sub(str, result.start, result.finish)
+ end
+ end
+end
+
+local function replace(repl, args)
+ local ret = ''
+ if type(repl) == 'string' then
+ local ignore = false
+ local num
+ for _, c in utf8gensub(repl) do
+ if not ignore then
+ if c == '%' then
+ ignore = true
+ else
+ ret = ret .. c
+ end
+ else
+ num = tonumber(c)
+ if num then
+ ret = ret .. assert(args[num], "invalid capture index %" .. c)
+ else
+ ret = ret .. c
+ end
+ ignore = false
+ end
+ end
+ elseif type(repl) == 'table' then
+ ret = repl[args[1]] or args[0]
+ elseif type(repl) == 'function' then
+ ret = repl(unpack(args, 1)) or args[0]
+ end
+ return ret
+end
+
+local function utf8gsub(str, regex, repl, limit)
+ limit = limit or -1
+ local subbed = ''
+ local prev_sub_finish = 1
+
+ local func = get_matcher_function(regex, false)
+ local ctx, result, captures
+ local continue_pos = 1
+
+ local n = 0
+ while limit ~= n do
+ ctx, result, captures = func(str, continue_pos, utf8)
+ if not ctx then break end
+
+ utf8.debug('ctx:', ctx)
+ utf8.debug('result:', result)
+ utf8.debug('result:', utf8sub(str, result.start, result.finish))
+ utf8.debug('captures:', captures)
+
+ continue_pos = math.max(result.finish + 1, result.start + 1)
+ local args
+ if #captures > 0 then
+ args = {[0] = utf8sub(str, result.start, result.finish), unpack(captures)}
+ else
+ args = {[0] = utf8sub(str, result.start, result.finish)}
+ args[1] = args[0]
+ end
+
+ subbed = subbed .. utf8sub(str, prev_sub_finish, result.start - 1)
+ subbed = subbed .. replace(repl, args)
+ prev_sub_finish = result.finish + 1
+ n = n + 1
+
+ end
+
+ return subbed .. utf8sub(str, prev_sub_finish), n
+end
+
+-- attaching high-level functions
+utf8.find = utf8find
+utf8.match = utf8match
+utf8.gmatch = utf8gmatch
+utf8.gsub = utf8gsub
+
+return utf8
+
+end
diff --git a/mac/.config/mpv/script-modules/utf8/init.lua b/mac/.config/mpv/script-modules/utf8/init.lua
new file mode 100644
index 0000000..d2f72a4
--- /dev/null
+++ b/mac/.config/mpv/script-modules/utf8/init.lua
@@ -0,0 +1,71 @@
+local module_path = ...
+module_path = module_path:match("^(.-)init$") or (module_path .. '.')
+
+local ffi_enabled, ffi = pcall(require, 'ffi')
+
+local utf8 = {
+ config = {},
+ default = {
+ debug = nil,
+ logger = io.write,
+ loadstring = (loadstring or load),
+ unpack = (unpack or table.unpack),
+ cache = {
+ regex = setmetatable({},{
+ __mode = 'kv'
+ }),
+ plain = setmetatable({},{
+ __mode = 'kv'
+ }),
+ },
+ locale = nil,
+ int32array = function(size)
+ if ffi_enabled then
+ return ffi.new("uint32_t[?]", size + 1)
+ else
+ return {}
+ end
+ end,
+ conversion = {
+ uc_lc = nil,
+ lc_uc = nil
+ }
+ },
+ regex = {
+ compiletime = {
+ charclass = {},
+ begins = {},
+ ends = {},
+ modifier = {},
+ }
+ },
+ util = {},
+}
+
+function utf8:require(name)
+ local full_module_path = module_path .. name
+ if package.loaded[full_module_path] then
+ return package.loaded[full_module_path]
+ end
+
+ local mod = require(full_module_path)
+ if type(mod) == 'function' then
+ mod = mod(self)
+ package.loaded[full_module_path] = mod
+ end
+ return mod
+end
+
+function utf8:init()
+ for k, v in pairs(self.default) do
+ self.config[k] = self.config[k] or v
+ end
+
+ self:require "util"
+ self:require "primitives.init"
+ self:require "functions.lua53"
+
+ return self
+end
+
+return utf8
diff --git a/mac/.config/mpv/script-modules/utf8/modifier/compiletime/frontier.lua b/mac/.config/mpv/script-modules/utf8/modifier/compiletime/frontier.lua
new file mode 100644
index 0000000..cf0f4ab
--- /dev/null
+++ b/mac/.config/mpv/script-modules/utf8/modifier/compiletime/frontier.lua
@@ -0,0 +1,50 @@
+return function(utf8)
+
+local matchers = {
+ frontier = function(class, name)
+ local class_name = 'class' .. name
+ return [[
+ local ]] .. class_name .. [[ = ]] .. class .. [[
+
+ add(function(ctx) -- frontier
+ ctx:prev_char()
+ local prev_charcode = ctx:get_charcode() or 0
+ ctx:next_char()
+ local charcode = ctx:get_charcode() or 0
+ -- debug("frontier pos", ctx.pos, "prev_charcode", prev_charcode, "charcode", charcode)
+ if ]] .. class_name .. [[:test(prev_charcode) then return end
+ if ]] .. class_name .. [[:test(charcode) then
+ ctx:next_function()
+ return ctx:get_function()(ctx)
+ end
+ end)
+]]
+ end,
+ simple = utf8:require("modifier.compiletime.simple").simple,
+}
+
+local function parse(regex, c, bs, ctx)
+ local functions, nbs, class
+
+ if c == '%' then
+ if utf8.raw.sub(regex, bs + 1, bs + 1) ~= 'f' then return end
+ if utf8.raw.sub(regex, bs + 2, bs + 2) ~= '[' then error("missing '[' after '%f' in pattern") end
+
+ functions = {}
+ if ctx.prev_class then
+ table.insert(functions, matchers.simple(ctx.prev_class, tostring(bs)))
+ ctx.prev_class = nil
+ end
+ class, nbs = utf8.regex.compiletime.charclass.parse(regex, '[', bs + 2, ctx)
+ nbs = nbs + 2
+ table.insert(functions, matchers.frontier(class:build(), tostring(bs)))
+ end
+
+ return functions, nbs
+end
+
+return {
+ parse = parse,
+}
+
+end
diff --git a/mac/.config/mpv/script-modules/utf8/modifier/compiletime/parser.lua b/mac/.config/mpv/script-modules/utf8/modifier/compiletime/parser.lua
new file mode 100644
index 0000000..9149f71
--- /dev/null
+++ b/mac/.config/mpv/script-modules/utf8/modifier/compiletime/parser.lua
@@ -0,0 +1,20 @@
+return function(utf8)
+
+utf8.config.modifier = utf8.config.modifier or {
+ utf8:require "modifier.compiletime.vanilla",
+ utf8:require "modifier.compiletime.frontier",
+ utf8:require "modifier.compiletime.stub",
+}
+
+function utf8.regex.compiletime.modifier.parse(regex, c, bs, ctx)
+ for _, m in ipairs(utf8.config.modifier) do
+ local functions, move = m.parse(regex, c, bs, ctx)
+ utf8.debug("mod", _, c, bs, move, functions and utf8.config.unpack(functions))
+ if functions then
+ ctx.prev_class = nil
+ return functions, move
+ end
+ end
+end
+
+end
diff --git a/mac/.config/mpv/script-modules/utf8/modifier/compiletime/simple.lua b/mac/.config/mpv/script-modules/utf8/modifier/compiletime/simple.lua
new file mode 100644
index 0000000..1a28b85
--- /dev/null
+++ b/mac/.config/mpv/script-modules/utf8/modifier/compiletime/simple.lua
@@ -0,0 +1,23 @@
+return function(utf8)
+
+local matchers = {
+ simple = function(class, name)
+ local class_name = 'class' .. name
+ return [[
+ local ]] .. class_name .. [[ = ]] .. class .. [[
+
+ add(function(ctx) -- simple
+ -- debug(ctx, 'simple', ']] .. class_name .. [[')
+ if ]] .. class_name .. [[:test(ctx:get_charcode()) then
+ ctx:next_char()
+ ctx:next_function()
+ return ctx:get_function()(ctx)
+ end
+ end)
+]]
+ end,
+}
+
+return matchers
+
+end
diff --git a/mac/.config/mpv/script-modules/utf8/modifier/compiletime/stub.lua b/mac/.config/mpv/script-modules/utf8/modifier/compiletime/stub.lua
new file mode 100644
index 0000000..e1289a6
--- /dev/null
+++ b/mac/.config/mpv/script-modules/utf8/modifier/compiletime/stub.lua
@@ -0,0 +1,28 @@
+return function(utf8)
+
+local matchers = utf8:require("modifier.compiletime.simple")
+
+local function parse(regex, c, bs, ctx)
+ local functions
+
+ if ctx.prev_class then
+ functions = { matchers.simple(ctx.prev_class, tostring(bs)) }
+ ctx.prev_class = nil
+ end
+
+ return functions, 0
+end
+
+local function check(ctx)
+ if ctx.prev_class then
+ table.insert(ctx.funcs, matchers.simple(ctx.prev_class, tostring(ctx.pos)))
+ ctx.prev_class = nil
+ end
+end
+
+return {
+ parse = parse,
+ check = check,
+}
+
+end
diff --git a/mac/.config/mpv/script-modules/utf8/modifier/compiletime/vanilla.lua b/mac/.config/mpv/script-modules/utf8/modifier/compiletime/vanilla.lua
new file mode 100644
index 0000000..96e79d2
--- /dev/null
+++ b/mac/.config/mpv/script-modules/utf8/modifier/compiletime/vanilla.lua
@@ -0,0 +1,270 @@
+return function(utf8)
+
+local utf8unicode = utf8.byte
+local sub = utf8.raw.sub
+
+local matchers = {
+ star = function(class, name)
+ local class_name = 'class' .. name
+ return [[
+ local ]] .. class_name .. [[ = ]] .. class .. [[
+
+ add(function(ctx) -- star
+ -- debug(ctx, 'star', ']] .. class_name .. [[')
+ local clone = ctx:clone()
+ while ]] .. class_name .. [[:test(clone:get_charcode()) do
+ clone:next_char()
+ end
+ local pos = clone.pos
+ while pos >= ctx.pos do
+ clone.pos = pos
+ clone.func_pos = ctx.func_pos
+ clone:next_function()
+ clone:get_function()(clone)
+ if clone.modified then
+ clone = ctx:clone()
+ end
+ pos = pos - 1
+ end
+ end)
+]]
+ end,
+ minus = function(class, name)
+ local class_name = 'class' .. name
+ return [[
+ local ]] .. class_name .. [[ = ]] .. class .. [[
+
+ add(function(ctx) -- minus
+ -- debug(ctx, 'minus', ']] .. class_name .. [[')
+
+ local clone = ctx:clone()
+ local pos
+ repeat
+ pos = clone.pos
+ clone:next_function()
+ clone:get_function()(clone)
+ if clone.modified then
+ clone = ctx:clone()
+ clone.pos = pos
+ else
+ clone.pos = pos
+ clone.func_pos = ctx.func_pos
+ end
+ local match = ]] .. class_name .. [[:test(clone:get_charcode())
+ clone:next_char()
+ until not match
+ end)
+]]
+ end,
+ question = function(class, name)
+ local class_name = 'class' .. name
+ return [[
+ local ]] .. class_name .. [[ = ]] .. class .. [[
+
+ add(function(ctx) -- question
+ -- debug(ctx, 'question', ']] .. class_name .. [[')
+ local saved = ctx:clone()
+ if ]] .. class_name .. [[:test(ctx:get_charcode()) then
+ ctx:next_char()
+ ctx:next_function()
+ ctx:get_function()(ctx)
+ end
+ ctx = saved
+ ctx:next_function()
+ return ctx:get_function()(ctx)
+ end)
+]]
+ end,
+ capture_start = function(number)
+ return [[
+ add(function(ctx)
+ ctx.modified = true
+ -- debug(ctx, 'capture_start', ']] .. tostring(number) .. [[')
+ table.insert(ctx.captures.active, { id = ]] .. tostring(number) .. [[, start = ctx.pos })
+ ctx:next_function()
+ return ctx:get_function()(ctx)
+ end)
+]]
+ end,
+ capture_finish = function(number)
+ return [[
+ add(function(ctx)
+ ctx.modified = true
+ -- debug(ctx, 'capture_finish', ']] .. tostring(number) .. [[')
+ local cap = table.remove(ctx.captures.active)
+ cap.finish = ctx.pos
+ local b, e = ctx.offsets[cap.start], ctx.offsets[cap.finish]
+ if cap.start < 1 then
+ b = 1
+ elseif cap.start >= ctx.len then
+ b = ctx.rawlen + 1
+ end
+ if cap.finish < 1 then
+ e = 1
+ elseif cap.finish >= ctx.len then
+ e = ctx.rawlen + 1
+ end
+ ctx.captures[cap.id] = rawsub(ctx.str, b, e - 1)
+ -- debug('capture#' .. tostring(cap.id), '[' .. tostring(cap.start).. ',' .. tostring(cap.finish) .. ']' , 'is', ctx.captures[cap.id])
+ ctx:next_function()
+ return ctx:get_function()(ctx)
+ end)
+]]
+ end,
+ capture_position = function(number)
+ return [[
+ add(function(ctx)
+ ctx.modified = true
+ -- debug(ctx, 'capture_position', ']] .. tostring(number) .. [[')
+ ctx.captures[ ]] .. tostring(number) .. [[ ] = ctx.pos
+ ctx:next_function()
+ return ctx:get_function()(ctx)
+ end)
+]]
+ end,
+ capture = function(number)
+ return [[
+ add(function(ctx)
+ -- debug(ctx, 'capture', ']] .. tostring(number) .. [[')
+ local cap = ctx.captures[ ]] .. tostring(number) .. [[ ]
+ local len = utf8len(cap)
+ local check = utf8sub(ctx.str, ctx.pos, ctx.pos + len - 1)
+ -- debug("capture check:", cap, check)
+ if cap == check then
+ ctx.pos = ctx.pos + len
+ ctx:next_function()
+ return ctx:get_function()(ctx)
+ end
+ end)
+]]
+ end,
+ balancer = function(pair, name)
+ local class_name = 'class' .. name
+ return [[
+
+ add(function(ctx) -- balancer
+ local d, b = ]] .. tostring(utf8unicode(pair[1])) .. [[, ]] .. tostring(utf8unicode(pair[2])) .. [[
+ if ctx:get_charcode() ~= d then return end
+ local balance = 0
+ repeat
+ local c = ctx:get_charcode()
+ if c == nil then return end
+
+ if c == d then
+ balance = balance + 1
+ elseif c == b then
+ balance = balance - 1
+ end
+ -- debug("balancer: balance=", balance, ", d=", d, ", b=", b, ", charcode=", ctx:get_charcode())
+ ctx:next_char()
+ until balance == 0 or (balance == 2 and d == b)
+ ctx:next_function()
+ return ctx:get_function()(ctx)
+ end)
+]]
+ end,
+ simple = utf8:require("modifier.compiletime.simple").simple,
+}
+
+local next = utf8.util.next
+
+local function parse(regex, c, bs, ctx)
+ local functions, nbs = nil, bs
+ if c == '%' then
+ c, nbs = next(regex, bs)
+ utf8.debug("next", c, bs)
+ if c == '' then
+ error("malformed pattern (ends with '%')")
+ end
+ if utf8.raw.find('123456789', c, 1, true) then
+ functions = { matchers.capture(tonumber(c)) }
+ nbs = utf8.next(regex, nbs)
+ elseif c == 'b' then
+ local d, b
+ d, nbs = next(regex, nbs)
+ b, nbs = next(regex, nbs)
+ assert(d ~= '' and b ~= '', "unbalanced pattern")
+ functions = { matchers.balancer({d, b}, tostring(bs)) }
+ nbs = utf8.next(regex, nbs)
+ end
+
+ if functions and ctx.prev_class then
+ table.insert(functions, 1, matchers.simple(ctx.prev_class, tostring(bs)))
+ end
+ elseif c == '*' and ctx.prev_class then
+ functions = {
+ matchers.star(
+ ctx.prev_class,
+ tostring(bs)
+ )
+ }
+ nbs = bs + 1
+ elseif c == '+' and ctx.prev_class then
+ functions = {
+ matchers.simple(
+ ctx.prev_class,
+ tostring(bs)
+ ),
+ matchers.star(
+ ctx.prev_class,
+ tostring(bs)
+ )
+ }
+ nbs = bs + 1
+ elseif c == '-' and ctx.prev_class then
+ functions = {
+ matchers.minus(
+ ctx.prev_class,
+ tostring(bs)
+ )
+ }
+ nbs = bs + 1
+ elseif c == '?' and ctx.prev_class then
+ functions = {
+ matchers.question(
+ ctx.prev_class,
+ tostring(bs)
+ )
+ }
+ nbs = bs + 1
+ elseif c == '(' then
+ ctx.capture = ctx.capture or {balance = 0, id = 0}
+ ctx.capture.id = ctx.capture.id + 1
+ local nc = next(regex, nbs)
+ if nc == ')' then
+ functions = {matchers.capture_position(ctx.capture.id)}
+ nbs = bs + 2
+ else
+ ctx.capture.balance = ctx.capture.balance + 1
+ functions = {matchers.capture_start(ctx.capture.id)}
+ nbs = bs + 1
+ end
+ if ctx.prev_class then
+ table.insert(functions, 1, matchers.simple(ctx.prev_class, tostring(bs)))
+ end
+ elseif c == ')' then
+ ctx.capture = ctx.capture or {balance = 0, id = 0}
+ functions = { matchers.capture_finish(ctx.capture.id) }
+
+ ctx.capture.balance = ctx.capture.balance - 1
+ assert(ctx.capture.balance >= 0, 'invalid capture: "(" missing')
+
+ if ctx.prev_class then
+ table.insert(functions, 1, matchers.simple(ctx.prev_class, tostring(bs)))
+ end
+ nbs = bs + 1
+ end
+
+ return functions, nbs - bs
+end
+
+local function check(ctx)
+ if ctx.capture then assert(ctx.capture.balance == 0, 'invalid capture: ")" missing') end
+end
+
+return {
+ parse = parse,
+ check = check,
+}
+
+end
diff --git a/mac/.config/mpv/script-modules/utf8/primitives/dummy.lua b/mac/.config/mpv/script-modules/utf8/primitives/dummy.lua
new file mode 100644
index 0000000..a4665f5
--- /dev/null
+++ b/mac/.config/mpv/script-modules/utf8/primitives/dummy.lua
@@ -0,0 +1,555 @@
+-- $Id: utf8.lua 179 2009-04-03 18:10:03Z pasta $
+--
+-- Provides UTF-8 aware string functions implemented in pure lua:
+-- * utf8len(s)
+-- * utf8sub(s, i, j)
+-- * utf8reverse(s)
+-- * utf8char(unicode)
+-- * utf8unicode(s, i, j)
+-- * utf8gensub(s, sub_len)
+-- * utf8find(str, regex, init, plain)
+-- * utf8match(str, regex, init)
+-- * utf8gmatch(str, regex, all)
+-- * utf8gsub(str, regex, repl, limit)
+--
+-- All functions behave as their non UTF-8 aware counterparts with the exception
+-- that UTF-8 characters are used instead of bytes for all units.
+
+--[[
+Copyright (c) 2006-2007, Kyle Smith
+All rights reserved.
+
+Contributors:
+ Alimov Stepan
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of the author nor the names of its contributors may be
+ used to endorse or promote products derived from this software without
+ specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+--]]
+
+-- ABNF from RFC 3629
+--
+-- UTF8-octets = *( UTF8-char )
+-- UTF8-char = UTF8-1 / UTF8-2 / UTF8-3 / UTF8-4
+-- UTF8-1 = %x00-7F
+-- UTF8-2 = %xC2-DF UTF8-tail
+-- UTF8-3 = %xE0 %xA0-BF UTF8-tail / %xE1-EC 2( UTF8-tail ) /
+-- %xED %x80-9F UTF8-tail / %xEE-EF 2( UTF8-tail )
+-- UTF8-4 = %xF0 %x90-BF 2( UTF8-tail ) / %xF1-F3 3( UTF8-tail ) /
+-- %xF4 %x80-8F 2( UTF8-tail )
+-- UTF8-tail = %x80-BF
+--
+return function(utf8)
+
+local byte = string.byte
+local char = string.char
+local dump = string.dump
+local find = string.find
+local format = string.format
+local len = string.len
+local lower = string.lower
+local rep = string.rep
+local sub = string.sub
+local upper = string.upper
+
+local utf8charpattern = '[%z\1-\127\194-\244][\128-\191]*'
+
+local function utf8symbollen(byte)
+ return not byte and 0 or (byte < 0x80 and 1) or (byte >= 0xF0 and 4) or (byte >= 0xE0 and 3) or (byte >= 0xC0 and 2) or 1
+end
+
+local head_table = utf8.config.int32array(256)
+for i = 0, 255 do
+ head_table[i] = utf8symbollen(i)
+end
+head_table[256] = 0
+
+local function utf8charbytes(str, bs)
+ return head_table[byte(str, bs) or 256]
+end
+
+local function utf8next(str, bs)
+ return bs + utf8charbytes(str, bs)
+end
+
+-- returns the number of characters in a UTF-8 string
+local function utf8len (str)
+ local bs = 1
+ local bytes = len(str)
+ local length = 0
+
+ while bs <= bytes do
+ length = length + 1
+ bs = utf8next(str, bs)
+ end
+
+ return length
+end
+
+-- functions identically to string.sub except that i and j are UTF-8 characters
+-- instead of bytes
+local function utf8sub (s, i, j)
+ -- argument defaults
+ j = j or -1
+
+ local bs = 1
+ local bytes = len(s)
+ local length = 0
+
+ local l = (i >= 0 and j >= 0) or utf8len(s)
+ i = (i >= 0) and i or l + i + 1
+ j = (j >= 0) and j or l + j + 1
+
+ if i > j then
+ return ""
+ end
+
+ local start, finish = 1, bytes
+
+ while bs <= bytes do
+ length = length + 1
+
+ if length == i then
+ start = bs
+ end
+
+ bs = utf8next(s, bs)
+
+ if length == j then
+ finish = bs - 1
+ break
+ end
+ end
+
+ if i > length then start = bytes + 1 end
+ if j < 1 then finish = 0 end
+
+ return sub(s, start, finish)
+end
+
+-- http://en.wikipedia.org/wiki/Utf8
+-- http://developer.coronalabs.com/code/utf-8-conversion-utility
+local function utf8char(...)
+ local codes = {...}
+ local result = {}
+
+ for _, unicode in ipairs(codes) do
+
+ if unicode <= 0x7F then
+ result[#result + 1] = unicode
+ elseif unicode <= 0x7FF then
+ local b0 = 0xC0 + math.floor(unicode / 0x40);
+ local b1 = 0x80 + (unicode % 0x40);
+ result[#result + 1] = b0
+ result[#result + 1] = b1
+ elseif unicode <= 0xFFFF then
+ local b0 = 0xE0 + math.floor(unicode / 0x1000);
+ local b1 = 0x80 + (math.floor(unicode / 0x40) % 0x40);
+ local b2 = 0x80 + (unicode % 0x40);
+ result[#result + 1] = b0
+ result[#result + 1] = b1
+ result[#result + 1] = b2
+ elseif unicode <= 0x10FFFF then
+ local code = unicode
+ local b3= 0x80 + (code % 0x40);
+ code = math.floor(code / 0x40)
+ local b2= 0x80 + (code % 0x40);
+ code = math.floor(code / 0x40)
+ local b1= 0x80 + (code % 0x40);
+ code = math.floor(code / 0x40)
+ local b0= 0xF0 + code;
+
+ result[#result + 1] = b0
+ result[#result + 1] = b1
+ result[#result + 1] = b2
+ result[#result + 1] = b3
+ else
+ error 'Unicode cannot be greater than U+10FFFF!'
+ end
+
+ end
+
+ return char(utf8.config.unpack(result))
+end
+
+
+local shift_6 = 2^6
+local shift_12 = 2^12
+local shift_18 = 2^18
+
+local utf8unicode
+utf8unicode = function(str, ibs, jbs)
+ if ibs > jbs then return end
+
+ local ch,bytes
+
+ bytes = utf8charbytes(str, ibs)
+ if bytes == 0 then return end
+
+ local unicode
+
+ if bytes == 1 then unicode = byte(str, ibs, ibs) end
+ if bytes == 2 then
+ local byte0,byte1 = byte(str, ibs, ibs + 1)
+ if byte0 and byte1 then
+ local code0,code1 = byte0-0xC0,byte1-0x80
+ unicode = code0*shift_6 + code1
+ else
+ unicode = byte0
+ end
+ end
+ if bytes == 3 then
+ local byte0,byte1,byte2 = byte(str, ibs, ibs + 2)
+ if byte0 and byte1 and byte2 then
+ local code0,code1,code2 = byte0-0xE0,byte1-0x80,byte2-0x80
+ unicode = code0*shift_12 + code1*shift_6 + code2
+ else
+ unicode = byte0
+ end
+ end
+ if bytes == 4 then
+ local byte0,byte1,byte2,byte3 = byte(str, ibs, ibs + 3)
+ if byte0 and byte1 and byte2 and byte3 then
+ local code0,code1,code2,code3 = byte0-0xF0,byte1-0x80,byte2-0x80,byte3-0x80
+ unicode = code0*shift_18 + code1*shift_12 + code2*shift_6 + code3
+ else
+ unicode = byte0
+ end
+ end
+
+ if ibs == jbs then
+ return unicode
+ else
+ return unicode,utf8unicode(str, ibs+bytes, jbs)
+ end
+end
+
+local function utf8byte(str, i, j)
+ if #str == 0 then return end
+
+ local ibs, jbs
+
+ if i or j then
+ i = i or 1
+ j = j or i
+
+ local str_len = utf8len(str)
+ i = i < 0 and str_len + i + 1 or i
+ j = j < 0 and str_len + j + 1 or j
+ j = j > str_len and str_len or j
+
+ if i > j then return end
+
+ for p = 1, i - 1 do
+ ibs = utf8next(str, ibs or 1)
+ end
+
+ if i == j then
+ jbs = ibs
+ else
+ for p = 1, j - 1 do
+ jbs = utf8next(str, jbs or 1)
+ end
+ end
+
+ if not ibs or not jbs then
+ return nil
+ end
+ else
+ ibs, jbs = 1, 1
+ end
+
+ return utf8unicode(str, ibs, jbs)
+end
+
+local function utf8gensub(str, sub_len)
+ sub_len = sub_len or 1
+ local max_len = #str
+ return function(skip_ptr, bs)
+ bs = (bs and bs or 1) + (skip_ptr and (skip_ptr[1] or 0) or 0)
+
+ local nbs = bs
+ if bs > max_len then return nil end
+ for i = 1, sub_len do
+ nbs = utf8next(str, nbs)
+ end
+
+ return nbs, sub(str, bs, nbs - 1), bs
+ end
+end
+
+local function utf8reverse (s)
+ local result = ''
+ for _, w in utf8gensub(s) do result = w .. result end
+ return result
+end
+
+local function utf8validator(str, bs)
+ bs = bs or 1
+
+ if type(str) ~= "string" then
+ error("bad argument #1 to 'utf8charbytes' (string expected, got ".. type(str).. ")")
+ end
+ if type(bs) ~= "number" then
+ error("bad argument #2 to 'utf8charbytes' (number expected, got ".. type(bs).. ")")
+ end
+
+ local c = byte(str, bs)
+ if not c then return end
+
+ -- determine bytes needed for character, based on RFC 3629
+
+ -- UTF8-1
+ if c >= 0 and c <= 127 then
+ return bs + 1
+ elseif c >= 128 and c <= 193 then
+ return bs + 1, bs, 1, c
+ -- UTF8-2
+ elseif c >= 194 and c <= 223 then
+ local c2 = byte(str, bs + 1)
+ if not c2 or c2 < 128 or c2 > 191 then
+ return bs + 2, bs, 2, c2
+ end
+
+ return bs + 2
+ -- UTF8-3
+ elseif c >= 224 and c <= 239 then
+ local c2 = byte(str, bs + 1)
+
+ if not c2 then
+ return bs + 2, bs, 2, c2
+ end
+
+ -- validate byte 2
+ if c == 224 and (c2 < 160 or c2 > 191) then
+ return bs + 2, bs, 2, c2
+ elseif c == 237 and (c2 < 128 or c2 > 159) then
+ return bs + 2, bs, 2, c2
+ elseif c2 < 128 or c2 > 191 then
+ return bs + 2, bs, 2, c2
+ end
+
+ local c3 = byte(str, bs + 2)
+ if not c3 or c3 < 128 or c3 > 191 then
+ return bs + 3, bs, 3, c3
+ end
+
+ return bs + 3
+ -- UTF8-4
+ elseif c >= 240 and c <= 244 then
+ local c2 = byte(str, bs + 1)
+
+ if not c2 then
+ return bs + 2, bs, 2, c2
+ end
+
+ -- validate byte 2
+ if c == 240 and (c2 < 144 or c2 > 191) then
+ return bs + 2, bs, 2, c2
+ elseif c == 244 and (c2 < 128 or c2 > 143) then
+ return bs + 2, bs, 2, c2
+ elseif c2 < 128 or c2 > 191 then
+ return bs + 2, bs, 2, c2
+ end
+
+ local c3 = byte(str, bs + 2)
+ if not c3 or c3 < 128 or c3 > 191 then
+ return bs + 3, bs, 3, c3
+ end
+
+ local c4 = byte(str, bs + 3)
+ if not c4 or c4 < 128 or c4 > 191 then
+ return bs + 4, bs, 4, c4
+ end
+
+ return bs + 4
+ else -- c > 245
+ return bs + 1, bs, 1, c
+ end
+end
+
+local function utf8validate(str, byte_pos)
+ local result = {}
+ for nbs, bs, part, code in utf8validator, str, byte_pos do
+ if bs then
+ result[#result + 1] = { pos = bs, part = part, code = code }
+ end
+ end
+ return #result == 0, result
+end
+
+local function utf8codes(str)
+ local max_len = #str
+ local bs = 1
+ return function(skip_ptr)
+ if bs > max_len then return nil end
+ local pbs = bs
+ bs = utf8next(str, pbs)
+
+ return pbs, utf8unicode(str, pbs, pbs), pbs
+ end
+end
+
+
+--[[--
+differs from Lua 5.3 utf8.offset in accepting any byte positions (not only head byte) for all n values
+
+h - head, c - continuation, t - tail
+hhhccthccthccthcthhh
+ ^ start byte pos
+searching current charracter head by moving backwards
+hhhccthccthccthcthhh
+ ^ head
+
+n == 0: current position
+n > 0: n jumps forward
+n < 0: n more scans backwards
+--]]--
+local function utf8offset(str, n, bs)
+ local l = #str
+ if not bs then
+ if n < 0 then
+ bs = l + 1
+ else
+ bs = 1
+ end
+ end
+ if bs <= 0 or bs > l + 1 then
+ error("bad argument #3 to 'offset' (position out of range)")
+ end
+
+ if n == 0 then
+ if bs == l + 1 then
+ return bs
+ end
+ while true do
+ local b = byte(str, bs)
+ if (0 < b and b < 127)
+ or (194 < b and b < 244) then
+ return bs
+ end
+ bs = bs - 1
+ if bs < 1 then
+ return
+ end
+ end
+ elseif n < 0 then
+ bs = bs - 1
+ repeat
+ if bs < 1 then
+ return
+ end
+
+ local b = byte(str, bs)
+ if (0 < b and b < 127)
+ or (194 < b and b < 244) then
+ n = n + 1
+ end
+ bs = bs - 1
+ until n == 0
+ return bs + 1
+ else
+ while true do
+ if bs > l then
+ return
+ end
+
+ local b = byte(str, bs)
+ if (0 < b and b < 127)
+ or (194 < b and b < 244) then
+ n = n - 1
+ for i = 1, n do
+ if bs > l then
+ return
+ end
+ bs = utf8next(str, bs)
+ end
+ return bs
+ end
+ bs = bs - 1
+ end
+ end
+
+end
+
+local function utf8replace (s, mapping)
+ if type(s) ~= "string" then
+ error("bad argument #1 to 'utf8replace' (string expected, got ".. type(s).. ")")
+ end
+ if type(mapping) ~= "table" then
+ error("bad argument #2 to 'utf8replace' (table expected, got ".. type(mapping).. ")")
+ end
+ local result = utf8.raw.gsub( s, utf8charpattern, mapping )
+ return result
+end
+
+local function utf8upper (s)
+ return utf8replace(s, utf8.config.conversion.lc_uc)
+end
+
+if utf8.config.conversion.lc_uc then
+ upper = utf8upper
+end
+
+local function utf8lower (s)
+ return utf8replace(s, utf8.config.conversion.uc_lc)
+end
+
+if utf8.config.conversion.uc_lc then
+ lower = utf8lower
+end
+
+utf8.len = utf8len
+utf8.sub = utf8sub
+utf8.reverse = utf8reverse
+utf8.char = utf8char
+utf8.unicode = utf8unicode
+utf8.byte = utf8byte
+utf8.next = utf8next
+utf8.gensub = utf8gensub
+utf8.validator = utf8validator
+utf8.validate = utf8validate
+utf8.dump = dump
+utf8.format = format
+utf8.lower = lower
+utf8.upper = upper
+utf8.rep = rep
+utf8.raw = {}
+for k,v in pairs(string) do
+ utf8.raw[k] = v
+end
+
+utf8.charpattern = utf8charpattern
+utf8.offset = utf8offset
+if _VERSION == 'Lua 5.3' then
+ local utf8_53 = require "utf8"
+ utf8.codes = utf8_53.codes
+ utf8.codepoint = utf8_53.codepoint
+ utf8.len53 = utf8_53.len
+else
+ utf8.codes = utf8codes
+ utf8.codepoint = utf8unicode
+end
+
+return utf8
+
+end
diff --git a/mac/.config/mpv/script-modules/utf8/primitives/init.lua b/mac/.config/mpv/script-modules/utf8/primitives/init.lua
new file mode 100644
index 0000000..df28ef3
--- /dev/null
+++ b/mac/.config/mpv/script-modules/utf8/primitives/init.lua
@@ -0,0 +1,23 @@
+return function(utf8)
+
+local provided = utf8.config.primitives
+
+if provided then
+ if type(provided) == "table" then
+ return provided
+ elseif type(provided) == "function" then
+ return provided(utf8)
+ else
+ return utf8:require(provided)
+ end
+end
+
+if pcall(require, "tarantool") then
+ return utf8:require "primitives.tarantool"
+elseif pcall(require, "ffi") then
+ return utf8:require "primitives.native"
+else
+ return utf8:require "primitives.dummy"
+end
+
+end
diff --git a/mac/.config/mpv/script-modules/utf8/primitives/native.lua b/mac/.config/mpv/script-modules/utf8/primitives/native.lua
new file mode 100644
index 0000000..c9aca54
--- /dev/null
+++ b/mac/.config/mpv/script-modules/utf8/primitives/native.lua
@@ -0,0 +1,57 @@
+return function(utf8)
+
+local ffi = require("ffi")
+if ffi.os == "Windows" then
+ os.setlocale(utf8.config.locale or "english_us.65001", "ctype")
+ ffi.cdef[[
+ short towupper(short c);
+ short towlower(short c);
+ ]]
+else
+ os.setlocale(utf8.config.locale or "C.UTF-8", "ctype")
+ ffi.cdef[[
+ int towupper(int c);
+ int towlower(int c);
+ ]]
+end
+
+utf8:require "primitives.dummy"
+
+if not utf8.config.conversion.uc_lc then
+ function utf8.lower(str)
+ local bs = 1
+ local nbs
+ local bytes = utf8.raw.len(str)
+ local res = {}
+
+ while bs <= bytes do
+ nbs = utf8.next(str, bs)
+ local cp = utf8.unicode(str, bs, nbs)
+ res[#res + 1] = ffi.C.towlower(cp)
+ bs = nbs
+ end
+
+ return utf8.char(utf8.config.unpack(res))
+ end
+end
+
+if not utf8.config.conversion.lc_uc then
+ function utf8.upper(str)
+ local bs = 1
+ local nbs
+ local bytes = utf8.raw.len(str)
+ local res = {}
+
+ while bs <= bytes do
+ nbs = utf8.next(str, bs)
+ local cp = utf8.unicode(str, bs, nbs)
+ res[#res + 1] = ffi.C.towupper(cp)
+ bs = nbs
+ end
+
+ return utf8.char(utf8.config.unpack(res))
+ end
+end
+
+return utf8
+end
diff --git a/mac/.config/mpv/script-modules/utf8/primitives/tarantool.lua b/mac/.config/mpv/script-modules/utf8/primitives/tarantool.lua
new file mode 100644
index 0000000..c38acf6
--- /dev/null
+++ b/mac/.config/mpv/script-modules/utf8/primitives/tarantool.lua
@@ -0,0 +1,13 @@
+return function(utf8)
+
+utf8:require "primitives.dummy"
+
+local tnt_utf8 = utf8.config.tarantool_utf8 or require("utf8")
+
+utf8.lower = tnt_utf8.lower
+utf8.upper = tnt_utf8.upper
+utf8.len = tnt_utf8.len
+utf8.char = tnt_utf8.char
+
+return utf8
+end
diff --git a/mac/.config/mpv/script-modules/utf8/regex_parser.lua b/mac/.config/mpv/script-modules/utf8/regex_parser.lua
new file mode 100644
index 0000000..3190f1b
--- /dev/null
+++ b/mac/.config/mpv/script-modules/utf8/regex_parser.lua
@@ -0,0 +1,80 @@
+return function(utf8)
+
+utf8:require "modifier.compiletime.parser"
+utf8:require "charclass.compiletime.parser"
+utf8:require "begins.compiletime.parser"
+utf8:require "ends.compiletime.parser"
+
+local gensub = utf8.gensub
+local sub = utf8.sub
+
+local parser_context = utf8:require "context.compiletime"
+
+return function(regex, plain)
+ utf8.debug("regex", regex)
+ local ctx = parser_context:new()
+
+ local skip = {0}
+ for nbs, c, bs in gensub(regex, 0), skip do
+ repeat -- continue
+ skip[1] = 0
+
+ c = utf8.raw.sub(regex, bs, utf8.next(regex, bs) - 1)
+
+ local functions, move = utf8.regex.compiletime.begins.parse(regex, c, bs, ctx)
+ if functions then
+ ctx.begins = functions
+ skip[1] = move
+ end
+ if skip[1] ~= 0 then break end
+
+ local functions, move = utf8.regex.compiletime.ends.parse(regex, c, bs, ctx)
+ if functions then
+ ctx.ends = functions
+ skip[1] = move
+ end
+ if skip[1] ~= 0 then break end
+
+ local functions, move = utf8.regex.compiletime.modifier.parse(regex, c, bs, ctx)
+ if functions then
+ for _, f in ipairs(functions) do
+ ctx.funcs[#ctx.funcs + 1] = f
+ end
+ skip[1] = move
+ end
+ if skip[1] ~= 0 then break end
+
+ local charclass, move = utf8.regex.compiletime.charclass.parse(regex, c, bs, ctx)
+ if charclass then skip[1] = move end
+ until true -- continue
+ end
+
+ for _, m in ipairs(utf8.config.modifier) do
+ if m.check then m.check(ctx) end
+ end
+
+ local src = [[
+ return function(str, init, utf8)
+ local ctx = utf8:require("context.runtime").new({str = str, pos = init or 1})
+ local cl = utf8:require("charclass.runtime.init")
+ local utf8sub = utf8.sub
+ local rawsub = utf8.raw.sub
+ local utf8len = utf8.len
+ local utf8next = utf8.next
+ local debug = utf8.debug
+ local function add(fun)
+ ctx.functions[#ctx.functions + 1] = fun
+ end
+ ]] .. ctx.begins
+ for _, v in ipairs(ctx.funcs) do src = src .. v end
+ src = src .. ctx.ends .. [[
+ return coroutine.wrap(ctx:get_function())(ctx)
+ end
+ ]]
+
+ utf8.debug(regex, src)
+
+ return assert(utf8.config.loadstring(src, (plain and "plain " or "") .. regex))()
+end
+
+end
diff --git a/mac/.config/mpv/script-modules/utf8/test.sh b/mac/.config/mpv/script-modules/utf8/test.sh
new file mode 100755
index 0000000..b8d2d63
--- /dev/null
+++ b/mac/.config/mpv/script-modules/utf8/test.sh
@@ -0,0 +1,23 @@
+#!/bin/sh
+
+set -xe
+
+lua53=$(which lua5.3 || which true)
+lua51=$(which lua5.1 || which true)
+luajit=$(which luajit || which true)
+
+for test in \
+ test/charclass_compiletime.lua \
+ test/charclass_runtime.lua \
+ test/context_runtime.lua \
+ test/test.lua \
+ test/test_compat.lua \
+ test/test_pm.lua \
+ test/test_utf8data.lua
+do
+ $lua53 $test
+ $lua51 $test
+ $luajit $test
+done
+
+echo "tests passed"
diff --git a/mac/.config/mpv/script-modules/utf8/test/charclass_compiletime.lua b/mac/.config/mpv/script-modules/utf8/test/charclass_compiletime.lua
new file mode 100644
index 0000000..05d762d
--- /dev/null
+++ b/mac/.config/mpv/script-modules/utf8/test/charclass_compiletime.lua
@@ -0,0 +1,165 @@
+local utf8 = require "init"
+utf8.config = {
+ debug = nil,
+-- debug = utf8:require("util").debug,
+}
+utf8:init()
+
+local ctx = utf8:require("context.compiletime"):new()
+
+local equals = require 'test.util'.equals
+local assert = require 'test.util'.assert
+local assert_equals = require 'test.util'.assert_equals
+local parse = utf8.regex.compiletime.charclass.parse
+
+assert_equals({parse("aabb", "a", 1, ctx)}, {{codes = {utf8.byte("a")}}, 1})
+assert_equals({parse("aabb", "a", 2, ctx)}, {{codes = {utf8.byte("a")}}, 1})
+assert_equals({parse("aabb", "b", 3, ctx)}, {{codes = {utf8.byte("b")}}, 1})
+assert_equals({parse("aabb", "b", 4, ctx)}, {{codes = {utf8.byte("b")}}, 1})
+
+assert_equals({parse("aa%ab", "%", 3, ctx)}, {{classes = {'alpha'}}, 2})
+assert_equals({parse("aac%Ab", "%", 4, ctx)}, {{not_classes = {'alpha'}}, 2})
+assert_equals({parse("aa.b", ".", 3, ctx)}, {{inverted = true}, 1})
+
+assert_equals({parse("aa[c]b", "[", 3, ctx)}, {
+ {codes = {utf8.byte("c")}, ranges = nil, classes = nil, not_classes = nil},
+ utf8.raw.len("[c]")
+})
+
+assert_equals({parse("aa[%A]b", "[", 3, ctx)}, {
+ {codes = nil, ranges = nil, classes = nil, not_classes = {'alpha'}},
+ utf8.raw.len("[%A]")
+})
+
+assert_equals({parse("[^%p%d%s%c]+", "[", 1, ctx)}, {
+ {codes = nil, ranges = nil, classes = {'punct', 'digit', 'space', 'cntrl'}, not_classes = nil, inverted = true},
+ utf8.raw.len("[^%p%d%s%c]")
+})
+
+assert_equals({parse("aa[[c]]b", "[", 3, ctx)}, {
+ {codes = {utf8.byte("["), utf8.byte("c")}, ranges = nil, classes = nil, not_classes = nil},
+ utf8.raw.len("[[c]")
+})
+
+assert_equals({parse("aa[%a[c]]b", "[", 3, ctx)}, {
+ {codes = {utf8.byte("["), utf8.byte("c")}, ranges = nil, classes = {'alpha'}, not_classes = nil},
+ utf8.raw.len("[%a[c]")
+})
+
+assert_equals({parse("aac-db", "c", 3, ctx)}, {
+ {codes = {utf8.byte("c")}},
+ utf8.raw.len("c")
+})
+
+assert_equals({parse("aa[c-d]b", "[", 3, ctx)}, {
+ {codes = nil, ranges = {{utf8.byte("c"),utf8.byte("d")}}, classes = nil, not_classes = nil},
+ utf8.raw.len("[c-d]")
+})
+assert_equals(ctx.internal, false)
+
+assert_equals({parse("aa[c-]]b", "[", 3, ctx)}, {
+ {codes = {utf8.byte("-"), utf8.byte("c")}, ranges = nil, classes = nil, not_classes = nil},
+ utf8.raw.len("[c-]")
+})
+assert_equals(ctx.internal, false)
+
+assert_equals({parse("aad-", "d", 3, ctx)}, {
+ {codes = {utf8.byte("d")}},
+ utf8.raw.len("d")
+})
+assert_equals(ctx.internal, false)
+
+ctx.internal = false
+assert_equals({parse(".", ".", 1, ctx)}, {
+ {inverted = true},
+ utf8.raw.len(".")
+})
+
+assert_equals({parse("[.]", "[", 1, ctx)}, {
+ {codes = {utf8.byte(".")}},
+ utf8.raw.len("[.]")
+})
+
+assert_equals({parse("%?", "%", 1, ctx)}, {
+ {codes = {utf8.byte("?")}},
+ utf8.raw.len("%?")
+})
+
+assert_equals({parse("[]]", "[", 1, ctx)}, {
+ {codes = {utf8.byte("]")}},
+ utf8.raw.len("[]]")
+})
+
+assert_equals({parse("[^]]", "[", 1, ctx)}, {
+ {codes = {utf8.byte("]")}, inverted = true},
+ utf8.raw.len("[^]]")
+})
+
+--[[--
+multibyte chars
+--]]--
+
+assert_equals({parse("ббюю", "б", #"" + 1, ctx)}, {{codes = {utf8.byte("б")}}, utf8.raw.len("б")})
+assert_equals({parse("ббюю", "б", #"б" + 1, ctx)}, {{codes = {utf8.byte("б")}}, utf8.raw.len("б")})
+assert_equals({parse("ббюю", "ю", #"бб" + 1, ctx)}, {{codes = {utf8.byte("ю")}}, utf8.raw.len("ю")})
+assert_equals({parse("ббюю", "ю", #"ббю" + 1, ctx)}, {{codes = {utf8.byte("ю")}}, utf8.raw.len("ю")})
+
+assert_equals({parse("бб%aю", "%", #"бб" + 1, ctx)}, {{classes = {'alpha'}}, 2})
+assert_equals({parse("ббц%Aю", "%", #"ббц" + 1, ctx)}, {{not_classes = {'alpha'}}, 2})
+assert_equals({parse("бб.ю", ".", #"бб" + 1, ctx)}, {{inverted = true}, 1})
+
+assert_equals({parse("бб[ц]ю", "[", #"бб" + 1, ctx)}, {
+ {codes = {utf8.byte("ц")}, ranges = nil, classes = nil, not_classes = nil},
+ utf8.raw.len("[ц]")
+})
+
+assert_equals({parse("бб[%A]ю", "[", #"бб" + 1, ctx)}, {
+ {codes = nil, ranges = nil, classes = nil, not_classes = {'alpha'}},
+ utf8.raw.len("[%A]")
+})
+
+assert_equals({parse("бб[[ц]]ю", "[", #"бб" + 1, ctx)}, {
+ {codes = {utf8.byte("["), utf8.byte("ц")}, ranges = nil, classes = nil, not_classes = nil},
+ utf8.raw.len("[[ц]")
+})
+
+assert_equals({parse("бб[%a[ц]]ю", "[", #"бб" + 1, ctx)}, {
+ {codes = {utf8.byte("["), utf8.byte("ц")}, ranges = nil, classes = {'alpha'}, not_classes = nil},
+ utf8.raw.len("[%a[ц]")
+})
+
+ctx.internal = true
+assert_equals({parse("ббц-ыю", "ц", #"бб" + 1, ctx)}, {
+ {ranges = {{utf8.byte("ц"),utf8.byte("ы")}}},
+ utf8.raw.len("ц-ы")
+})
+
+ctx.internal = false
+assert_equals({parse("бб[ц-ы]ю", "[", #"бб" + 1, ctx)}, {
+ {codes = nil, ranges = {{utf8.byte("ц"),utf8.byte("ы")}}, classes = nil, not_classes = nil},
+ utf8.raw.len("[ц-ы]")
+})
+
+assert_equals({parse("бб[ц-]]ю", "[", #"бб" + 1, ctx)}, {
+ {codes = {utf8.byte("-"), utf8.byte("ц")}, ranges = nil, classes = nil, not_classes = nil},
+ utf8.raw.len("[ц-]")
+})
+
+assert_equals({parse("ббы-", "ы", #"бб" + 1, ctx)}, {
+ {codes = {utf8.byte("ы")}},
+ utf8.raw.len("ы")
+})
+
+ctx.internal = true
+assert_equals({parse("ббы-цю", "ы", #"бб" + 1, ctx)}, {
+ {ranges = {{utf8.byte("ы"),utf8.byte("ц")}}},
+ utf8.raw.len("ы-ц")
+})
+
+ctx.internal = false
+assert_equals({parse("бб[ы]ю", "[", #"бб" + 1, ctx)}, {
+ {codes = {utf8.byte("ы")}, ranges = nil, classes = nil, not_classes = nil},
+ utf8.raw.len("[ы]")
+})
+
+print "OK"
diff --git a/mac/.config/mpv/script-modules/utf8/test/charclass_runtime.lua b/mac/.config/mpv/script-modules/utf8/test/charclass_runtime.lua
new file mode 100644
index 0000000..616af14
--- /dev/null
+++ b/mac/.config/mpv/script-modules/utf8/test/charclass_runtime.lua
@@ -0,0 +1,116 @@
+local utf8 = require("init")
+utf8.config = {
+ debug = nil, --utf8:require("util").debug
+}
+utf8:init()
+
+local cl = utf8:require("charclass.runtime.init")
+
+local equals = require('test.util').equals
+local assert = require('test.util').assert
+local assert_equals = require('test.util').assert_equals
+
+assert_equals(true, cl.new()
+ :with_codes(utf8.byte' ')
+ :invert()
+ :in_codes(utf8.byte' '))
+
+assert_equals(false, cl.new()
+ :with_codes(utf8.byte' ')
+ :invert()
+ :test(utf8.byte' '))
+
+assert_equals(false, cl.new()
+ :with_codes()
+ :with_ranges()
+ :with_classes('space')
+ :without_classes()
+ :with_subs()
+ :invert()
+ :test(utf8.byte(' ')))
+
+assert_equals(true, cl.new()
+ :with_codes()
+ :with_ranges()
+ :with_classes()
+ :without_classes('space')
+ :with_subs()
+ :invert()
+ :test(utf8.byte(' ')))
+
+assert_equals(false, cl.new()
+ :with_codes()
+ :with_ranges()
+ :with_classes()
+ :without_classes()
+ :with_subs(cl.new():with_classes('space'))
+ :invert()
+ :test(utf8.byte(' ')))
+
+assert_equals(true, cl.new()
+ :with_codes()
+ :with_ranges()
+ :with_classes()
+ :without_classes()
+ :with_subs(cl.new():with_classes('space'):invert())
+ :invert()
+ :test(utf8.byte(' ')))
+
+assert_equals(true, cl.new()
+ :with_codes()
+ :with_ranges()
+ :with_classes('punct', 'digit', 'space', 'cntrl')
+ :without_classes()
+ :with_subs()
+ :invert()
+ :test(utf8.byte'П')
+)
+
+assert_equals(true, cl.new()
+ :with_codes()
+ :with_ranges()
+ :with_classes('punct', 'digit', 'space', 'cntrl')
+ :without_classes()
+ :with_subs()
+ :invert()
+ :test(utf8.byte'и')
+)
+
+assert_equals(true, cl.new()
+ :with_codes()
+ :with_ranges()
+ :with_classes()
+ :without_classes('space')
+ :with_subs()
+ :test(utf8.byte'f')
+)
+
+assert_equals(false, cl.new()
+ :with_codes()
+ :with_ranges()
+ :with_classes()
+ :without_classes('space')
+ :with_subs()
+ :test(utf8.byte'\n')
+)
+
+assert_equals(false, cl.new()
+ :with_codes()
+ :with_ranges()
+ :with_classes('lower')
+ :without_classes()
+ :with_subs()
+ :invert()
+ :test(nil)
+)
+
+assert_equals(false, cl.new()
+ :with_codes()
+ :with_ranges()
+ :with_classes('lower')
+ :without_classes()
+ :with_subs()
+ :test(nil)
+)
+
+print "OK"
diff --git a/mac/.config/mpv/script-modules/utf8/test/context_runtime.lua b/mac/.config/mpv/script-modules/utf8/test/context_runtime.lua
new file mode 100644
index 0000000..9a177bf
--- /dev/null
+++ b/mac/.config/mpv/script-modules/utf8/test/context_runtime.lua
@@ -0,0 +1,82 @@
+local utf8 = require("init"):init()
+
+local context = utf8:require('context.runtime')
+
+local equals = require('test.util').equals
+local assert = require('test.util').assert
+local assert_equals = require('test.util').assert_equals
+
+local ctx_en
+local ctx_ru
+local function setup()
+ ctx_en = context.new({str = 'asdf'})
+ ctx_ru = context.new({str = 'фыва'})
+end
+
+local test_get_char = (function()
+ setup()
+
+ assert_equals('a', ctx_en:get_char())
+ assert_equals('ф', ctx_ru:get_char())
+end)()
+
+local test_get_charcode = (function()
+ setup()
+
+ assert_equals(utf8.byte'a', ctx_en:get_charcode())
+ assert_equals(utf8.byte'ф', ctx_ru:get_charcode())
+end)()
+
+local test_next_char = (function()
+ setup()
+
+ assert_equals(1, ctx_en.pos)
+ assert_equals(1, ctx_ru.pos)
+
+ ctx_ru:next_char()
+ ctx_en:next_char()
+
+ assert_equals(2, ctx_en.pos)
+ assert_equals(2, ctx_ru.pos)
+
+ assert_equals('s', ctx_en:get_char())
+ assert_equals('ы', ctx_ru:get_char())
+ assert_equals(utf8.byte's', ctx_en:get_charcode())
+ assert_equals(utf8.byte'ы', ctx_ru:get_charcode())
+end)()
+
+local test_clone = (function()
+ setup()
+
+ local clone = ctx_en:clone()
+
+ assert(getmetatable(clone) == getmetatable(ctx_en))
+ assert_equals(clone, ctx_en)
+
+ ctx_en:next_char()
+
+ assert_equals('a', clone:get_char())
+ assert_equals('s', ctx_en:get_char())
+
+end)()
+
+local test_last_char = (function()
+ ctx_en = context.new({str = 'asdf', pos = 4})
+ ctx_ru = context.new({str = 'фыва', pos = 4})
+
+ assert_equals('f', ctx_en:get_char())
+ assert_equals('а', ctx_ru:get_char())
+
+ ctx_ru:next_char()
+ ctx_en:next_char()
+
+ assert_equals(5, ctx_en.pos)
+ assert_equals(5, ctx_ru.pos)
+
+ assert_equals("", ctx_en:get_char())
+ assert_equals("", ctx_ru:get_char())
+ assert_equals(nil, ctx_en:get_charcode())
+ assert_equals(nil, ctx_ru:get_charcode())
+end)()
+
+print('OK')
diff --git a/mac/.config/mpv/script-modules/utf8/test/strict.lua b/mac/.config/mpv/script-modules/utf8/test/strict.lua
new file mode 100644
index 0000000..7324644
--- /dev/null
+++ b/mac/.config/mpv/script-modules/utf8/test/strict.lua
@@ -0,0 +1,42 @@
+--[[--
+strict.lua from http://metalua.luaforge.net/src/lib/strict.lua.html
+--]]--
+
+--
+-- strict.lua
+-- checks uses of undeclared global variables
+-- All global variables must be 'declared' through a regular assignment
+-- (even assigning nil will do) in a main chunk before being used
+-- anywhere or assigned to inside a function.
+--
+
+local mt = getmetatable(_G)
+if mt == nil then
+ mt = {}
+ setmetatable(_G, mt)
+end
+
+__STRICT = true
+mt.__declared = {}
+
+mt.__newindex = function (t, n, v)
+ if __STRICT and not mt.__declared[n] then
+ local w = debug.getinfo(2, "S").what
+ if w ~= "main" and w ~= "C" then
+ error("assign to undeclared variable '"..n.."'", 2)
+ end
+ mt.__declared[n] = true
+ end
+ rawset(t, n, v)
+end
+
+mt.__index = function (t, n)
+ if not mt.__declared[n] and debug.getinfo(2, "S").what ~= "C" then
+ error("variable '"..n.."' is not declared", 2)
+ end
+ return rawget(t, n)
+end
+
+function global(...)
+ for _, v in ipairs{...} do mt.__declared[v] = true end
+end
diff --git a/mac/.config/mpv/script-modules/utf8/test/test.lua b/mac/.config/mpv/script-modules/utf8/test/test.lua
new file mode 100644
index 0000000..8653b5d
--- /dev/null
+++ b/mac/.config/mpv/script-modules/utf8/test/test.lua
@@ -0,0 +1,205 @@
+local utf8 = require('init')
+utf8.config = {
+ debug = nil,
+-- debug = utf8:require("util").debug,
+}
+utf8:init()
+
+for k,v in pairs(utf8) do
+ string[k] = v
+end
+
+local LUA_51, LUA_53 = false, false
+if "\xe4" == "xe4" then -- lua5.1
+ LUA_51 = true
+else -- luajit lua5.3
+ LUA_53 = true
+end
+
+local FFI_ENABLED = false
+if pcall(require, "ffi") then
+ FFI_ENABLED = true
+end
+
+local res = {}
+
+local equals = require 'test.util'.equals
+local assert = require 'test.util'.assert
+local assert_equals = require 'test.util'.assert_equals
+
+if FFI_ENABLED then
+ assert_equals(("АБВ"):lower(), "абв")
+ assert_equals(("абв"):upper(), "АБВ")
+end
+
+res = {}
+for _, w in ("123456789"):gensub(2), {1} do res[#res + 1] = w end
+assert_equals({"23", "56", "89"}, res)
+
+assert_equals(0, ("фыва"):next(0))
+assert_equals(100, ("фыва"):next(100))
+assert_equals(#"ф" + 1, ("фыва"):next(1))
+assert_equals("ыва", utf8.raw.sub("фыва", ("фыва"):next(1)))
+
+res = {}
+for p, c in ("абвгд"):codes() do res[#res + 1] = {p, c} end
+assert_equals({
+ {1, utf8.byte'а'},
+ {#'а' + 1, utf8.byte'б'},
+ {#'аб' + 1, utf8.byte'в'},
+ {#'абв' + 1, utf8.byte'г'},
+ {#'абвг' + 1, utf8.byte'д'},
+}, res)
+
+assert_equals(1, utf8.offset('abcde', 0))
+
+assert_equals(1, utf8.offset('abcde', 1))
+assert_equals(5, utf8.offset('abcde', 5))
+assert_equals(6, utf8.offset('abcde', 6))
+assert_equals(nil, utf8.offset('abcde', 7))
+
+assert_equals(5, utf8.offset('abcde', -1))
+assert_equals(1, utf8.offset('abcde', -5))
+assert_equals(nil, utf8.offset('abcde', -6))
+
+assert_equals(1, utf8.offset('abcde', 0, 1))
+assert_equals(3, utf8.offset('abcde', 0, 3))
+assert_equals(6, utf8.offset('abcde', 0, 6))
+
+assert_equals(3, utf8.offset('abcde', 1, 3))
+assert_equals(5, utf8.offset('abcde', 3, 3))
+assert_equals(6, utf8.offset('abcde', 4, 3))
+assert_equals(nil, utf8.offset('abcde', 5, 3))
+
+assert_equals(2, utf8.offset('abcde', -1, 3))
+assert_equals(1, utf8.offset('abcde', -2, 3))
+assert_equals(5, utf8.offset('abcde', -1, 6))
+assert_equals(nil, utf8.offset('abcde', -3, 3))
+
+assert_equals(1, utf8.offset('абвгд', 0))
+
+assert_equals(1, utf8.offset('абвгд', 1))
+assert_equals(#'абвг' + 1, utf8.offset('абвгд', 5))
+assert_equals(#'абвгд' + 1, utf8.offset('абвгд', 6))
+assert_equals(nil, utf8.offset('абвгд', 7))
+
+assert_equals(#'абвг' + 1, utf8.offset('абвгд', -1))
+assert_equals(1, utf8.offset('абвгд', -5))
+assert_equals(nil, utf8.offset('абвгд', -6))
+
+assert_equals(1, utf8.offset('абвгд', 0, 1))
+assert_equals(1, utf8.offset('абвгд', 0, 2))
+assert_equals(#'аб' + 1, utf8.offset('абвгд', 0, #'аб' + 1))
+assert_equals(#'аб' + 1, utf8.offset('абвгд', 0, #'аб' + 2))
+assert_equals(#'абвгд' + 1, utf8.offset('абвгд', 0, #'абвгд' + 1))
+
+assert_equals(#'аб' + 1, utf8.offset('абвгд', 1, #'аб' + 1))
+assert_equals(#'абвг' + 1, utf8.offset('абвгд', 3, #'аб' + 1))
+assert_equals(#'абвгд' + 1, utf8.offset('абвгд', 4, #'аб' + 1))
+assert_equals(#'абвгд' + 1, utf8.offset('абвгд', 4, #'аб' + 2))
+assert_equals(nil, utf8.offset('абвгд', 5, #'аб' + 1))
+
+assert_equals(#'а' + 1, utf8.offset('абвгд', -1, #'аб' + 1))
+assert_equals(1, utf8.offset('абвгд', -2, #'аб' + 1))
+assert_equals(#'абвг' + 1, utf8.offset('абвгд', -1, #'абвгд' + 1))
+assert_equals(nil, utf8.offset('абвгд', -3, #'аб' + 1))
+
+assert(("фыва"):validate())
+assert_equals({false, {{ pos = #"ф" + 1, part = 1, code = 255 }} }, {("ф\255ыва"):validate()})
+if LUA_53 then
+ assert_equals({false, {{ pos = #"ф" + 1, part = 1, code = 0xFF }} }, {("ф\xffыва"):validate()})
+end
+
+assert_equals(nil, ("aabb"):find("%bcd"))
+assert_equals({1, 4}, {("aabb"):find("%bab")})
+assert_equals({1, 2}, {("aba"):find('%bab')})
+
+res = {}
+for w in ("aacaabbcabbacbaacab"):gmatch('%bab') do res[#res + 1] = w end
+assert_equals({"acaabbcabb", "acb", "ab"}, res)
+
+assert_equals({1, 0}, {("aacaabbcabbacbaacab"):find('%f[acb]')})
+assert_equals("a", ("aba"):match('%f[ab].'))
+
+res = {}
+for w in ("aacaabbcabbacbaacab"):gmatch('%f[ab]') do res[#res + 1] = w end
+assert_equals({"", "", "", "", ""}, res)
+
+assert_equals({"HaacHaabbcHabbacHbaacHab", 5}, {("aacaabbcabbacbaacab"):gsub('%f[ab]', 'H')})
+
+res = {}
+for w in ("Привет, мир, от Lua"):gmatch("[^%p%d%s%c]+") do res[#res + 1] = w end
+assert_equals({"Привет", "мир", "от", "Lua"}, res)
+
+res = {}
+for k, v in ("从=世界, 到=Lua"):gmatch("([^%p%s%c]+)=([^%p%s%c]+)") do res[k] = v end
+assert_equals({["到"] = "Lua", ["从"] = "世界"}, res)
+
+assert_equals("Ahoj Ahoj světe světe", ("Ahoj světe"):gsub("([^%p%s%c]+)", "%1 %1"))
+
+assert_equals("Ahoj Ahoj světe", ("Ahoj světe"):gsub("[^%p%s%c]+", "%0 %0", 1))
+
+assert_equals("κόσμο γεια Lua από", ("γεια κόσμο από Lua"):gsub("([^%p%s%c]+)%s*([^%p%s%c]+)", "%2 %1"))
+
+assert_equals({8, 27, "ололоо я водитель э"}, {("пыщпыщ ололоо я водитель энло"):find("(.л.+)н")})
+
+assert_equals({"пыщпыщ о보라보라 я водитель эн보라", 3}, {("пыщпыщ ололоо я водитель энло"):gsub("ло+", "보라")})
+
+assert_equals("пыщпыщ ололоо я", ("пыщпыщ ололоо я водитель энло"):match("^п[лопыщ ]*я"))
+
+assert_equals("в", ("пыщпыщ ололоо я водитель энло"):match("[в-д]+"))
+
+assert_equals(nil, ('abc abc'):match('([^%s]+)%s%s')) -- https://github.com/Stepets/utf8.lua/issues/2
+
+res = {}
+for w in ("aacabbacbbcaabbcbacaa"):gmatch("a+b") do res[#res + 1] = w end
+assert_equals({"ab","aab"}, res)
+
+res = {}
+for w in ("aacabbacbbcaabbcbacaa"):gmatch("a-b") do res[#res + 1] = w end
+assert_equals({"ab","b","b","b","aab","b","b"}, res)
+
+res = {}
+for w in ("aacabbacbbcaabbcbacaa"):gmatch("a*b") do res[#res + 1] = w end
+assert_equals({"ab","b","b","b","aab","b","b"}, res)
+
+res = {}
+for w in ("aacabbacbbcaabbcbacaa"):gmatch("ba+") do res[#res + 1] = w end
+assert_equals({"ba","ba"}, res)
+
+res = {}
+for w in ("aacabbacbbcaabbcbacaa"):gmatch("ba-") do res[#res + 1] = w end
+assert_equals({"b","b","b","b","b","b","b"}, res)
+
+res = {}
+for w in ("aacabbacbbcaabbcbacaa"):gmatch("ba*") do res[#res + 1] = w end
+assert_equals({"b","ba","b","b","b","b","ba"}, res)
+
+assert_equals({"bacbbcaabbcba", "ba"}, {("aacabbacbbcaabbcbacaa"):match("((ba+).*%2)")})
+assert_equals({"bbacbbcaabbcb", "b"}, {("aacabbacbbcaabbcbacaa"):match("((ba*).*%2)")})
+
+res = {}
+for w in ("aacabbacbbcaabbcbacaa"):gmatch("((b+a*).-%2)") do res[#res + 1] = w end
+assert_equals({"bbacbb", "bb"}, res)
+
+assert_equals("a**", ("a**v"):match("a**+"))
+assert_equals("a", ("a**v"):match("a**-"))
+
+assert_equals({"test", "."}, {("test.lua"):match("(.-)([.])")})
+
+-- https://github.com/Stepets/utf8.lua/issues/3
+assert_equals({"ab", "c"}, {("abc"):match("^([ab]-)([^b]*)$")})
+assert_equals({"ab", ""}, {("ab"):match("^([ab]-)([^b]*)$")})
+assert_equals({"items.", ""}, {("items."):match("^(.-)([^.]*)$")})
+assert_equals({"", "items"}, {("items"):match("^(.-)([^.]*)$")})
+
+-- https://github.com/Stepets/utf8.lua/issues/4
+assert_equals({"ab.123", 1}, {("ab.?"):gsub("%?", "123")})
+
+-- https://github.com/Stepets/utf8.lua/issues/5
+assert_equals({"ab", 1}, {("ab"):gsub("a", "%0")})
+assert_equals({"ab", 1}, {("ab"):gsub("a", "%1")})
+
+assert_equals("c", ("abc"):match("c", -1))
+
+print("\ntests passed\n")
diff --git a/mac/.config/mpv/script-modules/utf8/test/test_compat.lua b/mac/.config/mpv/script-modules/utf8/test/test_compat.lua
new file mode 100644
index 0000000..d5042a5
--- /dev/null
+++ b/mac/.config/mpv/script-modules/utf8/test/test_compat.lua
@@ -0,0 +1,109 @@
+local utf8 = require 'init'
+utf8.config = {
+ debug = nil, --utf8:require("util").debug
+}
+utf8:init()
+print('testing utf8 library')
+
+local LUA_51, LUA_53 = false, false
+if "\xe4" == "xe4" then -- lua5.1
+ LUA_51 = true
+else -- luajit lua5.3
+ LUA_53 = true
+end
+
+assert(utf8.sub("123456789",2,4) == "234")
+assert(utf8.sub("123456789",7) == "789")
+assert(utf8.sub("123456789",7,6) == "")
+assert(utf8.sub("123456789",7,7) == "7")
+assert(utf8.sub("123456789",0,0) == "")
+assert(utf8.sub("123456789",-10,10) == "123456789")
+assert(utf8.sub("123456789",1,9) == "123456789")
+assert(utf8.sub("123456789",-10,-20) == "")
+assert(utf8.sub("123456789",-1) == "9")
+assert(utf8.sub("123456789",-4) == "6789")
+assert(utf8.sub("123456789",-6, -4) == "456")
+if not _no32 then
+ assert(utf8.sub("123456789",-2^31, -4) == "123456")
+ assert(utf8.sub("123456789",-2^31, 2^31 - 1) == "123456789")
+ assert(utf8.sub("123456789",-2^31, -2^31) == "")
+end
+assert(utf8.sub("\000123456789",3,5) == "234")
+assert(utf8.sub("\000123456789", 8) == "789")
+print('+')
+
+assert(utf8.find("123456789", "345") == 3)
+local a,b = utf8.find("123456789", "345")
+assert(utf8.sub("123456789", a, b) == "345")
+assert(utf8.find("1234567890123456789", "345", 3) == 3)
+assert(utf8.find("1234567890123456789", "345", 4) == 13)
+assert(utf8.find("1234567890123456789", "346", 4) == nil)
+assert(utf8.find("1234567890123456789", ".45", -9) == 13)
+assert(utf8.find("abcdefg", "\0", 5, 1) == nil)
+assert(utf8.find("", "") == 1)
+assert(utf8.find("", "", 1) == 1)
+assert(not utf8.find("", "", 2))
+assert(utf8.find('', 'aaa', 1) == nil)
+assert(('alo(.)alo'):find('(.)', 1, 1) == 4)
+print('+')
+
+assert(utf8.len("") == 0)
+assert(utf8.len("\0\0\0") == 3)
+assert(utf8.len("1234567890") == 10)
+
+assert(utf8.byte("a") == 97)
+if LUA_51 then
+ assert(utf8.byte("�") > 127)
+else
+ assert(utf8.byte("\xe4") > 127)
+end
+assert(utf8.byte(utf8.char(255)) == 255)
+assert(utf8.byte(utf8.char(0)) == 0)
+assert(utf8.byte("\0") == 0)
+assert(utf8.byte("\0\0alo\0x", -1) == string.byte('x'))
+assert(utf8.byte("ba", 2) == 97)
+assert(utf8.byte("\n\n", 2, -1) == 10)
+assert(utf8.byte("\n\n", 2, 2) == 10)
+assert(utf8.byte("") == nil)
+assert(utf8.byte("hi", -3) == nil)
+assert(utf8.byte("hi", 3) == nil)
+assert(utf8.byte("hi", 9, 10) == nil)
+assert(utf8.byte("hi", 2, 1) == nil)
+assert(utf8.char() == "")
+if LUA_53 then
+ assert(utf8.raw.char(0, 255, 0) == "\0\255\0") -- fails due 255 can't be utf8 byte
+ assert(utf8.char(0, 255, 0) == "\0\195\191\0")
+ assert(utf8.raw.char(0, utf8.byte("\xe4"), 0) == "\0\xe4\0")
+ assert(utf8.char(0, utf8.byte("\xe4"), 0) == "\0\195\164\0")
+ assert(utf8.raw.char(utf8.raw.byte("\xe4l\0�u", 1, -1)) == "\xe4l\0�u")
+ assert(utf8.raw.char(utf8.raw.byte("\xe4l\0�u", 1, -1)) == "\xe4l\0�u")
+ assert(utf8.raw.char(utf8.raw.byte("\xe4l\0�u", 1, 0)) == "")
+ assert(utf8.raw.char(utf8.raw.byte("\xe4l\0�u", -10, 100)) == "\xe4l\0�u")
+end
+
+assert(utf8.upper("ab\0c") == "AB\0C")
+assert(utf8.lower("\0ABCc%$") == "\0abcc%$")
+assert(utf8.rep('teste', 0) == '')
+assert(utf8.rep('t�s\00t�', 2) == 't�s\0t�t�s\000t�')
+assert(utf8.rep('', 10) == '')
+print('+')
+
+assert(utf8.upper("ab\0c") == "AB\0C")
+assert(utf8.lower("\0ABCc%$") == "\0abcc%$")
+
+assert(utf8.reverse"" == "")
+assert(utf8.reverse"\0\1\2\3" == "\3\2\1\0")
+assert(utf8.reverse"\0001234" == "4321\0")
+
+for i=0,30 do assert(utf8.len(string.rep('a', i)) == i) end
+
+print('+')
+
+do
+ local f = utf8.gmatch("1 2 3 4 5", "%d+")
+ assert(f() == "1")
+ local co = coroutine.wrap(f)
+ assert(co() == "2")
+end
+
+print('OK')
diff --git a/mac/.config/mpv/script-modules/utf8/test/test_pm.lua b/mac/.config/mpv/script-modules/utf8/test/test_pm.lua
new file mode 100644
index 0000000..9c8e472
--- /dev/null
+++ b/mac/.config/mpv/script-modules/utf8/test/test_pm.lua
@@ -0,0 +1,392 @@
+--[[--
+MIT License
+
+Copyright (c) 2018 Xavier Wang
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+--]]--
+
+local utf8 = require 'init'
+utf8.config = {
+ debug = nil, --utf8:require("util").debug,
+}
+utf8:init()
+
+print('testing pattern matching')
+
+local
+function f(s, p)
+ local i,e = utf8.find(s, p)
+ if i then return utf8.sub(s, i, e) end
+end
+
+local
+function f1(s, p)
+ p = utf8.gsub(p, "%%([0-9])", function (s) return "%" .. (tonumber(s)+1) end)
+ p = utf8.gsub(p, "^(^?)", "%1()", 1)
+ p = utf8.gsub(p, "($?)$", "()%1", 1)
+ local t = {utf8.match(s, p)}
+ return utf8.sub(s, t[1], t[#t] - 1)
+end
+
+local
+a,b = utf8.find('', '') -- empty patterns are tricky
+assert(a == 1 and b == 0);
+a,b = utf8.find('alo', '')
+assert(a == 1 and b == 0)
+a,b = utf8.find('a\0o a\0o a\0o', 'a', 1) -- first position
+assert(a == 1 and b == 1)
+a,b = utf8.find('a\0o a\0o a\0o', 'a\0o', 2) -- starts in the midle
+assert(a == 5 and b == 7)
+a,b = utf8.find('a\0o a\0o a\0o', 'a\0o', 9) -- starts in the midle
+assert(a == 9 and b == 11)
+a,b = utf8.find('a\0a\0a\0a\0\0ab', '\0ab', 2); -- finds at the end
+assert(a == 9 and b == 11);
+a,b = utf8.find('a\0a\0a\0a\0\0ab', 'b') -- last position
+assert(a == 11 and b == 11)
+assert(utf8.find('a\0a\0a\0a\0\0ab', 'b\0') == nil) -- check ending
+assert(utf8.find('', '\0') == nil)
+assert(utf8.find('alo123alo', '12') == 4)
+assert(utf8.find('alo123alo', '^12') == nil)
+
+assert(utf8.match("aaab", ".*b") == "aaab")
+assert(utf8.match("aaa", ".*a") == "aaa")
+assert(utf8.match("b", ".*b") == "b")
+
+assert(utf8.match("aaab", ".+b") == "aaab")
+assert(utf8.match("aaa", ".+a") == "aaa")
+assert(not utf8.match("b", ".+b"))
+
+assert(utf8.match("aaab", ".?b") == "ab")
+assert(utf8.match("aaa", ".?a") == "aa")
+assert(utf8.match("b", ".?b") == "b")
+
+assert(f('aloALO', '%l*') == 'alo')
+assert(f('aLo_ALO', '%a*') == 'aLo')
+
+assert(f(" \n\r*&\n\r xuxu \n\n", "%g%g%g+") == "xuxu")
+
+assert(f('aaab', 'a*') == 'aaa');
+assert(f('aaa', '^.*$') == 'aaa');
+assert(f('aaa', 'b*') == '');
+assert(f('aaa', 'ab*a') == 'aa')
+assert(f('aba', 'ab*a') == 'aba')
+assert(f('aaab', 'a+') == 'aaa')
+assert(f('aaa', '^.+$') == 'aaa')
+assert(f('aaa', 'b+') == nil)
+assert(f('aaa', 'ab+a') == nil)
+assert(f('aba', 'ab+a') == 'aba')
+assert(f('a$a', '.$') == 'a')
+assert(f('a$a', '.%$') == 'a$')
+assert(f('a$a', '.$.') == 'a$a')
+assert(f('a$a', '$$') == nil)
+assert(f('a$b', 'a$') == nil)
+assert(f('a$a', '$') == '')
+assert(f('', 'b*') == '')
+assert(f('aaa', 'bb*') == nil)
+assert(f('aaab', 'a-') == '')
+assert(f('aaa', '^.-$') == 'aaa')
+assert(f('aabaaabaaabaaaba', 'b.*b') == 'baaabaaabaaab')
+assert(f('aabaaabaaabaaaba', 'b.-b') == 'baaab')
+assert(f('alo xo', '.o$') == 'xo')
+assert(f(' \n isto é assim', '%S%S*') == 'isto')
+assert(f(' \n isto é assim', '%S*$') == 'assim')
+assert(f(' \n isto é assim', '[a-z]*$') == 'assim')
+assert(f('um caracter ? extra', '[^%sa-z]') == '?')
+assert(f('', 'a?') == '')
+assert(f('á', 'á?') == 'á')
+assert(f('ábl', 'á?b?l?') == 'ábl')
+assert(f(' ábl', 'á?b?l?') == '')
+assert(f('aa', '^aa?a?a') == 'aa')
+assert(f(']]]áb', '[^]]') == 'á')
+assert(f("0alo alo", "%x*") == "0a")
+assert(f("alo alo", "%C+") == "alo alo")
+print('+')
+
+assert(f1('alo alx 123 b\0o b\0o', '(..*) %1') == "b\0o b\0o")
+assert(f1('axz123= 4= 4 34', '(.+)=(.*)=%2 %1') == '3= 4= 4 3')
+assert(f1('=======', '^(=*)=%1$') == '=======')
+assert(utf8.match('==========', '^([=]*)=%1$') == nil)
+
+local function range (i, j)
+ if i <= j then
+ return i, range(i+1, j)
+ end
+end
+
+local abc = utf8.char(range(0, 255));
+
+assert(utf8.len(abc) == 256)
+assert(string.len(abc) == 384)
+
+local
+function strset (p)
+ local res = {s=''}
+ utf8.gsub(abc, p, function (c) res.s = res.s .. c end)
+ return res.s
+end;
+
+local a, b, c, d, e, t
+
+-- local E = utf8.escape
+-- assert(utf8.len(strset(E'[%200-%210]')) == 11)
+
+assert(strset('[a-z]') == "abcdefghijklmnopqrstuvwxyz")
+assert(strset('[a-z%d]') == strset('[%da-uu-z]'))
+assert(strset('[a-]') == "-a")
+assert(strset('[^%W]') == strset('[%w]'))
+assert(strset('[]%%]') == '%]')
+assert(strset('[a%-z]') == '-az')
+assert(strset('[%^%[%-a%]%-b]') == '-[]^ab')
+-- assert(strset('%Z') == strset(E'[%1-%255]'))
+-- assert(strset('.') == strset(E'[%1-%255%%z]'))
+print('+');
+
+assert(utf8.match("alo xyzK", "(%w+)K") == "xyz")
+assert(utf8.match("254 K", "(%d*)K") == "")
+assert(utf8.match("alo ", "(%w*)$") == "")
+assert(utf8.match("alo ", "(%w+)$") == nil)
+assert(utf8.find("(álo)", "%(á") == 1)
+a, b, c, d, e = utf8.match("âlo alo", "^(((.).).* (%w*))$")
+assert(a == 'âlo alo' and b == 'âl' and c == 'â' and d == 'alo' and e == nil)
+a, b, c, d = utf8.match('0123456789', '(.+(.?)())')
+assert(a == '0123456789' and b == '' and c == 11 and d == nil)
+print('+')
+
+assert(utf8.gsub('ülo ülo', 'ü', 'x') == 'xlo xlo')
+assert(utf8.gsub('alo úlo ', ' +$', '') == 'alo úlo') -- trim
+assert(utf8.gsub(' alo alo ', '^%s*(.-)%s*$', '%1') == 'alo alo') -- double trim
+assert(utf8.gsub('alo alo \n 123\n ', '%s+', ' ') == 'alo alo 123 ')
+t = "abç d"
+a, b = utf8.gsub(t, '(.)', '%1@')
+assert('@'..a == utf8.gsub(t, '', '@') and b == 5)
+a, b = utf8.gsub('abçd', '(.)', '%0@', 2)
+assert(a == 'a@b@çd' and b == 2)
+assert(utf8.gsub('alo alo', '()[al]', '%1') == '12o 56o')
+assert(utf8.gsub("abc=xyz", "(%w*)(%p)(%w+)", "%3%2%1-%0") ==
+ "xyz=abc-abc=xyz")
+assert(utf8.gsub("abc", "%w", "%1%0") == "aabbcc")
+assert(utf8.gsub("abc", "%w+", "%0%1") == "abcabc")
+assert(utf8.gsub('áéí', '$', '\0óú') == 'áéí\0óú')
+assert(utf8.gsub('', '^', 'r') == 'r')
+assert(utf8.gsub('', '$', 'r') == 'r')
+print('+')
+
+assert(utf8.gsub("um (dois) tres (quatro)", "(%(%w+%))", utf8.upper) ==
+ "um (DOIS) tres (QUATRO)")
+
+do
+ local function setglobal (n,v) rawset(_G, n, v) end
+ utf8.gsub("a=roberto,roberto=a", "(%w+)=(%w%w*)", setglobal)
+ assert(_G.a=="roberto" and _G.roberto=="a")
+end
+
+function f(a,b) return utf8.gsub(a,'.',b) end
+assert(utf8.gsub("trocar tudo em |teste|b| é |beleza|al|", "|([^|]*)|([^|]*)|", f) ==
+ "trocar tudo em bbbbb é alalalalalal")
+
+local function dostring (s) return (loadstring or load)(s)() or "" end
+assert(utf8.gsub("alo $a=1$ novamente $return a$", "$([^$]*)%$", dostring) ==
+ "alo novamente 1")
+
+x = utf8.gsub("$local utf8=require'init' x=utf8.gsub('alo', '.', utf8.upper)$ assim vai para $return x$",
+ "$([^$]*)%$", dostring)
+assert(x == ' assim vai para ALO')
+
+local s,r
+t = {}
+s = 'a alo jose joao'
+r = utf8.gsub(s, '()(%w+)()', function (a,w,b)
+ assert(utf8.len(w) == b-a);
+ t[a] = b-a;
+ end)
+assert(s == r and t[1] == 1 and t[3] == 3 and t[7] == 4 and t[13] == 4)
+
+local
+function isbalanced (s)
+ return utf8.find(utf8.gsub(s, "%b()", ""), "[()]") == nil
+end
+
+assert(isbalanced("(9 ((8))(\0) 7) \0\0 a b ()(c)() a"))
+assert(not isbalanced("(9 ((8) 7) a b (\0 c) a"))
+assert(utf8.gsub("alo 'oi' alo", "%b''", '"') == 'alo " alo')
+
+
+local t = {"apple", "orange", "lime"; n=0}
+assert(utf8.gsub("x and x and x", "x", function () t.n=t.n+1; return t[t.n] end)
+ == "apple and orange and lime")
+
+t = {n=0}
+utf8.gsub("first second word", "%w%w*", function (w) t.n=t.n+1; t[t.n] = w end)
+assert(t[1] == "first" and t[2] == "second" and t[3] == "word" and t.n == 3)
+
+t = {n=0}
+assert(utf8.gsub("first second word", "%w+",
+ function (w) t.n=t.n+1; t[t.n] = w end, 2) == "first second word")
+assert(t[1] == "first" and t[2] == "second" and t[3] == nil)
+
+assert(not pcall(utf8.gsub, "alo", "(.", print))
+assert(not pcall(utf8.gsub, "alo", ".)", print))
+assert(not pcall(utf8.gsub, "alo", "(.", {}))
+assert(not pcall(utf8.gsub, "alo", "(.)", "%2"))
+assert(not pcall(utf8.gsub, "alo", "(%1)", "a"))
+--[[--
+Stepets: ignoring this test because it's probably bug in Lua.
+ %0 should be interpreted as capture reference only in replacement arg
+ it doesn't have sense in pattern
+--]]--
+-- assert(not pcall(utf8.gsub, "alo", "(%0)", "a"))
+
+-- bug since 2.5 (C-stack overflow)
+-- todo: benchmark OOM
+-- do
+-- local function f (size)
+-- local s = string.rep("a", size)
+-- local p = string.rep(".?", size)
+-- return pcall(utf8.match, s, p)
+-- end
+-- local r, m = f(80)
+-- assert(r and #m == 80)
+-- r, m = f(200000)
+-- assert(not r and utf8.find(m, "too complex"))
+-- end
+
+-- if not _soft then
+-- -- big strings
+-- local a = string.rep('a', 300000)
+-- assert(utf8.find(a, '^a*.?$'))
+-- assert(not utf8.find(a, '^a*.?b$'))
+-- assert(utf8.find(a, '^a-.?$'))
+
+-- -- bug in 5.1.2
+-- a = string.rep('a', 10000) .. string.rep('b', 10000)
+-- assert(not pcall(utf8.gsub, a, 'b'))
+-- end
+
+-- recursive nest of gsubs
+local function rev (s)
+ return utf8.gsub(s, "(.)(.+)", function (c,s1) return rev(s1)..c end)
+end
+
+local x = "abcdef"
+assert(rev(rev(x)) == x)
+
+
+-- gsub with tables
+assert(utf8.gsub("alo alo", ".", {}) == "alo alo")
+assert(utf8.gsub("alo alo", "(.)", {a="AA", l=""}) == "AAo AAo")
+assert(utf8.gsub("alo alo", "(.).", {a="AA", l="K"}) == "AAo AAo")
+assert(utf8.gsub("alo alo", "((.)(.?))", {al="AA", o=false}) == "AAo AAo")
+
+assert(utf8.gsub("alo alo", "().", {2,5,6}) == "256 alo")
+
+t = {}; setmetatable(t, {__index = function (t,s) return utf8.upper(s) end})
+assert(utf8.gsub("a alo b hi", "%w%w+", t) == "a ALO b HI")
+
+
+-- tests for gmatch
+local a = 0
+for i in utf8.gmatch('abcde', '()') do assert(i == a+1); a=i end
+assert(a==6)
+
+t = {n=0}
+for w in utf8.gmatch("first second word", "%w+") do
+ t.n=t.n+1; t[t.n] = w
+end
+assert(t[1] == "first" and t[2] == "second" and t[3] == "word")
+
+t = {3, 6, 9}
+for i in utf8.gmatch ("xuxx uu ppar r", "()(.)%2") do
+ assert(i == table.remove(t, 1))
+end
+assert(#t == 0)
+
+t = {}
+for i,j in utf8.gmatch("13 14 10 = 11, 15= 16, 22=23", "(%d+)%s*=%s*(%d+)") do
+ t[i] = j
+end
+a = 0
+for k,v in pairs(t) do assert(k+1 == v+0); a=a+1 end
+assert(a == 3)
+
+
+-- tests for `%f' (`frontiers')
+
+assert(utf8.gsub("aaa aa a aaa a", "%f[%w]a", "x") == "xaa xa x xaa x")
+assert(utf8.gsub("[[]] [][] [[[[", "%f[[].", "x") == "x[]] x]x] x[[[")
+assert(utf8.gsub("01abc45de3", "%f[%d]", ".") == ".01abc.45de.3")
+assert(utf8.gsub("01abc45 de3x", "%f[%D]%w", ".") == "01.bc45 de3.")
+-- local u = utf8.escape
+-- assert(utf8.gsub("function", u"%%f[%1-%255]%%w", ".") == ".unction")
+-- assert(utf8.gsub("function", u"%%f[^%1-%255]", ".") == "function.")
+
+--[[--
+Stepets: %z is Lua 5.1 class for representing \0
+ Lua 5.2, Lua 5.3 doesn't have it in documentation. So it's considered deprecated.
+--]]--
+assert(utf8.find("a", "%f[a]") == 1)
+assert(utf8.find("a", "%f[^%z]") == 1)
+assert(utf8.find("a", "%f[^%l]") == 2)
+assert(utf8.find("aba", "%f[a%z]") == 3)
+assert(utf8.find("aba", "%f[%z]") == 4)
+assert(not utf8.find("aba", "%f[%l%z]"))
+assert(not utf8.find("aba", "%f[^%l%z]"))
+
+local i, e = utf8.find(" alo aalo allo", "%f[%S].-%f[%s].-%f[%S]")
+assert(i == 2 and e == 5)
+local k = utf8.match(" alo aalo allo", "%f[%S](.-%f[%s].-%f[%S])")
+assert(k == 'alo ')
+
+local a = {1, 5, 9, 14, 17,}
+for k in utf8.gmatch("alo alo th02 is 1hat", "()%f[%w%d]") do
+ assert(table.remove(a, 1) == k)
+end
+assert(#a == 0)
+
+-- malformed patterns
+local function malform (p, m)
+ m = m or "malformed"
+ local r, msg = pcall(utf8.find, "a", p)
+ assert(not r and utf8.find(msg, m))
+end
+
+malform("[a")
+malform("[]")
+malform("[^]")
+malform("[a%]")
+malform("[a%")
+malform("%b", "unbalanced")
+malform("%ba", "unbalanced")
+malform("%")
+malform("%f", "missing")
+
+-- \0 in patterns
+assert(utf8.match("ab\0\1\2c", "[\0-\2]+") == "\0\1\2")
+assert(utf8.match("ab\0\1\2c", "[\0-\0]+") == "\0")
+assert(utf8.find("b$a", "$\0?") == 2)
+assert(utf8.find("abc\0efg", "%\0") == 4)
+assert(utf8.match("abc\0efg\0\1e\1g", "%b\0\1") == "\0efg\0\1e\1")
+assert(utf8.match("abc\0\0\0", "%\0+") == "\0\0\0")
+assert(utf8.match("abc\0\0\0", "%\0%\0?") == "\0\0")
+
+-- magic char after \0
+assert(utf8.find("abc\0\0","\0.") == 4)
+assert(utf8.find("abcx\0\0abc\0abc","x\0\0abc\0a.") == 4)
+
+print('OK')
diff --git a/mac/.config/mpv/script-modules/utf8/test/test_utf8data.lua b/mac/.config/mpv/script-modules/utf8/test/test_utf8data.lua
new file mode 100644
index 0000000..e915b2b
--- /dev/null
+++ b/mac/.config/mpv/script-modules/utf8/test/test_utf8data.lua
@@ -0,0 +1,15 @@
+local utf8uclc = require('init')
+utf8uclc.config = {
+ debug = nil,
+-- debug = utf8:require("util").debug,
+ conversion = {
+ uc_lc = setmetatable({}, {__index = function(self, idx) return "l" end}),
+ lc_uc = setmetatable({}, {__index = function(self, idx) return "u" end}),
+ }
+}
+utf8uclc:init()
+
+local assert_equals = require 'test.util'.assert_equals
+
+assert_equals(utf8uclc.lower("фыва"), "llll")
+assert_equals(utf8uclc.upper("фыва"), "uuuu")
diff --git a/mac/.config/mpv/script-modules/utf8/test/util.lua b/mac/.config/mpv/script-modules/utf8/test/util.lua
new file mode 100644
index 0000000..bdc25e5
--- /dev/null
+++ b/mac/.config/mpv/script-modules/utf8/test/util.lua
@@ -0,0 +1,75 @@
+require "test.strict"
+
+local function equals(t1, t2)
+ for k,v in pairs(t1) do
+ if t2[k] == nil then return false end
+ if type(t2[k]) == 'cdata' and type(v) == 'cdata' then
+ return true -- don't know how to compare
+ elseif type(t2[k]) == 'table' and type(v) == 'table' then
+ if not equals(t2[k], v) then return false end
+ else
+ if t2[k] ~= v then return false end
+ end
+ end
+ for k,v in pairs(t2) do
+ if t1[k] == nil then return false end
+ if type(t1[k]) == 'cdata' and type(v) == 'cdata' then
+ return true -- don't know how to compare
+ elseif type(t1[k]) == 'table' and type(v) == 'table' then
+ if not equals(t1[k], v) then return false end
+ else
+ if t1[k] ~= v then return false end
+ end
+ end
+ return true
+end
+
+local old_tostring = tostring
+local function tostring(v)
+ local type = type(v)
+ if type == 'table' then
+ local tbl = "{"
+ for k,v in pairs(v) do
+ tbl = tbl .. tostring(k) .. ' = ' .. tostring(v) .. ', '
+ end
+ return tbl .. '}'
+ else
+ return old_tostring(v)
+ end
+end
+
+local old_assert = assert
+local assert = function(cond, ...)
+ if not cond then
+ local data = {...}
+ local msg = ""
+ for _, v in pairs(data) do
+ local type = type(v)
+ if type == 'table' then
+ local tbl = "{"
+ for k,v in pairs(v) do
+ tbl = tbl .. tostring(k) .. ' = ' .. tostring(v) .. ', '
+ end
+ msg = msg .. tbl .. '}'
+ else
+ msg = msg .. tostring(v)
+ end
+ end
+ error(#data > 0 and msg or "assertion failed!")
+ end
+ return cond
+end
+
+local function assert_equals(a,b)
+ assert(
+ type(a) == 'table' and type(b) == 'table' and equals(a,b) or a == b,
+ "expected: ", a and a or tostring(a), "\n",
+ "got: ", b and b or tostring(b)
+ )
+end
+
+return {
+ equals = equals,
+ assert = assert,
+ assert_equals = assert_equals,
+}
diff --git a/mac/.config/mpv/script-modules/utf8/util.lua b/mac/.config/mpv/script-modules/utf8/util.lua
new file mode 100644
index 0000000..7723626
--- /dev/null
+++ b/mac/.config/mpv/script-modules/utf8/util.lua
@@ -0,0 +1,64 @@
+return function(utf8)
+
+function utf8.util.copy(obj, deep)
+ if type(obj) == 'table' then
+ local result = {}
+ if deep then
+ for k,v in pairs(obj) do
+ result[k] = utf8.util.copy(v, true)
+ end
+ else
+ for k,v in pairs(obj) do
+ result[k] = v
+ end
+ end
+ return result
+ else
+ return obj
+ end
+end
+
+local function dump(val, tab)
+ tab = tab or ''
+
+ if type(val) == 'table' then
+ utf8.config.logger('{\n')
+ for k,v in pairs(val) do
+ utf8.config.logger(tab .. tostring(k) .. " = ")
+ dump(v, tab .. '\t')
+ utf8.config.logger("\n")
+ end
+ utf8.config.logger(tab .. '}\n')
+ else
+ utf8.config.logger(tostring(val))
+ end
+end
+
+function utf8.util.debug(...)
+ local t = {...}
+ for _, v in ipairs(t) do
+ if type(v) == "table" and not (getmetatable(v) or {}).__tostring then
+ dump(v, '\t')
+ else
+ utf8.config.logger(tostring(v), " ")
+ end
+ end
+
+ utf8.config.logger('\n')
+end
+
+function utf8.debug(...)
+ if utf8.config.debug then
+ utf8.config.debug(...)
+ end
+end
+
+function utf8.util.next(str, bs)
+ local nbs1 = utf8.next(str, bs)
+ local nbs2 = utf8.next(str, nbs1)
+ return utf8.raw.sub(str, nbs1, nbs2 - 1), nbs1
+end
+
+return utf8.util
+
+end
diff --git a/mac/.config/mpv/script-modules/utf8_data.lua b/mac/.config/mpv/script-modules/utf8_data.lua
new file mode 100644
index 0000000..bec6b9e
--- /dev/null
+++ b/mac/.config/mpv/script-modules/utf8_data.lua
@@ -0,0 +1,1865 @@
+utf8_lc_uc = {
+ ["a"] = "A",
+ ["b"] = "B",
+ ["c"] = "C",
+ ["d"] = "D",
+ ["e"] = "E",
+ ["f"] = "F",
+ ["g"] = "G",
+ ["h"] = "H",
+ ["i"] = "I",
+ ["j"] = "J",
+ ["k"] = "K",
+ ["l"] = "L",
+ ["m"] = "M",
+ ["n"] = "N",
+ ["o"] = "O",
+ ["p"] = "P",
+ ["q"] = "Q",
+ ["r"] = "R",
+ ["s"] = "S",
+ ["t"] = "T",
+ ["u"] = "U",
+ ["v"] = "V",
+ ["w"] = "W",
+ ["x"] = "X",
+ ["y"] = "Y",
+ ["z"] = "Z",
+ ["µ"] = "Μ",
+ ["à"] = "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["ṙ"] = "Ṙ",
+ ["ṛ"] = "Ṛ",
+ ["ṝ"] = "Ṝ",
+ ["ṟ"] = "Ṟ",
+ ["ṡ"] = "Ṡ",
+ ["ṣ"] = "Ṣ",
+ ["ṥ"] = "Ṥ",
+ ["ṧ"] = "Ṧ",
+ ["ṩ"] = "Ṩ",
+ ["ṫ"] = "Ṫ",
+ ["ṭ"] = "Ṭ",
+ ["ṯ"] = "Ṯ",
+ ["ṱ"] = "Ṱ",
+ ["ṳ"] = "Ṳ",
+ ["ṵ"] = "Ṵ",
+ ["ṷ"] = "Ṷ",
+ ["ṹ"] = "Ṹ",
+ ["ṻ"] = "Ṻ",
+ ["ṽ"] = "Ṽ",
+ ["ṿ"] = "Ṿ",
+ ["ẁ"] = "Ẁ",
+ ["ẃ"] = "Ẃ",
+ ["ẅ"] = "Ẅ",
+ ["ẇ"] = "Ẇ",
+ ["ẉ"] = "Ẉ",
+ ["ẋ"] = "Ẋ",
+ ["ẍ"] = "Ẍ",
+ ["ẏ"] = "Ẏ",
+ ["ẑ"] = "Ẑ",
+ ["ẓ"] = "Ẓ",
+ ["ẕ"] = "Ẕ",
+ ["ẛ"] = "Ṡ",
+ ["ạ"] = "Ạ",
+ ["ả"] = "Ả",
+ ["ấ"] = "Ấ",
+ ["ầ"] = "Ầ",
+ ["ẩ"] = "Ẩ",
+ ["ẫ"] = "Ẫ",
+ ["ậ"] = "Ậ",
+ ["ắ"] = "Ắ",
+ ["ằ"] = "Ằ",
+ ["ẳ"] = "Ẳ",
+ ["ẵ"] = "Ẵ",
+ ["ặ"] = "Ặ",
+ ["ẹ"] = "Ẹ",
+ ["ẻ"] = "Ẻ",
+ ["ẽ"] = "Ẽ",
+ ["ế"] = "Ế",
+ ["ề"] = "Ề",
+ ["ể"] = "Ể",
+ ["ễ"] = "Ễ",
+ ["ệ"] = "Ệ",
+ ["ỉ"] = "Ỉ",
+ ["ị"] = "Ị",
+ ["ọ"] = "Ọ",
+ ["ỏ"] = "Ỏ",
+ ["ố"] = "Ố",
+ ["ồ"] = "Ồ",
+ ["ổ"] = "Ổ",
+ ["ỗ"] = "Ỗ",
+ ["ộ"] = "Ộ",
+ ["ớ"] = "Ớ",
+ ["ờ"] = "Ờ",
+ ["ở"] = "Ở",
+ ["ỡ"] = "Ỡ",
+ ["ợ"] = "Ợ",
+ ["ụ"] = "Ụ",
+ ["ủ"] = "Ủ",
+ ["ứ"] = "Ứ",
+ ["ừ"] = "Ừ",
+ ["ử"] = "Ử",
+ ["ữ"] = "Ữ",
+ ["ự"] = "Ự",
+ ["ỳ"] = "Ỳ",
+ ["ỵ"] = "Ỵ",
+ ["ỷ"] = "Ỷ",
+ ["ỹ"] = "Ỹ",
+ ["ἀ"] = "Ἀ",
+ ["ἁ"] = "Ἁ",
+ ["ἂ"] = "Ἂ",
+ ["ἃ"] = "Ἃ",
+ ["ἄ"] = "Ἄ",
+ ["ἅ"] = "Ἅ",
+ ["ἆ"] = "Ἆ",
+ ["ἇ"] = "Ἇ",
+ ["ἐ"] = "Ἐ",
+ ["ἑ"] = "Ἑ",
+ ["ἒ"] = "Ἒ",
+ ["ἓ"] = "Ἓ",
+ ["ἔ"] = "Ἔ",
+ ["ἕ"] = "Ἕ",
+ ["ἠ"] = "Ἠ",
+ ["ἡ"] = "Ἡ",
+ ["ἢ"] = "Ἢ",
+ ["ἣ"] = "Ἣ",
+ ["ἤ"] = "Ἤ",
+ ["ἥ"] = "Ἥ",
+ ["ἦ"] = "Ἦ",
+ ["ἧ"] = "Ἧ",
+ ["ἰ"] = "Ἰ",
+ ["ἱ"] = "Ἱ",
+ ["ἲ"] = "Ἲ",
+ ["ἳ"] = "Ἳ",
+ ["ἴ"] = "Ἴ",
+ ["ἵ"] = "Ἵ",
+ ["ἶ"] = "Ἶ",
+ ["ἷ"] = "Ἷ",
+ ["ὀ"] = "Ὀ",
+ ["ὁ"] = "Ὁ",
+ ["ὂ"] = "Ὂ",
+ ["ὃ"] = "Ὃ",
+ ["ὄ"] = "Ὄ",
+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ᾼ",
+ ["ι"] = "Ι",
+ ["ῃ"] = "ῌ",
+ ["ῐ"] = "Ῐ",
+ ["ῑ"] = "Ῑ",
+ ["ῠ"] = "Ῠ",
+ ["ῡ"] = "Ῡ",
+ ["ῥ"] = "Ῥ",
+ ["ῳ"] = "ῼ",
+ ["ⅎ"] = "Ⅎ",
+ ["ⅰ"] = "Ⅰ",
+ ["ⅱ"] = "Ⅱ",
+ ["ⅲ"] = "Ⅲ",
+ ["ⅳ"] = "Ⅳ",
+ ["ⅴ"] = "Ⅴ",
+ ["ⅵ"] = "Ⅵ",
+ ["ⅶ"] = "Ⅶ",
+ ["ⅷ"] = "Ⅷ",
+ ["ⅸ"] = "Ⅸ",
+ ["ⅹ"] = "Ⅹ",
+ ["ⅺ"] = "Ⅺ",
+ ["ⅻ"] = "Ⅻ",
+ ["ⅼ"] = "Ⅼ",
+ ["ⅽ"] = "Ⅽ",
+ ["ⅾ"] = "Ⅾ",
+ ["ⅿ"] = "Ⅿ",
+ ["ↄ"] = "Ↄ",
+ ["ⓐ"] = "Ⓐ",
+ ["ⓑ"] = "Ⓑ",
+ ["ⓒ"] = "Ⓒ",
+ ["ⓓ"] = "Ⓓ",
+ ["ⓔ"] = "Ⓔ",
+ ["ⓕ"] = "Ⓕ",
+ ["ⓖ"] = "Ⓖ",
+ ["ⓗ"] = "Ⓗ",
+ ["ⓘ"] = "Ⓘ",
+ ["ⓙ"] = "Ⓙ",
+ ["ⓚ"] = "Ⓚ",
+ ["ⓛ"] = "Ⓛ",
+ ["ⓜ"] = "Ⓜ",
+ ["ⓝ"] = "Ⓝ",
+ ["ⓞ"] = "Ⓞ",
+ ["ⓟ"] = "Ⓟ",
+ ["ⓠ"] = "Ⓠ",
+ ["ⓡ"] = "Ⓡ",
+ ["ⓢ"] = "Ⓢ",
+ ["ⓣ"] = "Ⓣ",
+ ["ⓤ"] = "Ⓤ",
+ ["ⓥ"] = "Ⓥ",
+ ["ⓦ"] = "Ⓦ",
+ ["ⓧ"] = "Ⓧ",
+ ["ⓨ"] = "Ⓨ",
+ ["ⓩ"] = "Ⓩ",
+ ["ⰰ"] = "Ⰰ",
+ ["ⰱ"] = "Ⰱ",
+ ["ⰲ"] = "Ⰲ",
+ ["ⰳ"] = "Ⰳ",
+ ["ⰴ"] = "Ⰴ",
+ ["ⰵ"] = "Ⰵ",
+ ["ⰶ"] = "Ⰶ",
+ ["ⰷ"] = "Ⰷ",
+ ["ⰸ"] = "Ⰸ",
+ ["ⰹ"] = "Ⰹ",
+ ["ⰺ"] = "Ⰺ",
+ ["ⰻ"] = "Ⰻ",
+ ["ⰼ"] = "Ⰼ",
+ ["ⰽ"] = "Ⰽ",
+ ["ⰾ"] = "Ⰾ",
+ ["ⰿ"] = "Ⰿ",
+ ["ⱀ"] = "Ⱀ",
+ ["ⱁ"] = "Ⱁ",
+ ["ⱂ"] = "Ⱂ",
+ ["ⱃ"] = "Ⱃ",
+ ["ⱄ"] = "Ⱄ",
+ ["ⱅ"] = "Ⱅ",
+ ["ⱆ"] = "Ⱆ",
+ ["ⱇ"] = "Ⱇ",
+ ["ⱈ"] = "Ⱈ",
+ ["ⱉ"] = "Ⱉ",
+ ["ⱊ"] = "Ⱊ",
+ ["ⱋ"] = "Ⱋ",
+ ["ⱌ"] = "Ⱌ",
+ ["ⱍ"] = "Ⱍ",
+ ["ⱎ"] = "Ⱎ",
+ ["ⱏ"] = "Ⱏ",
+ ["ⱐ"] = "Ⱐ",
+ ["ⱑ"] = "Ⱑ",
+ ["ⱒ"] = "Ⱒ",
+ ["ⱓ"] = "Ⱓ",
+ ["ⱔ"] = "Ⱔ",
+ ["ⱕ"] = "Ⱕ",
+ ["ⱖ"] = "Ⱖ",
+ ["ⱗ"] = "Ⱗ",
+ ["ⱘ"] = "Ⱘ",
+ ["ⱙ"] = "Ⱙ",
+ ["ⱚ"] = "Ⱚ",
+ ["ⱛ"] = "Ⱛ",
+ ["ⱜ"] = "Ⱜ",
+ ["ⱝ"] = "Ⱝ",
+ ["ⱞ"] = "Ⱞ",
+ ["ⱡ"] = "Ⱡ",
+ ["ⱥ"] = "Ⱥ",
+ ["ⱦ"] = "Ⱦ",
+ ["ⱨ"] = "Ⱨ",
+ ["ⱪ"] = "Ⱪ",
+ ["ⱬ"] = "Ⱬ",
+ ["ⱶ"] = "Ⱶ",
+ ["ⲁ"] = "Ⲁ",
+ ["ⲃ"] = "Ⲃ",
+ ["ⲅ"] = "Ⲅ",
+ ["ⲇ"] = "Ⲇ",
+ ["ⲉ"] = "Ⲉ",
+ ["ⲋ"] = "Ⲋ",
+ ["ⲍ"] = "Ⲍ",
+ ["ⲏ"] = "Ⲏ",
+ ["ⲑ"] = "Ⲑ",
+ ["ⲓ"] = "Ⲓ",
+ ["ⲕ"] = "Ⲕ",
+ ["ⲗ"] = "Ⲗ",
+ ["ⲙ"] = "Ⲙ",
+ ["ⲛ"] = "Ⲛ",
+ ["ⲝ"] = "Ⲝ",
+ ["ⲟ"] = "Ⲟ",
+ ["ⲡ"] = "Ⲡ",
+ ["ⲣ"] = "Ⲣ",
+ ["ⲥ"] = "Ⲥ",
+ ["ⲧ"] = "Ⲧ",
+ ["ⲩ"] = "Ⲩ",
+ ["ⲫ"] = "Ⲫ",
+ ["ⲭ"] = "Ⲭ",
+ ["ⲯ"] = "Ⲯ",
+ ["ⲱ"] = "Ⲱ",
+ ["ⲳ"] = "Ⲳ",
+ ["ⲵ"] = "Ⲵ",
+ ["ⲷ"] = "Ⲷ",
+ ["ⲹ"] = "Ⲹ",
+ ["ⲻ"] = "Ⲻ",
+ ["ⲽ"] = "Ⲽ",
+ ["ⲿ"] = "Ⲿ",
+ ["ⳁ"] = "Ⳁ",
+ ["ⳃ"] = "Ⳃ",
+ ["ⳅ"] = "Ⳅ",
+ ["ⳇ"] = "Ⳇ",
+ ["ⳉ"] = "Ⳉ",
+ ["ⳋ"] = "Ⳋ",
+ ["ⳍ"] = "Ⳍ",
+ ["ⳏ"] = "Ⳏ",
+ ["ⳑ"] = "Ⳑ",
+ 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d"] = "D",
+ ["e"] = "E",
+ ["f"] = "F",
+ ["g"] = "G",
+ ["h"] = "H",
+ ["i"] = "I",
+ ["j"] = "J",
+ ["k"] = "K",
+ ["l"] = "L",
+ ["m"] = "M",
+ ["n"] = "N",
+ ["o"] = "O",
+ ["p"] = "P",
+ ["q"] = "Q",
+ ["r"] = "R",
+ ["s"] = "S",
+ ["t"] = "T",
+ ["u"] = "U",
+ ["v"] = "V",
+ ["w"] = "W",
+ ["x"] = "X",
+ ["y"] = "Y",
+ ["z"] = "Z",
+ ["𐐨"] = "𐐀",
+ ["𐐩"] = "𐐁",
+ ["𐐪"] = "𐐂",
+ ["𐐫"] = "𐐃",
+ ["𐐬"] = "𐐄",
+ ["𐐭"] = "𐐅",
+ ["𐐮"] = "𐐆",
+ ["𐐯"] = "𐐇",
+ ["𐐰"] = "𐐈",
+ ["𐐱"] = "𐐉",
+ ["𐐲"] = "𐐊",
+ ["𐐳"] = "𐐋",
+ ["𐐴"] = "𐐌",
+ ["𐐵"] = "𐐍",
+ ["𐐶"] = "𐐎",
+ ["𐐷"] = "𐐏",
+ ["𐐸"] = "𐐐",
+ ["𐐹"] = "𐐑",
+ ["𐐺"] = "𐐒",
+ ["𐐻"] = "𐐓",
+ ["𐐼"] = "𐐔",
+ ["𐐽"] = "𐐕",
+ ["𐐾"] = "𐐖",
+ ["𐐿"] = "𐐗",
+ ["𐑀"] = "𐐘",
+ ["𐑁"] = "𐐙",
+ ["𐑂"] = "𐐚",
+ ["𐑃"] = "𐐛",
+ ["𐑄"] = "𐐜",
+ ["𐑅"] = "𐐝",
+ ["𐑆"] = "𐐞",
+ ["𐑇"] = "𐐟",
+ ["𐑈"] = "𐐠",
+ ["𐑉"] = "𐐡",
+ ["𐑊"] = "𐐢",
+ ["𐑋"] = "𐐣",
+ ["𐑌"] = "𐐤",
+ ["𐑍"] = "𐐥",
+ ["𐑎"] = "𐐦",
+ ["𐑏"] = "𐐧",
+}
+
+
+utf8_uc_lc = {
+ ["A"] = "a",
+ ["B"] = "b",
+ ["C"] = "c",
+ ["D"] = "d",
+ ["E"] = "e",
+ ["F"] = "f",
+ ["G"] = "g",
+ ["H"] = "h",
+ ["I"] = "i",
+ ["J"] = "j",
+ ["K"] = "k",
+ ["L"] = "l",
+ ["M"] = "m",
+ ["N"] = "n",
+ ["O"] = "o",
+ ["P"] = "p",
+ ["Q"] = "q",
+ ["R"] = "r",
+ ["S"] = "s",
+ ["T"] = "t",
+ ["U"] = "u",
+ ["V"] = "v",
+ ["W"] = "w",
+ ["X"] = "x",
+ ["Y"] = "y",
+ ["Z"] = "z",
+ ["À"] = "à",
+ ["Á"] = "á",
+ ["Â"] = "â",
+ ["Ã"] = "ã",
+ ["Ä"] = "ä",
+ ["Å"] = "å",
+ ["Æ"] = "æ",
+ ["Ç"] = "ç",
+ ["È"] = "è",
+ ["É"] = "é",
+ ["Ê"] = "ê",
+ ["Ë"] = "ë",
+ ["Ì"] = "ì",
+ ["Í"] = "í",
+ ["Î"] = "î",
+ ["Ï"] = "ï",
+ ["Ð"] = "ð",
+ ["Ñ"] = "ñ",
+ ["Ò"] = "ò",
+ ["Ó"] = "ó",
+ ["Ô"] = "ô",
+ ["Õ"] = "õ",
+ ["Ö"] = "ö",
+ ["Ø"] = "ø",
+ ["Ù"] = "ù",
+ ["Ú"] = "ú",
+ ["Û"] = "û",
+ ["Ü"] = "ü",
+ ["Ý"] = "ý",
+ ["Þ"] = "þ",
+ ["Ā"] = "ā",
+ ["Ă"] = "ă",
+ ["Ą"] = "ą",
+ ["Ć"] = "ć",
+ ["Ĉ"] = "ĉ",
+ ["Ċ"] = "ċ",
+ ["Č"] = "č",
+ ["Ď"] = "ď",
+ ["Đ"] = "đ",
+ ["Ē"] = "ē",
+ ["Ĕ"] = "ĕ",
+ ["Ė"] = "ė",
+ ["Ę"] = "ę",
+ ["Ě"] = "ě",
+ ["Ĝ"] = "ĝ",
+ ["Ğ"] = "ğ",
+ ["Ġ"] = "ġ",
+ ["Ģ"] = "ģ",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 ["Ⴡ"] = "ⴡ",
+ ["Ⴢ"] = "ⴢ",
+ ["Ⴣ"] = "ⴣ",
+ ["Ⴤ"] = "ⴤ",
+ ["Ⴥ"] = "ⴥ",
+ ["Ḁ"] = "ḁ",
+ ["Ḃ"] = "ḃ",
+ ["Ḅ"] = "ḅ",
+ ["Ḇ"] = "ḇ",
+ ["Ḉ"] = "ḉ",
+ ["Ḋ"] = "ḋ",
+ ["Ḍ"] = "ḍ",
+ ["Ḏ"] = "ḏ",
+ ["Ḑ"] = "ḑ",
+ ["Ḓ"] = "ḓ",
+ ["Ḕ"] = "ḕ",
+ ["Ḗ"] = "ḗ",
+ ["Ḙ"] = "ḙ",
+ ["Ḛ"] = "ḛ",
+ ["Ḝ"] = "ḝ",
+ ["Ḟ"] = "ḟ",
+ ["Ḡ"] = "ḡ",
+ ["Ḣ"] = "ḣ",
+ ["Ḥ"] = "ḥ",
+ ["Ḧ"] = "ḧ",
+ ["Ḩ"] = "ḩ",
+ ["Ḫ"] = "ḫ",
+ ["Ḭ"] = "ḭ",
+ ["Ḯ"] = "ḯ",
+ ["Ḱ"] = "ḱ",
+ ["Ḳ"] = "ḳ",
+ ["Ḵ"] = "ḵ",
+ ["Ḷ"] = "ḷ",
+ ["Ḹ"] = "ḹ",
+ ["Ḻ"] = "ḻ",
+ ["Ḽ"] = "ḽ",
+ ["Ḿ"] = "ḿ",
+ ["Ṁ"] = "ṁ",
+ ["Ṃ"] = "ṃ",
+ ["Ṅ"] = "ṅ",
+ ["Ṇ"] = "ṇ",
+ ["Ṉ"] = "ṉ",
+ ["Ṋ"] = "ṋ",
+ ["Ṍ"] = "ṍ",
+ ["Ṏ"] = "ṏ",
+ ["Ṑ"] = "ṑ",
+ ["Ṓ"] = "ṓ",
+ ["Ṕ"] = "ṕ",
+ ["Ṗ"] = "ṗ",
+ ["Ṙ"] = "ṙ",
+ ["Ṛ"] = "ṛ",
+ ["Ṝ"] = "ṝ",
+ ["Ṟ"] = "ṟ",
+ ["Ṡ"] = "ṡ",
+ ["Ṣ"] = "ṣ",
+ ["Ṥ"] = "ṥ",
+ ["Ṧ"] = "ṧ",
+ ["Ṩ"] = "ṩ",
+ ["Ṫ"] = "ṫ",
+ ["Ṭ"] = "ṭ",
+ ["Ṯ"] = "ṯ",
+ ["Ṱ"] = "ṱ",
+ ["Ṳ"] = "ṳ",
+ ["Ṵ"] = "ṵ",
+ ["Ṷ"] = "ṷ",
+ ["Ṹ"] = "ṹ",
+ ["Ṻ"] = "ṻ",
+ ["Ṽ"] = "ṽ",
+ ["Ṿ"] = "ṿ",
+ ["Ẁ"] = "ẁ",
+ ["Ẃ"] = "ẃ",
+ ["Ẅ"] = "ẅ",
+ ["Ẇ"] = "ẇ",
+ ["Ẉ"] = "ẉ",
+ ["Ẋ"] = "ẋ",
+ ["Ẍ"] = "ẍ",
+ ["Ẏ"] = "ẏ",
+ ["Ẑ"] = "ẑ",
+ ["Ẓ"] = "ẓ",
+ ["Ẕ"] = "ẕ",
+ ["Ạ"] = "ạ",
+ ["Ả"] = "ả",
+ ["Ấ"] = "ấ",
+ ["Ầ"] = "ầ",
+ ["Ẩ"] = "ẩ",
+ ["Ẫ"] = "ẫ",
+ ["Ậ"] = "ậ",
+ ["Ắ"] = "ắ",
+ ["Ằ"] = "ằ",
+ ["Ẳ"] = "ẳ",
+ ["Ẵ"] = "ẵ",
+ ["Ặ"] = "ặ",
+ ["Ẹ"] = "ẹ",
+ ["Ẻ"] = "ẻ",
+ ["Ẽ"] = "ẽ",
+ ["Ế"] = "ế",
+ ["Ề"] = "ề",
+ ["Ể"] = "ể",
+ ["Ễ"] = "ễ",
+ ["Ệ"] = "ệ",
+ ["Ỉ"] = "ỉ",
+ ["Ị"] = "ị",
+ ["Ọ"] = "ọ",
+ ["Ỏ"] = "ỏ",
+ ["Ố"] = "ố",
+ ["Ồ"] = "ồ",
+ ["Ổ"] = "ổ",
+ ["Ỗ"] = "ỗ",
+ ["Ộ"] = "ộ",
+ ["Ớ"] = "ớ",
+ ["Ờ"] = "ờ",
+ ["Ở"] = "ở",
+ ["Ỡ"] = "ỡ",
+ ["Ợ"] = "ợ",
+ ["Ụ"] = "ụ",
+ ["Ủ"] = "ủ",
+ ["Ứ"] = "ứ",
+ ["Ừ"] = "ừ",
+ ["Ử"] = "ử",
+ ["Ữ"] = "ữ",
+ ["Ự"] = "ự",
+ ["Ỳ"] = "ỳ",
+ ["Ỵ"] = "ỵ",
+ ["Ỷ"] = "ỷ",
+ ["Ỹ"] = "ỹ",
+ ["Ἀ"] = "ἀ",
+ ["Ἁ"] = "ἁ",
+ ["Ἂ"] = "ἂ",
+ ["Ἃ"] = "ἃ",
+ ["Ἄ"] = "ἄ",
+ ["Ἅ"] = "ἅ",
+ ["Ἆ"] = "ἆ",
+ ["Ἇ"] = "ἇ",
+ ["Ἐ"] = "ἐ",
+ ["Ἑ"] = "ἑ",
+ ["Ἒ"] = "ἒ",
+ ["Ἓ"] = "ἓ",
+ ["Ἔ"] = "ἔ",
+ ["Ἕ"] = "ἕ",
+ ["Ἠ"] = "ἠ",
+ ["Ἡ"] = "ἡ",
+ ["Ἢ"] = "ἢ",
+ ["Ἣ"] = "ἣ",
+ ["Ἤ"] = "ἤ",
+ ["Ἥ"] = "ἥ",
+ ["Ἦ"] = "ἦ",
+ ["Ἧ"] = "ἧ",
+ ["Ἰ"] = "ἰ",
+ ["Ἱ"] = "ἱ",
+ ["Ἲ"] = "ἲ",
+ ["Ἳ"] = "ἳ",
+ ["Ἴ"] = "ἴ",
+ ["Ἵ"] = "ἵ",
+ ["Ἶ"] = "ἶ",
+ ["Ἷ"] = "ἷ",
+ ["Ὀ"] = "ὀ",
+ ["Ὁ"] = "ὁ",
+ ["Ὂ"] = "ὂ",
+ ["Ὃ"] = "ὃ",
+ ["Ὄ"] = "ὄ",
+ ["Ὅ"] = "ὅ",
+ ["Ὑ"] = "ὑ",
+ ["Ὓ"] = "ὓ",
+ ["Ὕ"] = "ὕ",
+ ["Ὗ"] = "ὗ",
+ ["Ὠ"] = "ὠ",
+ ["Ὡ"] = "ὡ",
+ ["Ὢ"] = "ὢ",
+ ["Ὣ"] = "ὣ",
+ ["Ὤ"] = "ὤ",
+ ["Ὥ"] = "ὥ",
+ ["Ὦ"] = "ὦ",
+ ["Ὧ"] = "ὧ",
+ ["ᾈ"] = "ᾀ",
+ ["ᾉ"] = "ᾁ",
+ ["ᾊ"] = "ᾂ",
+ ["ᾋ"] = "ᾃ",
+ ["ᾌ"] = "ᾄ",
+ ["ᾍ"] = "ᾅ",
+ ["ᾎ"] = "ᾆ",
+ ["ᾏ"] = "ᾇ",
+ ["ᾘ"] = "ᾐ",
+ ["ᾙ"] = "ᾑ",
+ ["ᾚ"] = "ᾒ",
+ ["ᾛ"] = "ᾓ",
+ ["ᾜ"] = "ᾔ",
+ ["ᾝ"] = "ᾕ",
+ ["ᾞ"] = "ᾖ",
+ ["ᾟ"] = "ᾗ",
+ ["ᾨ"] = "ᾠ",
+ ["ᾩ"] = "ᾡ",
+ ["ᾪ"] = "ᾢ",
+ ["ᾫ"] = "ᾣ",
+ ["ᾬ"] = "ᾤ",
+ ["ᾭ"] = "ᾥ",
+ ["ᾮ"] = "ᾦ",
+ ["ᾯ"] = "ᾧ",
+ ["Ᾰ"] = "ᾰ",
+ ["Ᾱ"] = "ᾱ",
+ ["Ὰ"] = "ὰ",
+ ["Ά"] = "ά",
+ ["ᾼ"] = "ᾳ",
+ ["Ὲ"] = "ὲ",
+ ["Έ"] = "έ",
+ ["Ὴ"] = "ὴ",
+ ["Ή"] = "ή",
+ ["ῌ"] = "ῃ",
+ ["Ῐ"] = "ῐ",
+ ["Ῑ"] = "ῑ",
+ ["Ὶ"] = "ὶ",
+ ["Ί"] = "ί",
+ ["Ῠ"] = "ῠ",
+ ["Ῡ"] = "ῡ",
+ ["Ὺ"] = "ὺ",
+ ["Ύ"] = "ύ",
+ ["Ῥ"] = "ῥ",
+ ["Ὸ"] = "ὸ",
+ ["Ό"] = "ό",
+ ["Ὼ"] = "ὼ",
+ ["Ώ"] = "ώ",
+ ["ῼ"] = "ῳ",
+ ["Ω"] = "ω",
+ ["K"] = "k",
+ ["Å"] = "å",
+ ["Ⅎ"] = "ⅎ",
+ ["Ⅰ"] = "ⅰ",
+ ["Ⅱ"] = "ⅱ",
+ ["Ⅲ"] = "ⅲ",
+ ["Ⅳ"] = "ⅳ",
+ ["Ⅴ"] = "ⅴ",
+ ["Ⅵ"] = "ⅵ",
+ ["Ⅶ"] = "ⅶ",
+ ["Ⅷ"] = "ⅷ",
+ ["Ⅸ"] = "ⅸ",
+ ["Ⅹ"] = "ⅹ",
+ ["Ⅺ"] = "ⅺ",
+ ["Ⅻ"] = "ⅻ",
+ ["Ⅼ"] = "ⅼ",
+ ["Ⅽ"] = "ⅽ",
+ ["Ⅾ"] = "ⅾ",
+ ["Ⅿ"] = "ⅿ",
+ ["Ↄ"] = "ↄ",
+ ["Ⓐ"] = "ⓐ",
+ ["Ⓑ"] = "ⓑ",
+ ["Ⓒ"] = "ⓒ",
+ ["Ⓓ"] = "ⓓ",
+ ["Ⓔ"] = "ⓔ",
+ ["Ⓕ"] = "ⓕ",
+ ["Ⓖ"] = "ⓖ",
+ ["Ⓗ"] = "ⓗ",
+ ["Ⓘ"] = "ⓘ",
+ ["Ⓙ"] = "ⓙ",
+ ["Ⓚ"] = "ⓚ",
+ ["Ⓛ"] = "ⓛ",
+ ["Ⓜ"] = "ⓜ",
+ ["Ⓝ"] = "ⓝ",
+ ["Ⓞ"] = "ⓞ",
+ ["Ⓟ"] = "ⓟ",
+ ["Ⓠ"] = "ⓠ",
+ ["Ⓡ"] = "ⓡ",
+ ["Ⓢ"] = "ⓢ",
+ ["Ⓣ"] = "ⓣ",
+ ["Ⓤ"] = "ⓤ",
+ ["Ⓥ"] = "ⓥ",
+ ["Ⓦ"] = "ⓦ",
+ ["Ⓧ"] = "ⓧ",
+ ["Ⓨ"] = "ⓨ",
+ ["Ⓩ"] = "ⓩ",
+ ["Ⰰ"] = "ⰰ",
+ ["Ⰱ"] = "ⰱ",
+ ["Ⰲ"] = "ⰲ",
+ ["Ⰳ"] = "ⰳ",
+ ["Ⰴ"] = "ⰴ",
+ ["Ⰵ"] = "ⰵ",
+ ["Ⰶ"] = "ⰶ",
+ ["Ⰷ"] = "ⰷ",
+ ["Ⰸ"] = "ⰸ",
+ ["Ⰹ"] = "ⰹ",
+ ["Ⰺ"] = "ⰺ",
+ ["Ⰻ"] = "ⰻ",
+ ["Ⰼ"] = "ⰼ",
+ ["Ⰽ"] = "ⰽ",
+ ["Ⰾ"] = "ⰾ",
+ ["Ⰿ"] = "ⰿ",
+ ["Ⱀ"] = "ⱀ",
+ ["Ⱁ"] = "ⱁ",
+ ["Ⱂ"] = "ⱂ",
+ ["Ⱃ"] = "ⱃ",
+ ["Ⱄ"] = "ⱄ",
+ ["Ⱅ"] = "ⱅ",
+ ["Ⱆ"] = "ⱆ",
+ ["Ⱇ"] = "ⱇ",
+ ["Ⱈ"] = "ⱈ",
+ ["Ⱉ"] = "ⱉ",
+ ["Ⱊ"] = "ⱊ",
+ ["Ⱋ"] = "ⱋ",
+ ["Ⱌ"] = "ⱌ",
+ ["Ⱍ"] = "ⱍ",
+ ["Ⱎ"] = "ⱎ",
+ ["Ⱏ"] = "ⱏ",
+ ["Ⱐ"] = "ⱐ",
+ ["Ⱑ"] = "ⱑ",
+ ["Ⱒ"] = "ⱒ",
+ ["Ⱓ"] = "ⱓ",
+ ["Ⱔ"] = "ⱔ",
+ ["Ⱕ"] = "ⱕ",
+ ["Ⱖ"] = "ⱖ",
+ ["Ⱗ"] = "ⱗ",
+ ["Ⱘ"] = "ⱘ",
+ ["Ⱙ"] = "ⱙ",
+ ["Ⱚ"] = "ⱚ",
+ ["Ⱛ"] = "ⱛ",
+ ["Ⱜ"] = "ⱜ",
+ ["Ⱝ"] = "ⱝ",
+ ["Ⱞ"] = "ⱞ",
+ ["Ⱡ"] = "ⱡ",
+ ["Ɫ"] = "ɫ",
+ ["Ᵽ"] = "ᵽ",
+ ["Ɽ"] = "ɽ",
+ ["Ⱨ"] = "ⱨ",
+ ["Ⱪ"] = "ⱪ",
+ ["Ⱬ"] = "ⱬ",
+ ["Ⱶ"] = "ⱶ",
+ ["Ⲁ"] = "ⲁ",
+ ["Ⲃ"] = "ⲃ",
+ ["Ⲅ"] = "ⲅ",
+ ["Ⲇ"] = "ⲇ",
+ ["Ⲉ"] = "ⲉ",
+ ["Ⲋ"] = "ⲋ",
+ ["Ⲍ"] = "ⲍ",
+ ["Ⲏ"] = "ⲏ",
+ ["Ⲑ"] = "ⲑ",
+ ["Ⲓ"] = "ⲓ",
+ ["Ⲕ"] = "ⲕ",
+ ["Ⲗ"] = "ⲗ",
+ ["Ⲙ"] = "ⲙ",
+ ["Ⲛ"] = "ⲛ",
+ ["Ⲝ"] = "ⲝ",
+ ["Ⲟ"] = "ⲟ",
+ ["Ⲡ"] = "ⲡ",
+ ["Ⲣ"] = "ⲣ",
+ ["Ⲥ"] = "ⲥ",
+ ["Ⲧ"] = "ⲧ",
+ ["Ⲩ"] = "ⲩ",
+ ["Ⲫ"] = "ⲫ",
+ ["Ⲭ"] = "ⲭ",
+ ["Ⲯ"] = "ⲯ",
+ ["Ⲱ"] = "ⲱ",
+ ["Ⲳ"] = "ⲳ",
+ ["Ⲵ"] = "ⲵ",
+ ["Ⲷ"] = "ⲷ",
+ ["Ⲹ"] = "ⲹ",
+ ["Ⲻ"] = "ⲻ",
+ ["Ⲽ"] = "ⲽ",
+ ["Ⲿ"] = "ⲿ",
+ ["Ⳁ"] = "ⳁ",
+ ["Ⳃ"] = "ⳃ",
+ ["Ⳅ"] = "ⳅ",
+ ["Ⳇ"] = "ⳇ",
+ ["Ⳉ"] = "ⳉ",
+ ["Ⳋ"] = "ⳋ",
+ ["Ⳍ"] = "ⳍ",
+ ["Ⳏ"] = "ⳏ",
+ ["Ⳑ"] = "ⳑ",
+ ["Ⳓ"] = "ⳓ",
+ ["Ⳕ"] = "ⳕ",
+ ["Ⳗ"] = "ⳗ",
+ ["Ⳙ"] = "ⳙ",
+ ["Ⳛ"] = "ⳛ",
+ ["Ⳝ"] = "ⳝ",
+ ["Ⳟ"] = "ⳟ",
+ ["Ⳡ"] = "ⳡ",
+ ["Ⳣ"] = "ⳣ",
+ ["A"] = "a",
+ ["B"] = "b",
+ ["C"] = "c",
+ ["D"] = "d",
+ ["E"] = "e",
+ ["F"] = "f",
+ ["G"] = "g",
+ ["H"] = "h",
+ ["I"] = "i",
+ ["J"] = "j",
+ ["K"] = "k",
+ ["L"] = "l",
+ ["M"] = "m",
+ ["N"] = "n",
+ ["O"] = "o",
+ ["P"] = "p",
+ ["Q"] = "q",
+ ["R"] = "r",
+ ["S"] = "s",
+ ["T"] = "t",
+ ["U"] = "u",
+ ["V"] = "v",
+ ["W"] = "w",
+ ["X"] = "x",
+ ["Y"] = "y",
+ ["Z"] = "z",
+ ["𐐀"] = "𐐨",
+ ["𐐁"] = "𐐩",
+ ["𐐂"] = "𐐪",
+ ["𐐃"] = "𐐫",
+ ["𐐄"] = "𐐬",
+ ["𐐅"] = "𐐭",
+ ["𐐆"] = "𐐮",
+ ["𐐇"] = "𐐯",
+ ["𐐈"] = "𐐰",
+ ["𐐉"] = "𐐱",
+ ["𐐊"] = "𐐲",
+ ["𐐋"] = "𐐳",
+ ["𐐌"] = "𐐴",
+ ["𐐍"] = "𐐵",
+ ["𐐎"] = "𐐶",
+ ["𐐏"] = "𐐷",
+ ["𐐐"] = "𐐸",
+ ["𐐑"] = "𐐹",
+ ["𐐒"] = "𐐺",
+ ["𐐓"] = "𐐻",
+ ["𐐔"] = "𐐼",
+ ["𐐕"] = "𐐽",
+ ["𐐖"] = "𐐾",
+ ["𐐗"] = "𐐿",
+ ["𐐘"] = "𐑀",
+ ["𐐙"] = "𐑁",
+ ["𐐚"] = "𐑂",
+ ["𐐛"] = "𐑃",
+ ["𐐜"] = "𐑄",
+ ["𐐝"] = "𐑅",
+ ["𐐞"] = "𐑆",
+ ["𐐟"] = "𐑇",
+ ["𐐠"] = "𐑈",
+ ["𐐡"] = "𐑉",
+ ["𐐢"] = "𐑊",
+ ["𐐣"] = "𐑋",
+ ["𐐤"] = "𐑌",
+ ["𐐥"] = "𐑍",
+ ["𐐦"] = "𐑎",
+ ["𐐧"] = "𐑏",
+}
+
+
+return {
+ utf8_lc_uc = utf8_lc_uc,
+ utf8_uc_lc = utf8_uc_lc,
+}