mirror of
https://github.com/NixOS/nix.git
synced 2025-11-14 14:32:42 +01:00
Apply clang-format universally.
* It is tough to contribute to a project that doesn't use a formatter, * It is extra hard to contribute to a project which has configured the formatter, but ignores it for some files * Code formatting makes it harder to hide obscure / weird bugs by accident or on purpose, Let's rip the bandaid off? Note that PRs currently in flight should be able to be merged relatively easily by applying `clang-format` to their tip prior to merge. Co-authored-by: Graham Christensen <graham@grahamc.com>
This commit is contained in:
parent
9b8b5d8560
commit
95d9c13716
585 changed files with 23297 additions and 23164 deletions
|
|
@ -3,12 +3,12 @@
|
|||
#include "nix/util/sync.hh"
|
||||
|
||||
#ifdef _WIN32
|
||||
# include <io.h>
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
# include <windows.h>
|
||||
# define isatty _isatty
|
||||
# include <io.h>
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
# include <windows.h>
|
||||
# define isatty _isatty
|
||||
#else
|
||||
# include <sys/ioctl.h>
|
||||
# include <sys/ioctl.h>
|
||||
#endif
|
||||
#include <unistd.h>
|
||||
#include <widechar_width.h>
|
||||
|
|
@ -57,16 +57,14 @@ inline std::pair<int, size_t> charWidthUTF8Helper(std::string_view s)
|
|||
return {width, bytes};
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace nix {
|
||||
|
||||
bool isTTY()
|
||||
{
|
||||
static const bool tty =
|
||||
isatty(STDERR_FILENO)
|
||||
&& getEnv("TERM").value_or("dumb") != "dumb"
|
||||
&& !(getEnv("NO_COLOR").has_value() || getEnv("NOCOLOR").has_value());
|
||||
static const bool tty = isatty(STDERR_FILENO) && getEnv("TERM").value_or("dumb") != "dumb"
|
||||
&& !(getEnv("NO_COLOR").has_value() || getEnv("NOCOLOR").has_value());
|
||||
|
||||
return tty;
|
||||
}
|
||||
|
|
@ -87,11 +85,14 @@ std::string filterANSIEscapes(std::string_view s, bool filterAll, unsigned int w
|
|||
if (i != s.end() && *i == '[') {
|
||||
e += *i++;
|
||||
// eat parameter bytes
|
||||
while (i != s.end() && *i >= 0x30 && *i <= 0x3f) e += *i++;
|
||||
while (i != s.end() && *i >= 0x30 && *i <= 0x3f)
|
||||
e += *i++;
|
||||
// eat intermediate bytes
|
||||
while (i != s.end() && *i >= 0x20 && *i <= 0x2f) e += *i++;
|
||||
while (i != s.end() && *i >= 0x20 && *i <= 0x2f)
|
||||
e += *i++;
|
||||
// eat final byte
|
||||
if (i != s.end() && *i >= 0x40 && *i <= 0x7e) e += last = *i++;
|
||||
if (i != s.end() && *i >= 0x40 && *i <= 0x7e)
|
||||
e += last = *i++;
|
||||
} else if (i != s.end() && *i == ']') {
|
||||
// OSC
|
||||
e += *i++;
|
||||
|
|
@ -101,15 +102,18 @@ std::string filterANSIEscapes(std::string_view s, bool filterAll, unsigned int w
|
|||
// 2. BEL ('\a') (xterm-style, used by gcc)
|
||||
|
||||
// eat ESC or BEL
|
||||
while (i != s.end() && *i != '\e' && *i != '\a') e += *i++;
|
||||
while (i != s.end() && *i != '\e' && *i != '\a')
|
||||
e += *i++;
|
||||
if (i != s.end()) {
|
||||
char v = *i;
|
||||
e += *i++;
|
||||
// eat backslash after ESC
|
||||
if (i != s.end() && v == '\e' && *i == '\\') e += last = *i++;
|
||||
char v = *i;
|
||||
e += *i++;
|
||||
// eat backslash after ESC
|
||||
if (i != s.end() && v == '\e' && *i == '\\')
|
||||
e += last = *i++;
|
||||
}
|
||||
} else {
|
||||
if (i != s.end() && *i >= 0x40 && *i <= 0x5f) e += *i++;
|
||||
if (i != s.end() && *i >= 0x40 && *i <= 0x5f)
|
||||
e += *i++;
|
||||
}
|
||||
|
||||
if (!filterAll && last == 'm')
|
||||
|
|
@ -146,17 +150,16 @@ std::string filterANSIEscapes(std::string_view s, bool filterAll, unsigned int w
|
|||
|
||||
static Sync<std::pair<unsigned short, unsigned short>> windowSize{{0, 0}};
|
||||
|
||||
|
||||
void updateWindowSize()
|
||||
{
|
||||
#ifndef _WIN32
|
||||
#ifndef _WIN32
|
||||
struct winsize ws;
|
||||
if (ioctl(2, TIOCGWINSZ, &ws) == 0) {
|
||||
auto windowSize_(windowSize.lock());
|
||||
windowSize_->first = ws.ws_row;
|
||||
windowSize_->second = ws.ws_col;
|
||||
}
|
||||
#else
|
||||
#else
|
||||
CONSOLE_SCREEN_BUFFER_INFO info;
|
||||
// From https://stackoverflow.com/a/12642749
|
||||
if (GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info) != 0) {
|
||||
|
|
@ -165,13 +168,12 @@ void updateWindowSize()
|
|||
windowSize_->first = info.srWindow.Bottom - info.srWindow.Top + 1;
|
||||
windowSize_->second = info.dwSize.X;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
std::pair<unsigned short, unsigned short> getWindowSize()
|
||||
{
|
||||
return *windowSize.lock();
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace nix
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue