Added check for tty output
This commit is contained in:
@ -11,7 +11,8 @@
|
||||
using namespace sc;
|
||||
|
||||
term::term(int fd) {
|
||||
if (isatty(fd)) {
|
||||
_isatty = isatty(fd);
|
||||
if (_isatty) {
|
||||
throw_if_min1(ioctl(fd, TIOCGWINSZ, &_ws));
|
||||
}
|
||||
switch (fd) {
|
||||
@ -22,11 +23,11 @@ term::term(int fd) {
|
||||
}
|
||||
|
||||
int term::rows() const {
|
||||
return _ws.ws_row;
|
||||
return _isatty ? _ws.ws_row : 0;
|
||||
}
|
||||
|
||||
int term::cols() const {
|
||||
return _ws.ws_col;
|
||||
return _isatty ? _ws.ws_col : 0;
|
||||
}
|
||||
|
||||
void term::progress(int prefixlen,
|
||||
@ -34,6 +35,8 @@ void term::progress(int prefixlen,
|
||||
double cur,
|
||||
double total) const
|
||||
{
|
||||
if (!_isatty) return;
|
||||
|
||||
// use unicode to make nice bar
|
||||
const char* bar[8] = {
|
||||
u8"\u258F", u8"\u258E", u8"\u258D", u8"\u258C",
|
||||
|
Reference in New Issue
Block a user