Skip to content

Commit 624edbe

Browse files
determine tty width for help output
1 parent b0f1f7f commit 624edbe

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/main.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <csignal>
1515
#include <filesystem>
1616
#include <iostream>
17+
#include <sys/ioctl.h>
1718
#include <sys/resource.h>
1819
#include <sys/signalfd.h>
1920
#include <sysexits.h>
@@ -200,6 +201,16 @@ int main(int argc, char **argv) {
200201
// print usage
201202
if (args.count("help")) {
202203
options.set_width(HELP_WIDTH);
204+
#ifdef OS_LINUX
205+
if (isatty(STDIN_FILENO)) {
206+
struct winsize w {};
207+
if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &w) != -1) { // NOLINT
208+
static constexpr auto MIN_TTY_SIZE = static_cast<decltype(w.ws_col)>(80);
209+
options.set_width(std::max(MIN_TTY_SIZE, w.ws_col));
210+
}
211+
}
212+
#endif
213+
203214
std::cout << options.help() << '\n';
204215
std::cout << '\n';
205216
std::cout << "The modbus registers are mapped to shared memory objects:" << '\n';

0 commit comments

Comments
 (0)