File tree Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Original file line number Diff line number Diff line change 12
12
#include < filesystem>
13
13
#include < iostream>
14
14
#include < memory>
15
+ #include < sys/ioctl.h>
15
16
#include < sysexits.h>
16
17
17
- // ! Help output line width
18
- static constexpr std::size_t HELP_WIDTH = 120 ;
19
-
20
18
int main (int argc, char **argv) {
21
19
const std::string exe_name = std::filesystem::path (*argv).filename ().string ();
22
20
cxxopts::Options options (exe_name, " Writes the content of stdin to a named shared memory." );
@@ -61,7 +59,15 @@ int main(int argc, char **argv) {
61
59
62
60
// print usage
63
61
if (args.count (" help" )) {
64
- options.set_width (HELP_WIDTH);
62
+ static constexpr std::size_t MIN_HELP_SIZE = 80 ;
63
+ if (isatty (STDIN_FILENO)) {
64
+ struct winsize w {};
65
+ if (ioctl (STDOUT_FILENO, TIOCGWINSZ, &w) != -1 ) { // NOLINT
66
+ options.set_width (std::max (static_cast <decltype (w.ws_col )>(MIN_HELP_SIZE), w.ws_col ));
67
+ }
68
+ } else {
69
+ options.set_width (MIN_HELP_SIZE);
70
+ }
65
71
std::cout << options.help () << ' \n ' ;
66
72
std::cout << " This application uses the following libraries:" << ' \n ' ;
67
73
std::cout << " - cxxopts by jarro2783 (https://github.com/jarro2783/cxxopts)" << ' \n ' ;
You can’t perform that action at this time.
0 commit comments