/src/wxwidgets/include/wx/private/terminal.h
Line | Count | Source |
1 | | /////////////////////////////////////////////////////////////////////////////// |
2 | | // Name: wx/private/terminal.h |
3 | | // Purpose: Helpers for working with terminal output |
4 | | // Author: Vadim Zeitlin |
5 | | // Created: 2024-11-22 |
6 | | // Copyright: (c) 2024 Vadim Zeitlin <vadim@wxwidgets.org> |
7 | | // Licence: wxWindows licence |
8 | | /////////////////////////////////////////////////////////////////////////////// |
9 | | |
10 | | #ifndef _WX_PRIVATE_TERMINAL_H_ |
11 | | #define _WX_PRIVATE_TERMINAL_H_ |
12 | | |
13 | | #ifdef __WINDOWS__ |
14 | | #include "wx/utils.h" |
15 | | |
16 | | #include "wx/msw/wrapwin.h" |
17 | | #endif |
18 | | |
19 | | #ifdef __UNIX__ |
20 | | #include <stdio.h> |
21 | | #include <unistd.h> |
22 | | #include <sys/ioctl.h> |
23 | | #endif |
24 | | |
25 | | namespace wxTerminal |
26 | | { |
27 | | |
28 | | // Return the current terminal width or 0 if we couldn't find it. |
29 | | inline int GetWidth() |
30 | 0 | { |
31 | | #ifdef __WINDOWS__ |
32 | | CONSOLE_SCREEN_BUFFER_INFO csbi; |
33 | | if ( ::GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi) ) |
34 | | return csbi.srWindow.Right - csbi.srWindow.Left + 1; |
35 | | #elif defined TIOCGWINSZ |
36 | | winsize w; |
37 | 0 | int fd = fileno(stdout); |
38 | 0 | if ( fd != -1 && ioctl(fd, TIOCGWINSZ, &w) == 0 ) |
39 | 0 | return w.ws_col; |
40 | 0 | #endif |
41 | | |
42 | 0 | return 0; |
43 | 0 | } |
44 | | |
45 | | } // namespace wxTerminal |
46 | | |
47 | | #endif // _WX_PRIVATE_TERMINAL_H_ |