History

player/command: add term-size/[w,h] property

There was no way for scripts to know the current size of the terminal, which is essintial if they want to provide a good user experience even without a window.

Christoph Heinrich committed 3 years ago

Commit 0c8f3bc1 parent 0230a0c3 files · +33 −0Browse files

Unified · Split

3 files
  1. DOCS/interface-changes/term-size.txt +1 −0
  2. DOCS/man/input.rst +13 −0
  3. player/command.c +19 −0
DOCS/interface-changes/term-size.txt+1−0
@@ -0,0 +1 @@
1+add `term-size` property
DOCS/man/input.rst+13−0
@@ -2804,6 +2804,19 @@ Property list · 2803 unmodified lines
28042804 Any of these properties may be unavailable or set to dummy values if the
28052805 VO window is not created or visible.
28062806
2807+``term-size``
2808+ The current terminal size.
2809+
2810+ This has two sub-properties.
2811+
2812+ ``term-size/w``
2813+ width of the terminal in cells
2814+ ``term-size/h``
2815+ height of the terminal in cells
2816+
2817+ This property is not observable. Reacting to size changes requires
2818+ polling.
2819+
28072820 ``window-id``
28082821 Read-only - mpv's window id. May not always be available, i.e due to window
28092822 not being opened yet or not being supported by the VO.
player/command.c+19−0
@@ -74,6 +74,7 @@ · 73 unmodified lines
7474
7575 #include "osdep/io.h"
7676 #include "osdep/subprocess.h"
77+#include "osdep/terminal.h"
7778
7879 #include "core.h"
7980
@@ -2886,6 +2887,23 @@ static int mp_property_osd_ass(void *ctx, struct m_property *prop, · 2806 unmodified lines
28862887 return m_property_read_sub(props, action, arg);
28872888 }
28882889
2890+static int mp_property_term_size(void *ctx, struct m_property *prop,
2891+ int action, void *arg)
2892+{
2893+ int w = -1, h = -1;
2894+ terminal_get_size(&w, &h);
2895+ if (w == -1 || h == -1)
2896+ return M_PROPERTY_UNAVAILABLE;
2897+
2898+ struct m_sub_property props[] = {
2899+ {"w", SUB_PROP_INT(w)},
2900+ {"h", SUB_PROP_INT(h)},
2901+ {0}
2902+ };
2903+
2904+ return m_property_read_sub(props, action, arg);
2905+}
2906+
28892907 static int mp_property_mouse_pos(void *ctx, struct m_property *prop,
28902908 int action, void *arg)
28912909 {
@@ -4092,6 +4110,7 @@ static const struct m_property mp_properties_base[] = { · 1200 unmodified lines
40924110 {"input-bindings", mp_property_bindings},
40934111
40944112 {"user-data", mp_property_udata},
4113+ {"term-size", mp_property_term_size},
40954114
40964115 M_PROPERTY_ALIAS("video", "vid"),
40974116 M_PROPERTY_ALIAS("audio", "aid"),

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t