Ookii.CommandLine for C++  2.0.0
linux_helper.h
Go to the documentation of this file.
1 #ifndef OOKII_LINUX_HELPER_H_
4 #define OOKII_LINUX_HELPER_H_
5 
6 #pragma once
7 
8 #if !defined(OOKII_NO_PLATFORM_HEADERS) && (!defined(OOKII_CONSOLE_NOT_INLINE) || defined(OOKII_CONSOLE_DEFINITION))
9 
10 #include <unistd.h>
11 #include <sys/ioctl.h>
12 
13 #endif
14 
15 #include <optional>
16 
17 namespace ookii::details
18 {
19 
20  OOKII_PLATFORM_FUNC(std::optional<short> get_console_width())
21 #ifdef OOKII_PLATFORM_FUNC_HAS_BODY
22  {
23 #if defined(TIOCGWINSZ)
24 
25  struct winsize ws;
26 
27  if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) == 0)
28  {
29  return static_cast<short>(ws.ws_col);
30  }
31 
32 #endif
33 
34  return {};
35  }
36 #endif
37 
38 }
39 
40 #endif
short get_console_width(short default_width=80) noexcept
Determines the width of the console.
Definition: console_helper.h:19