Sharg 1.1.1
The argument parser for bio-c++ tools.
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages Concepts
Loading...
Searching...
No Matches
terminal.hpp
Go to the documentation of this file.
1// --------------------------------------------------------------------------------------------------------
2// Copyright (c) 2006-2023, Knut Reinert & Freie Universität Berlin
3// Copyright (c) 2016-2023, Knut Reinert & MPI für molekulare Genetik
4// This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License
5// shipped with this file and also available at: https://github.com/seqan/sharg-parser/blob/main/LICENSE.md
6// --------------------------------------------------------------------------------------------------------
7
14#pragma once
15
16#ifndef _WIN32
17# include <unistd.h>
18
19# include <sys/ioctl.h>
20#else
21# include <io.h>
22# include <stdio.h>
23#endif
24
25#include <sharg/platform.hpp>
26
27namespace sharg::detail
28{
29
36inline bool stdin_is_terminal()
37{
38#ifndef _WIN32
39 return isatty(STDIN_FILENO);
40#else
41 return _isatty(_fileno(stdin));
42#endif
43}
44
51inline bool stdout_is_terminal()
52{
53#ifndef _WIN32
54 return isatty(STDOUT_FILENO);
55#else
56 return _isatty(_fileno(stdout));
57#endif
58}
59
66inline bool stderr_is_terminal()
67{
68#ifndef _WIN32
69 return isatty(STDERR_FILENO);
70#else
71 return _isatty(_fileno(stderr));
72#endif
73}
74
75// ----------------------------------------------------------------------------
76// Function get_terminal_size()
77// ----------------------------------------------------------------------------
78
89inline unsigned get_terminal_width()
90{
91#ifndef _WIN32
92
93 struct winsize w;
94 w.ws_row = 0;
95 w.ws_col = 0;
96
97 ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
98
99 return w.ws_col;
100#else
101 return 80; // Not implemented for Windows yet. For inspiration, see https://stackoverflow.com/a/12642749.
102#endif
103}
104
105} // namespace sharg::detail
Provides platform and dependency checks.