mirror of https://github.com/mpv-player/mpv
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.
This commit is contained in:
parent
0230a0c25a
commit
0c8f3bc73c
|
@ -0,0 +1 @@
|
|||
add `term-size` property
|
|
@ -2804,6 +2804,19 @@ Property list
|
|||
Any of these properties may be unavailable or set to dummy values if the
|
||||
VO window is not created or visible.
|
||||
|
||||
``term-size``
|
||||
The current terminal size.
|
||||
|
||||
This has two sub-properties.
|
||||
|
||||
``term-size/w``
|
||||
width of the terminal in cells
|
||||
``term-size/h``
|
||||
height of the terminal in cells
|
||||
|
||||
This property is not observable. Reacting to size changes requires
|
||||
polling.
|
||||
|
||||
``window-id``
|
||||
Read-only - mpv's window id. May not always be available, i.e due to window
|
||||
not being opened yet or not being supported by the VO.
|
||||
|
|
|
@ -74,6 +74,7 @@
|
|||
|
||||
#include "osdep/io.h"
|
||||
#include "osdep/subprocess.h"
|
||||
#include "osdep/terminal.h"
|
||||
|
||||
#include "core.h"
|
||||
|
||||
|
@ -2886,6 +2887,23 @@ static int mp_property_osd_ass(void *ctx, struct m_property *prop,
|
|||
return m_property_read_sub(props, action, arg);
|
||||
}
|
||||
|
||||
static int mp_property_term_size(void *ctx, struct m_property *prop,
|
||||
int action, void *arg)
|
||||
{
|
||||
int w = -1, h = -1;
|
||||
terminal_get_size(&w, &h);
|
||||
if (w == -1 || h == -1)
|
||||
return M_PROPERTY_UNAVAILABLE;
|
||||
|
||||
struct m_sub_property props[] = {
|
||||
{"w", SUB_PROP_INT(w)},
|
||||
{"h", SUB_PROP_INT(h)},
|
||||
{0}
|
||||
};
|
||||
|
||||
return m_property_read_sub(props, action, arg);
|
||||
}
|
||||
|
||||
static int mp_property_mouse_pos(void *ctx, struct m_property *prop,
|
||||
int action, void *arg)
|
||||
{
|
||||
|
@ -4092,6 +4110,7 @@ static const struct m_property mp_properties_base[] = {
|
|||
{"input-bindings", mp_property_bindings},
|
||||
|
||||
{"user-data", mp_property_udata},
|
||||
{"term-size", mp_property_term_size},
|
||||
|
||||
M_PROPERTY_ALIAS("video", "vid"),
|
||||
M_PROPERTY_ALIAS("audio", "aid"),
|
||||
|
|
Loading…
Reference in New Issue