File tree Expand file tree Collapse file tree 2 files changed +11
-15
lines changed Expand file tree Collapse file tree 2 files changed +11
-15
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 3.22.0 FATAL_ERROR)
4
4
# ======================================================================================================================
5
5
6
6
# project
7
- project (write-shm LANGUAGES CXX VERSION 1.1.0 )
7
+ project (write-shm LANGUAGES CXX VERSION 1.1.1 )
8
8
9
9
# settings
10
10
set (Target "write-shm" ) # Executable name (without file extension!)
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,24 +59,22 @@ 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 ' ;
68
74
exit (EX_OK);
69
75
}
70
76
71
77
// 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
-
82
78
if (args.count (" shortversion" )) {
83
79
std::cout << PROJECT_VERSION << ' \n ' ;
84
80
return EX_OK;
You can’t perform that action at this time.
0 commit comments