SeqAn3  3.2.0-rc.1
The Modern C++ library for sequence analysis.
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/seqan3/blob/master/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 <seqan3/core/platform.hpp>
26 
27 namespace seqan3::detail
28 {
29 
30 // ----------------------------------------------------------------------------
31 // Function is_terminal()
32 // ----------------------------------------------------------------------------
33 
37 inline bool is_terminal()
38 {
39 #ifndef _WIN32
40  return isatty(STDOUT_FILENO);
41 #else
42  return false;
43 #endif
44 }
45 
46 // ----------------------------------------------------------------------------
47 // Function get_terminal_size()
48 // ----------------------------------------------------------------------------
49 
59 inline unsigned get_terminal_width()
60 {
61 #ifndef _WIN32
62 
63  struct winsize w;
64  w.ws_row = 0;
65  w.ws_col = 0;
66 
67  ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
68 
69  return w.ws_col;
70 #else
71  return 80; // not implemented in windows
72 #endif
73 }
74 
75 } // namespace seqan3::detail
Provides platform and dependency checks.