|
1
|
/* |
|
2
|
** Copyright (c) 2020 D. Richard Hipp |
|
3
|
** |
|
4
|
** This program is free software; you can redistribute it and/or |
|
5
|
** modify it under the terms of the Simplified BSD License (also |
|
6
|
** known as the "2-Clause License" or "FreeBSD License".) |
|
7
|
|
|
8
|
** This program is distributed in the hope that it will be useful, |
|
9
|
** but without any warranty; without even the implied warranty of |
|
10
|
** merchantability or fitness for a particular purpose. |
|
11
|
** |
|
12
|
** Author contact information: |
|
13
|
** [email protected] |
|
14
|
** http://www.hwaci.com/drh/ |
|
15
|
** |
|
16
|
******************************************************************************* |
|
17
|
** |
|
18
|
** This file contains code used to query terminal info |
|
19
|
*/ |
|
20
|
|
|
21
|
#include "config.h" |
|
22
|
#include "terminal.h" |
|
23
|
#include <assert.h> |
|
24
|
#ifdef _WIN32 |
|
25
|
# include <windows.h> |
|
26
|
#else |
|
27
|
#ifdef __EXTENSIONS__ |
|
28
|
#include <termio.h> |
|
29
|
#endif |
|
30
|
#include <sys/ioctl.h> |
|
31
|
#include <stdio.h> |
|
32
|
#include <unistd.h> |
|
33
|
#endif |
|
34
|
|
|
35
|
|
|
36
|
|
|
37
|
#if INTERFACE |
|
38
|
/* |
|
39
|
** Terminal size defined in terms of columns and lines. |
|
40
|
*/ |
|
41
|
struct TerminalSize { |
|
42
|
unsigned int nColumns; /* Number of characters on a single line */ |
|
43
|
unsigned int nLines; /* Number of lines */ |
|
44
|
}; |
|
45
|
VT escapes on terminal. */ |
|
46
|
#endif |
|
47
|
|
|
48
|
|
|
49
|
/* Get the current terminal size by calling a system service. |
|
50
|
** |
|
51
|
** Return 1 on success. This sets the size parameters to the values returned by |
|
52
|
** the system call, when such is supported; set the size to zero otherwise. |
|
53
|
** Return 0 on the system service call failure. |
|
54
|
** |
|
55
|
** Under Linux/bash the size info is also available from env $LINES, $COLUMNS. |
|
56
|
** Or it can be queried using tput `echo -e "lines\ncols"|tput -S`. |
|
57
|
** Technically, this info could be cached, but then we'd need to handle |
|
58
|
** SIGWINCH signal to requery the terminal on resize event. |
|
59
|
*/ |
|
60
|
int terminal_get_size(TerminalSize *t){ |
|
61
|
memset(t, 0, sizeof(*t)); |
|
62
|
char *zNoColor;O, TIOCGSIZE, &tsif( !/* |
|
63
|
** Copyright (c) 2020 Dopyright (c) |