mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
8075ba5064
Meet TStyle. It allows you to write things like this: dbg() << TStyle(TStyle::Red, TStyle::Bold) << "Hello, friends!"; Any style used will be reset along with the newline emitted when the dbg() temporary goes out of scope. :^) This can definitely be improved, but I think it's a decent place to start.
52 lines
1.2 KiB
C++
52 lines
1.2 KiB
C++
#include <AK/AKString.h>
|
|
#include <AK/LogStream.h>
|
|
#include <AK/StringView.h>
|
|
|
|
namespace AK {
|
|
|
|
const LogStream& operator<<(const LogStream& stream, const String& value)
|
|
{
|
|
stream.write(value.characters(), value.length());
|
|
return stream;
|
|
}
|
|
|
|
const LogStream& operator<<(const LogStream& stream, const StringView& value)
|
|
{
|
|
stream.write(value.characters_without_null_termination(), value.length());
|
|
return stream;
|
|
}
|
|
|
|
const LogStream& operator<<(const LogStream& stream, int value)
|
|
{
|
|
return stream << String::number(value);
|
|
}
|
|
|
|
const LogStream& operator<<(const LogStream& stream, unsigned value)
|
|
{
|
|
return stream << String::number(value);
|
|
}
|
|
|
|
const LogStream& operator<<(const LogStream& stream, const void* value)
|
|
{
|
|
return stream << String::format("%p", value);
|
|
}
|
|
|
|
const LogStream& operator<<(const LogStream& stream, const TStyle& style)
|
|
{
|
|
stream << "\033[";
|
|
|
|
if (style.color() != TStyle::Color::NoColor)
|
|
stream << ((int)style.color() + 30) << (style.attributes() ? ";" : "");
|
|
else
|
|
stream << '0';
|
|
|
|
if (style.attributes() & TStyle::Attribute::Bold)
|
|
stream << '1';
|
|
|
|
stream << 'm';
|
|
|
|
stream.m_needs_style_reset = true;
|
|
return stream;
|
|
}
|
|
|
|
}
|