FTXUI 7.0.3
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
9namespace ftxui::util {
10
11// Similaire à std::clamp, mais permet à 'hi' d'être inférieur à 'lo'.
12template <class T>
13constexpr const T& clamp(const T& v, const T& lo, const T& hi) {
14 return v < lo ? lo : hi < v ? hi : v;
15}
16
17// Renvoie la valeur de la variable d'environnement |name|, ou "" si non définie.
18inline const char* GetEnv(const char* name) {
19 // Le CRT de Microsoft marque std::getenv comme obsolète.
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 /* fin de la protection d'inclusion : FTXUI_SCREEN_UTIL_HPP */
const char * GetEnv(const char *name)
Definition util.hpp:18
constexpr const T & clamp(const T &v, const T &lo, const T &hi)
Definition util.hpp:13
int value
Definition elements.hpp:195