sharg 1.0.0
THE argument parser for bio-c++ tools.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages Concepts
terminal.hpp
Go to the documentation of this file.
1// --------------------------------------------------------------------------------------------------------
2// Copyright (c) 2006-2022, Knut Reinert & Freie Universität Berlin
3// Copyright (c) 2016-2022, 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 <sys/ioctl.h>
18#else
19# include <windows.h>
20#endif
21
22#include <cstdio>
23#include <unistd.h>
24
25#include <sharg/platform.hpp>
26
27namespace sharg::detail
28{
29
30// ----------------------------------------------------------------------------
31// Function is_terminal()
32// ----------------------------------------------------------------------------
33
38inline bool is_terminal()
39{
40#ifndef _WIN32
41 return isatty(STDOUT_FILENO);
42#else
43 return false;
44#endif
45}
46
47// ----------------------------------------------------------------------------
48// Function get_terminal_size()
49// ----------------------------------------------------------------------------
50
61inline unsigned get_terminal_width()
62{
63#ifndef _WIN32
64
65 struct winsize w;
66 w.ws_row = 0;
67 w.ws_col = 0;
68
69 ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
70
71 return w.ws_col;
72#else
73 return 80; // not implemented in windows
74#endif
75}
76
77} // namespace sharg::detail
Provides platform and dependency checks.