Skip to content

Commit 3b3cee7

Browse files
Merge pull request #12 from NikolasK-source/main
update to 1.1.1
2 parents 1f17630 + f04d0f0 commit 3b3cee7

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 3.22.0 FATAL_ERROR)
44
# ======================================================================================================================
55

66
# project
7-
project(write-shm LANGUAGES CXX VERSION 1.1.0)
7+
project(write-shm LANGUAGES CXX VERSION 1.1.1)
88

99
# settings
1010
set(Target "write-shm") # Executable name (without file extension!)

src/main.cpp

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@
1212
#include <filesystem>
1313
#include <iostream>
1414
#include <memory>
15+
#include <sys/ioctl.h>
1516
#include <sysexits.h>
1617

17-
//! Help output line width
18-
static constexpr std::size_t HELP_WIDTH = 120;
19-
2018
int main(int argc, char **argv) {
2119
const std::string exe_name = std::filesystem::path(*argv).filename().string();
2220
cxxopts::Options options(exe_name, "Writes the content of stdin to a named shared memory.");
@@ -61,24 +59,22 @@ int main(int argc, char **argv) {
6159

6260
// print usage
6361
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+
}
6571
std::cout << options.help() << '\n';
6672
std::cout << "This application uses the following libraries:" << '\n';
6773
std::cout << " - cxxopts by jarro2783 (https://github.com/jarro2783/cxxopts)" << '\n';
6874
exit(EX_OK);
6975
}
7076

7177
// print version
72-
if (args.count("longversion")) {
73-
std::cout << PROJECT_NAME << ' ' << PROJECT_VERSION << " (compiled with " << COMPILER_INFO << " on "
74-
<< SYSTEM_INFO << ')'
75-
#ifndef OS_LINUX
76-
<< "-nonlinux"
77-
#endif
78-
<< '\n';
79-
return EX_OK;
80-
}
81-
8278
if (args.count("shortversion")) {
8379
std::cout << PROJECT_VERSION << '\n';
8480
return EX_OK;

0 commit comments

Comments
 (0)