FTXUI
7.1.0
C++ functional terminal UI.
Loading...
Searching...
No Matches
util.hpp
Go to the documentation of this file.
1
// Copyright 2022 Arthur Sonzogni. All rights reserved.
2
// Use of this source code is governed by the MIT license that can be found in
3
// the LICENSE file.
4
#ifndef FTXUI_SCREEN_UTIL_HPP
5
#define FTXUI_SCREEN_UTIL_HPP
6
7
#include <cstdlib>
// for getenv
8
9
namespace
ftxui::util
{
10
11
// Similar to std::clamp, but allow hi to be lower than lo.
12
template
<
class
T>
13
constexpr
const
T&
clamp
(
const
T& v,
const
T& lo,
const
T& hi) {
14
return
v < lo ? lo : hi < v ? hi : v;
15
}
16
17
// Returns the value of the environment variable |name|, or "" if unset.
18
inline
const
char
*
GetEnv
(
const
char
* name) {
19
// The Microsoft CRT marks std::getenv as deprecated.
20
#if defined(__clang__)
21
#pragma clang diagnostic push
22
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
23
#elif defined(_MSC_VER)
24
#pragma warning(push)
25
#pragma warning(disable : 4996)
26
#endif
27
const
char
*
value
= std::getenv(name);
// NOLINT
28
#if defined(__clang__)
29
#pragma clang diagnostic pop
30
#elif defined(_MSC_VER)
31
#pragma warning(pop)
32
#endif
33
return
value
?
value
:
""
;
34
}
35
36
}
// namespace ftxui::util
37
38
#endif
/* end of include guard: FTXUI_SCREEN_UTIL_HPP */
ftxui::util
Definition
util.hpp:9
ftxui::util::GetEnv
const char * GetEnv(const char *name)
Definition
util.hpp:18
ftxui::util::clamp
constexpr const T & clamp(const T &v, const T &lo, const T &hi)
Definition
util.hpp:13
ftxui::value
int value
Definition
elements.hpp:195