Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
CMake
CMake
Commits
6a4071b5
Commit
6a4071b5
authored
Sep 16, 2004
by
Andy Cedilnik
Browse files
ENH: Add method to retrieve the terminal width
parent
d349d6ff
Changes
2
Hide whitespace changes
Inline
Side-by-side
Source/kwsys/SystemTools.cxx
View file @
6a4071b5
...
...
@@ -35,6 +35,8 @@
#include
<stdlib.h>
#include
<sys/param.h>
#include
<sys/wait.h>
#include
<sys/ioctl.h>
#include
<unistd.h>
#endif
#if defined(_WIN32) && (defined(_MSC_VER) || defined(__BORLANDC__) || defined(__MINGW32__))
...
...
@@ -1846,6 +1848,38 @@ bool SystemTools::GetLineFromStream(kwsys_ios::istream& is, kwsys_stl::string& l
return
haveData
;
}
int
SystemTools
::
GetTerminalWidth
()
{
int
width
=
-
1
;
#ifndef _WIN32
struct
winsize
ws
;
char
*
columns
;
/* Unix98 environment variable */
if
(
ioctl
(
1
,
TIOCGWINSZ
,
&
ws
)
!=
-
1
&&
ws
.
ws_col
>
0
&&
ws
.
ws_row
>
0
)
{
width
=
ws
.
ws_col
;
}
if
(
!
isatty
(
STDOUT_FILENO
))
{
width
=
-
1
;
}
columns
=
getenv
(
"COLUMNS"
);
if
(
columns
&&
*
columns
)
{
long
t
;
char
*
endptr
;
t
=
strtol
(
columns
,
&
endptr
,
0
);
if
(
endptr
&&
!*
endptr
&&
(
t
>
0
)
&&
(
t
<
1000
))
{
width
=
(
int
)
t
;
}
}
if
(
width
<
9
)
{
width
=
-
1
;
}
#endif
return
width
;
}
}
// namespace KWSYS_NAMESPACE
#if defined(_MSC_VER) && defined(_DEBUG)
...
...
Source/kwsys/SystemTools.hxx.in
View file @
6a4071b5
...
...
@@ -276,6 +276,13 @@ public:
*/
static bool GetLineFromStream(kwsys_ios::istream& istr, kwsys_stl::string& line,
bool* has_newline=0);
/**
* Get the width of the terminal window. The code may or may not work, so
* make sure you have some resonable defaults prepared if the code returns
* some bogus size.
*/
static int GetTerminalWidth();
protected:
// these two functions can be called from ConvertToOutputPath
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment