Skip to content

Commit b847872

Browse files
get help width from tty size
1 parent 9d78fd9 commit b847872

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/main.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@
4343
//! Maximum number of registers per type
4444
static constexpr size_t MODBUS_MAX_REGS = 0x10000;
4545

46-
//! Help output line width
47-
static constexpr std::size_t HELP_WIDTH = 120;
48-
4946
//! Default permissions for the created shared memory
5047
static constexpr mode_t DEFAULT_SHM_PERMISSIONS = 0660;
5148

@@ -200,7 +197,15 @@ int main(int argc, char **argv) {
200197

201198
// print usage
202199
if (args.count("help")) {
203-
options.set_width(HELP_WIDTH);
200+
static constexpr std::size_t MIN_HELP_SIZE = 80;
201+
if (isatty(STDIN_FILENO)) {
202+
struct winsize w {};
203+
if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &w) != -1) { // NOLINT
204+
options.set_width(std::max(static_cast<decltype(w.ws_col)>(MIN_HELP_SIZE), w.ws_col));
205+
}
206+
} else {
207+
options.set_width(MIN_HELP_SIZE);
208+
}
204209
#ifdef OS_LINUX
205210
if (isatty(STDIN_FILENO)) {
206211
struct winsize w {};

0 commit comments

Comments
 (0)