llvm.org GIT mirror llvm / 7d83658
Process: Add sys::Process::FileDescriptorHasColors(). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@160557 91177308-0d34-0410-b5e6-96231b3b80d8 Daniel Dunbar 8 years ago
3 changed file(s) with 22 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
9696 /// the user rather than being put on a pipe or stored in a file.
9797 static bool FileDescriptorIsDisplayed(int fd);
9898
99 /// This function determines if the given file descriptor is displayd and
100 /// supports colors.
101 static bool FileDescriptorHasColors(int fd);
102
99103 /// This function determines the number of columns in the window
100104 /// if standard output is connected to a "tty" or "console"
101105 /// window. If standard output is not connected to a tty or
248248 return false;
249249 }
250250
251 bool Process::FileDescriptorHasColors(int fd) {
252 // A file descriptor has colors if it is displayed and the terminal has
253 // colors.
254 return FileDescriptorIsDisplayed(fd) && terminalHasColors();
255 }
256
251257 bool Process::StandardOutHasColors() {
252 if (!StandardOutIsDisplayed())
253 return false;
254 return terminalHasColors();
258 return FileDescriptorHasColors(STDOUT_FILENO);
255259 }
256260
257261 bool Process::StandardErrHasColors() {
258 if (!StandardErrIsDisplayed())
259 return false;
260 return terminalHasColors();
262 return FileDescriptorHasColors(STDERR_FILENO);
261263 }
262264
263265 bool Process::ColorNeedsFlush() {
152152 return Columns;
153153 }
154154
155 // It always has colors.
155 // The terminal always has colors.
156 bool FileDescriptorHasColors(int fd) {
157 return FileDescriptorIsDisplayed(fd);
158 }
159
160 bool Process::StandardOutHasColors() {
161 return FileDescriptorHasColors(1);
162 }
163
156164 bool Process::StandardErrHasColors() {
157 return StandardErrIsDisplayed();
158 }
159
160 bool Process::StandardOutHasColors() {
161 return StandardOutIsDisplayed();
165 return FileDescriptorHasColors(2);
162166 }
163167
164168 namespace {