mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-10-01 17:29:07 +08:00
Apply Clang-tidy (#918)
This commit is contained in:
@@ -6,14 +6,12 @@
|
||||
#include <array> // for array
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
#include "ftxui/screen/color_info.hpp" // for GetColorInfo, ColorInfo
|
||||
#include "ftxui/screen/terminal.hpp" // for ColorSupport, Color, Palette256, TrueColor
|
||||
|
||||
namespace ftxui {
|
||||
|
||||
using namespace std::literals;
|
||||
|
||||
namespace {
|
||||
const std::array<const char*, 33> palette16code = {
|
||||
"30", "40", //
|
||||
@@ -46,22 +44,30 @@ bool Color::operator!=(const Color& rhs) const {
|
||||
}
|
||||
|
||||
std::string Color::Print(bool is_background_color) const {
|
||||
switch (type_) {
|
||||
case ColorType::Palette1:
|
||||
return is_background_color ? "49"s : "39"s;
|
||||
|
||||
case ColorType::Palette16:
|
||||
return palette16code[2 * red_ + is_background_color]; // NOLINT;
|
||||
|
||||
case ColorType::Palette256:
|
||||
return (is_background_color ? "48;5;"s : "38;5;"s) + std::to_string(red_);
|
||||
|
||||
case ColorType::TrueColor:
|
||||
default:
|
||||
return (is_background_color ? "48;2;"s : "38;2;"s) //
|
||||
+ std::to_string(red_) + ";" //
|
||||
+ std::to_string(green_) + ";" //
|
||||
+ std::to_string(blue_); //
|
||||
if (is_background_color) {
|
||||
switch (type_) {
|
||||
case ColorType::Palette1:
|
||||
return "49";
|
||||
case ColorType::Palette16:
|
||||
return palette16code[2 * red_ + 1]; // NOLINT
|
||||
case ColorType::Palette256:
|
||||
return "48;5;" + std::to_string(red_);
|
||||
case ColorType::TrueColor:
|
||||
return "48;2;" + std::to_string(red_) + ";" + std::to_string(green_) +
|
||||
";" + std::to_string(blue_);
|
||||
}
|
||||
} else {
|
||||
switch (type_) {
|
||||
case ColorType::Palette1:
|
||||
return "39";
|
||||
case ColorType::Palette16:
|
||||
return palette16code[2 * red_]; // NOLINT
|
||||
case ColorType::Palette256:
|
||||
return "38;5;" + std::to_string(red_);
|
||||
case ColorType::TrueColor:
|
||||
return "38;2;" + std::to_string(red_) + ";" + std::to_string(green_) +
|
||||
";" + std::to_string(blue_);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -2,8 +2,11 @@
|
||||
// Use of this source code is governed by the MIT license that can be found in
|
||||
// the LICENSE file.
|
||||
#include <sstream> // IWYU pragma: keep
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "ftxui/screen/image.hpp"
|
||||
#include "ftxui/screen/pixel.hpp"
|
||||
|
||||
namespace ftxui {
|
||||
|
||||
|
@@ -1,13 +1,16 @@
|
||||
// Copyright 2020 Arthur Sonzogni. All rights reserved.
|
||||
// Use of this source code is governed by the MIT license that can be found in
|
||||
// the LICENSE file.
|
||||
#include <cstdint> // for size_t
|
||||
#include <cstddef> // for size_t
|
||||
#include <cstdint>
|
||||
#include <iostream> // for operator<<, stringstream, basic_ostream, flush, cout, ostream
|
||||
#include <limits>
|
||||
#include <map> // for _Rb_tree_const_iterator, map, operator!=, operator==
|
||||
#include <sstream> // IWYU pragma: keep
|
||||
#include <utility> // for pair
|
||||
|
||||
#include "ftxui/screen/image.hpp" // for Image
|
||||
#include "ftxui/screen/pixel.hpp" // for Pixel
|
||||
#include "ftxui/screen/screen.hpp"
|
||||
#include "ftxui/screen/string.hpp" // for string_width
|
||||
#include "ftxui/screen/terminal.hpp" // for Dimensions, Size
|
||||
@@ -117,11 +120,11 @@ void UpdatePixelStyle(const Screen* screen,
|
||||
}
|
||||
|
||||
struct TileEncoding {
|
||||
uint8_t left : 2;
|
||||
uint8_t top : 2;
|
||||
uint8_t right : 2;
|
||||
uint8_t down : 2;
|
||||
uint8_t round : 1;
|
||||
std::uint8_t left : 2;
|
||||
std::uint8_t top : 2;
|
||||
std::uint8_t right : 2;
|
||||
std::uint8_t down : 2;
|
||||
std::uint8_t round : 1;
|
||||
|
||||
// clang-format off
|
||||
bool operator<(const TileEncoding& other) const {
|
||||
@@ -521,20 +524,20 @@ void Screen::ApplyShader() {
|
||||
}
|
||||
// clang-format on
|
||||
|
||||
uint8_t Screen::RegisterHyperlink(const std::string& link) {
|
||||
for (size_t i = 0; i < hyperlinks_.size(); ++i) {
|
||||
std::uint8_t Screen::RegisterHyperlink(const std::string& link) {
|
||||
for (std::size_t i = 0; i < hyperlinks_.size(); ++i) {
|
||||
if (hyperlinks_[i] == link) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
if (hyperlinks_.size() == std::numeric_limits<uint8_t>::max()) {
|
||||
if (hyperlinks_.size() == std::numeric_limits<std::uint8_t>::max()) {
|
||||
return 0;
|
||||
}
|
||||
hyperlinks_.push_back(link);
|
||||
return hyperlinks_.size() - 1;
|
||||
}
|
||||
|
||||
const std::string& Screen::Hyperlink(uint8_t id) const {
|
||||
const std::string& Screen::Hyperlink(std::uint8_t id) const {
|
||||
if (id >= hyperlinks_.size()) {
|
||||
return hyperlinks_[0];
|
||||
}
|
||||
|
@@ -16,6 +16,7 @@
|
||||
#include <cstdint> // for uint32_t, uint8_t, uint16_t, int32_t
|
||||
#include <string> // for string, basic_string, wstring
|
||||
#include <tuple> // for _Swallow_assign, ignore
|
||||
#include <vector>
|
||||
|
||||
#include "ftxui/screen/deprecated.hpp" // for wchar_width, wstring_width
|
||||
#include "ftxui/screen/string_internal.hpp" // for WordBreakProperty, EatCodePoint, CodepointToWordBreakProperty, GlyphCount, GlyphIterate, GlyphNext, GlyphPrevious, IsCombining, IsControl, IsFullWidth, Utf8ToWordBreakProperty
|
||||
@@ -1355,7 +1356,6 @@ int string_width(const std::string& input) {
|
||||
|
||||
std::vector<std::string> Utf8ToGlyphs(const std::string& input) {
|
||||
std::vector<std::string> out;
|
||||
const std::string current;
|
||||
out.reserve(input.size());
|
||||
size_t start = 0;
|
||||
size_t end = 0;
|
||||
|
Reference in New Issue
Block a user