Fossil SCM

Add the "fossil test-terminal-size" command.

drh 2020-05-09 12:04 trunk
Commit b241b9c999724307575ef29d52df40f282ced62a91305914520546406c20d1d6
1 file changed +19 -8
+19 -8
--- src/terminal.c
+++ src/terminal.c
@@ -51,12 +51,11 @@
5151
** Under Linux/bash the size info is also available from env $LINES, $COLUMNS.
5252
** Or it can be queried using tput `echo -e "lines\ncols"|tput -S`.
5353
** Technically, this info could be cached, but then we'd need to handle
5454
** SIGWINCH signal to requery the terminal on resize event.
5555
*/
56
-int terminal_get_size(struct TerminalSize *t)
57
-{
56
+int terminal_get_size(TerminalSize *t){
5857
memset(t, 0, sizeof(*t));
5958
6059
#if defined(TIOCGSIZE)
6160
{
6261
struct ttysize ts;
@@ -94,13 +93,12 @@
9493
9594
/*
9695
** Return the terminal's current width in columns when available, otherwise
9796
** return the specified default value.
9897
*/
99
-unsigned int terminal_get_width(unsigned int nDefault)
100
-{
101
- struct TerminalSize ts;
98
+unsigned int terminal_get_width(unsigned int nDefault){
99
+ TerminalSize ts;
102100
if( terminal_get_size(&ts) ){
103101
return ts.nColumns;
104102
}
105103
return nDefault;
106104
}
@@ -107,13 +105,26 @@
107105
108106
/*
109107
** Return the terminal's current height in lines when available, otherwise
110108
** return the specified default value.
111109
*/
112
-unsigned int terminal_get_height(unsigned int nDefault)
113
-{
114
- struct TerminalSize ts;
110
+unsigned int terminal_get_height(unsigned int nDefault){
111
+ TerminalSize ts;
115112
if( terminal_get_size(&ts) ){
116113
return ts.nLines;
117114
}
118115
return nDefault;
119116
}
117
+
118
+/*
119
+** COMMAND: test-terminal-size
120
+**
121
+** Show the size of the terminal window from which the command is launched
122
+** as two integers, the width in charaters and the height in lines.
123
+**
124
+** If the size cannot be determined, two zeros are shown.
125
+*/
126
+void test_terminal_size_cmd(void){
127
+ TerminalSize ts;
128
+ terminal_get_size(&ts);
129
+ fossil_print("%d %d\n", ts.nColumns, ts.nLines);
130
+}
120131
--- src/terminal.c
+++ src/terminal.c
@@ -51,12 +51,11 @@
51 ** Under Linux/bash the size info is also available from env $LINES, $COLUMNS.
52 ** Or it can be queried using tput `echo -e "lines\ncols"|tput -S`.
53 ** Technically, this info could be cached, but then we'd need to handle
54 ** SIGWINCH signal to requery the terminal on resize event.
55 */
56 int terminal_get_size(struct TerminalSize *t)
57 {
58 memset(t, 0, sizeof(*t));
59
60 #if defined(TIOCGSIZE)
61 {
62 struct ttysize ts;
@@ -94,13 +93,12 @@
94
95 /*
96 ** Return the terminal's current width in columns when available, otherwise
97 ** return the specified default value.
98 */
99 unsigned int terminal_get_width(unsigned int nDefault)
100 {
101 struct TerminalSize ts;
102 if( terminal_get_size(&ts) ){
103 return ts.nColumns;
104 }
105 return nDefault;
106 }
@@ -107,13 +105,26 @@
107
108 /*
109 ** Return the terminal's current height in lines when available, otherwise
110 ** return the specified default value.
111 */
112 unsigned int terminal_get_height(unsigned int nDefault)
113 {
114 struct TerminalSize ts;
115 if( terminal_get_size(&ts) ){
116 return ts.nLines;
117 }
118 return nDefault;
119 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120
--- src/terminal.c
+++ src/terminal.c
@@ -51,12 +51,11 @@
51 ** Under Linux/bash the size info is also available from env $LINES, $COLUMNS.
52 ** Or it can be queried using tput `echo -e "lines\ncols"|tput -S`.
53 ** Technically, this info could be cached, but then we'd need to handle
54 ** SIGWINCH signal to requery the terminal on resize event.
55 */
56 int terminal_get_size(TerminalSize *t){
 
57 memset(t, 0, sizeof(*t));
58
59 #if defined(TIOCGSIZE)
60 {
61 struct ttysize ts;
@@ -94,13 +93,12 @@
93
94 /*
95 ** Return the terminal's current width in columns when available, otherwise
96 ** return the specified default value.
97 */
98 unsigned int terminal_get_width(unsigned int nDefault){
99 TerminalSize ts;
 
100 if( terminal_get_size(&ts) ){
101 return ts.nColumns;
102 }
103 return nDefault;
104 }
@@ -107,13 +105,26 @@
105
106 /*
107 ** Return the terminal's current height in lines when available, otherwise
108 ** return the specified default value.
109 */
110 unsigned int terminal_get_height(unsigned int nDefault){
111 TerminalSize ts;
 
112 if( terminal_get_size(&ts) ){
113 return ts.nLines;
114 }
115 return nDefault;
116 }
117
118 /*
119 ** COMMAND: test-terminal-size
120 **
121 ** Show the size of the terminal window from which the command is launched
122 ** as two integers, the width in charaters and the height in lines.
123 **
124 ** If the size cannot be determined, two zeros are shown.
125 */
126 void test_terminal_size_cmd(void){
127 TerminalSize ts;
128 terminal_get_size(&ts);
129 fossil_print("%d %d\n", ts.nColumns, ts.nLines);
130 }
131

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button