Home

winsize

Winsize refers to the terminal window size data structure used in Unix-like systems to describe the dimensions of a terminal in characters and, optionally, pixels. It is central to programs that need to adapt their text-based user interfaces to the current size of the terminal, such as full-screen editors, pagers, and terminal multiplexers.

The data structure is commonly exposed as struct winsize and typically contains four fields: ws_row for the

Access to the terminal size is performed via the ioctl system call using the TIOCGWINSZ request to

Header declarations for struct winsize appear in system headers such as <sys/ioctl.h>, with some systems providing

Applications relying on winsize include terminal-based editors and applications, screen and tmux, and libraries such as

number
of
text
rows,
ws_col
for
the
number
of
text
columns,
ws_xpixel
for
the
width
in
pixels,
and
ws_ypixel
for
the
height
in
pixels.
The
ws_row
and
ws_col
fields
provide
the
core
dimensions
used
by
layout
and
wrapping
logic,
while
ws_xpixel
and
ws_ypixel
offer
optional
pixel
dimensions
that
may
be
reported
by
some
terminals
or
terminal
emulators.
On
many
systems
the
pixel
fields
may
be
zero
if
pixel
data
is
not
available.
get
the
current
size
and
TIOCSWINSZ
to
set
a
new
size.
A
typical
usage
involves
passing
a
file
descriptor
(often
STDIN_FILENO
or
the
controlling
terminal)
and
a
pointer
to
a
struct
winsize
to
ioctl.
The
resulting
ws_row
and
ws_col
values
are
then
used
to
adjust
interface
layout
accordingly.
related
definitions
in
other
headers
like
<termios.h>.
The
exact
presence
and
layout
of
fields
can
vary
slightly
between
platforms.
ncurses,
all
of
which
use
terminal
dimensions
to
manage
windows,
panels,
and
dynamic
content.