exec: Add TTYRows and TTYColumns properties to set TTY dimensions
This commit is contained in:
@@ -857,6 +857,39 @@ unsigned lines(void) {
|
||||
return cached_lines;
|
||||
}
|
||||
|
||||
int terminal_set_size_fd(int fd, const char *ident, unsigned rows, unsigned cols) {
|
||||
struct winsize ws;
|
||||
|
||||
if (rows == UINT_MAX && cols == UINT_MAX)
|
||||
return 0;
|
||||
|
||||
if (ioctl(fd, TIOCGWINSZ, &ws) < 0)
|
||||
return log_debug_errno(errno,
|
||||
"TIOCGWINSZ ioctl for getting %s size failed, not setting terminal size: %m",
|
||||
ident ?: "TTY");
|
||||
|
||||
if (rows == UINT_MAX)
|
||||
rows = ws.ws_row;
|
||||
else if (rows > USHRT_MAX)
|
||||
rows = USHRT_MAX;
|
||||
|
||||
if (cols == UINT_MAX)
|
||||
cols = ws.ws_col;
|
||||
else if (cols > USHRT_MAX)
|
||||
cols = USHRT_MAX;
|
||||
|
||||
if (rows == ws.ws_row && cols == ws.ws_col)
|
||||
return 0;
|
||||
|
||||
ws.ws_row = rows;
|
||||
ws.ws_col = cols;
|
||||
|
||||
if (ioctl(fd, TIOCSWINSZ, &ws) < 0)
|
||||
return log_debug_errno(errno, "TIOCSWINSZ ioctl for setting %s size failed: %m", ident ?: "TTY");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* intended to be used as a SIGWINCH sighandler */
|
||||
void columns_lines_cache_reset(int signum) {
|
||||
cached_columns = 0;
|
||||
|
||||
@@ -120,6 +120,8 @@ int release_terminal(void);
|
||||
int terminal_vhangup_fd(int fd);
|
||||
int terminal_vhangup(const char *name);
|
||||
|
||||
int terminal_set_size_fd(int fd, const char *ident, unsigned rows, unsigned cols);
|
||||
|
||||
int chvt(int vt);
|
||||
|
||||
int read_one_char(FILE *f, char *ret, usec_t timeout, bool *need_nl);
|
||||
|
||||
Reference in New Issue
Block a user