summaryrefslogtreecommitdiffstats
path: root/DOCS/lua_examples/status-line.lua
blob: d28bdcc082762762fb4d7793b40b1ac08ce109dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
-- Rebuild the status line as a lua script
-- Be aware that this will require more cpu power!

-- Add a string to the status line
function atsl(s)
    newStatus = newStatus .. s
end

function update_status_line()
    -- Reset the status line
    newStatus = ""

    if mp.get_property_bool("pause") then
        atsl("(Paused) ")
    elseif mp.get_property_bool("paused-for-cache") then
        atsl("(Buffering) ")
    end

    if mp.get_property("vid") ~= "no" then
        atsl("A")
    end
    if mp.get_property("aid") ~= "no" then
        atsl("V")
    end

    atsl(": ")

    atsl(mp.get_property_osd("time-pos"))

    atsl(" / ");
    atsl(mp.get_property_osd("length"));

    atsl(" (")
    atsl(mp.get_property_osd("percent-pos", -1))
    atsl("%)")

    local r = mp.get_property_number("speed", -1)
    if r ~= 1 then
        atsl(string.format(" x%4.2f", r))
    end

    r = mp.get_property_number("avsync", nil)
    if r ~= nil then
        atsl(string.format(" A-V: %7.3f", r))
    end

    r = mp.get_property("total-avsync-change", 0)
    if math.abs(r) > 0.05 then
        atsl(string.format(" ct:%7.3f", r))
    end

    r = mp.get_property_number("drop-frame-count", -1)
    if r > 0 then
        atsl(" Late: ")
        atsl(r)
    end

    r = mp.get_property_number("cache", 0)
    if r > 0 then
        atsl(string.format(" Cache: %d%% ", r))
    end

    -- Set the new status line
    mp.set_property("options/term-status-msg", newStatus)
end

-- Register the event
mp.register_event("tick", update_status_line)