Skip to content
Snippets Groups Projects
Commit d0d83805 authored by Nguyen Anh Quynh's avatar Nguyen Anh Quynh
Browse files

cleanup {Windows,Unix}/Process.inc

parent ab450a6b
No related branches found
No related tags found
No related merge requests found
......@@ -255,18 +255,6 @@ std::error_code Process::SafelyCloseFileDescriptor(int FD) {
return std::error_code(EC, std::generic_category());
}
bool Process::StandardInIsUserInput() {
return FileDescriptorIsDisplayed(STDIN_FILENO);
}
bool Process::StandardOutIsDisplayed() {
return FileDescriptorIsDisplayed(STDOUT_FILENO);
}
bool Process::StandardErrIsDisplayed() {
return FileDescriptorIsDisplayed(STDERR_FILENO);
}
bool Process::FileDescriptorIsDisplayed(int fd) {
#if HAVE_ISATTY
return isatty(fd);
......@@ -276,40 +264,6 @@ bool Process::FileDescriptorIsDisplayed(int fd) {
#endif
}
static unsigned getColumns(int FileID) {
// If COLUMNS is defined in the environment, wrap to that many columns.
if (const char *ColumnsStr = std::getenv("COLUMNS")) {
int Columns = std::atoi(ColumnsStr);
if (Columns > 0)
return Columns;
}
unsigned Columns = 0;
#if defined(HAVE_SYS_IOCTL_H) && defined(HAVE_TERMIOS_H)
// Try to determine the width of the terminal.
struct winsize ws;
if (ioctl(FileID, TIOCGWINSZ, &ws) == 0)
Columns = ws.ws_col;
#endif
return Columns;
}
unsigned Process::StandardOutColumns() {
if (!StandardOutIsDisplayed())
return 0;
return getColumns(1);
}
unsigned Process::StandardErrColumns() {
if (!StandardErrIsDisplayed())
return 0;
return getColumns(2);
}
#ifdef HAVE_TERMINFO
// We manually declare these extern functions because finding the correct
// headers from various terminfo, curses, or other sources is harder than
......
......@@ -257,39 +257,11 @@ std::error_code Process::SafelyCloseFileDescriptor(int FD) {
return std::error_code();
}
bool Process::StandardInIsUserInput() {
return FileDescriptorIsDisplayed(0);
}
bool Process::StandardOutIsDisplayed() {
return FileDescriptorIsDisplayed(1);
}
bool Process::StandardErrIsDisplayed() {
return FileDescriptorIsDisplayed(2);
}
bool Process::FileDescriptorIsDisplayed(int fd) {
DWORD Mode; // Unused
return (GetConsoleMode((HANDLE)_get_osfhandle(fd), &Mode) != 0);
}
unsigned Process::StandardOutColumns() {
unsigned Columns = 0;
CONSOLE_SCREEN_BUFFER_INFO csbi;
if (GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi))
Columns = csbi.dwSize.X;
return Columns;
}
unsigned Process::StandardErrColumns() {
unsigned Columns = 0;
CONSOLE_SCREEN_BUFFER_INFO csbi;
if (GetConsoleScreenBufferInfo(GetStdHandle(STD_ERROR_HANDLE), &csbi))
Columns = csbi.dwSize.X;
return Columns;
}
// The terminal always has colors.
bool Process::FileDescriptorHasColors(int fd) {
return FileDescriptorIsDisplayed(fd);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment