mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 09:17:35 +00:00
Ladybird/ConsoleClient: Implement console message styling with %c
This matches the changes made to Serenity in:
7a2da4cabf
This commit is contained in:
parent
0bf79b1f3b
commit
acec34351f
2 changed files with 20 additions and 9 deletions
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2021, Brandon Scott <xeon.productions@gmail.com>
|
* Copyright (c) 2021, Brandon Scott <xeon.productions@gmail.com>
|
||||||
* Copyright (c) 2020, Hunter Salyer <thefalsehonesty@gmail.com>
|
* Copyright (c) 2020, Hunter Salyer <thefalsehonesty@gmail.com>
|
||||||
* Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
|
* Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org>
|
||||||
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
|
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
@ -144,6 +144,9 @@ void ConsoleClient::clear()
|
||||||
// 2.3. Printer(logLevel, args[, options]), https://console.spec.whatwg.org/#printer
|
// 2.3. Printer(logLevel, args[, options]), https://console.spec.whatwg.org/#printer
|
||||||
JS::ThrowCompletionOr<JS::Value> ConsoleClient::printer(JS::Console::LogLevel log_level, PrinterArguments arguments)
|
JS::ThrowCompletionOr<JS::Value> ConsoleClient::printer(JS::Console::LogLevel log_level, PrinterArguments arguments)
|
||||||
{
|
{
|
||||||
|
auto styling = escape_html_entities(m_current_message_style.string_view());
|
||||||
|
m_current_message_style.clear();
|
||||||
|
|
||||||
if (log_level == JS::Console::LogLevel::Trace) {
|
if (log_level == JS::Console::LogLevel::Trace) {
|
||||||
auto trace = arguments.get<JS::Console::Trace>();
|
auto trace = arguments.get<JS::Console::Trace>();
|
||||||
StringBuilder html;
|
StringBuilder html;
|
||||||
|
@ -161,7 +164,7 @@ JS::ThrowCompletionOr<JS::Value> ConsoleClient::printer(JS::Console::LogLevel lo
|
||||||
|
|
||||||
if (log_level == JS::Console::LogLevel::Group || log_level == JS::Console::LogLevel::GroupCollapsed) {
|
if (log_level == JS::Console::LogLevel::Group || log_level == JS::Console::LogLevel::GroupCollapsed) {
|
||||||
auto group = arguments.get<JS::Console::Group>();
|
auto group = arguments.get<JS::Console::Group>();
|
||||||
begin_group(group.label, log_level == JS::Console::LogLevel::Group);
|
begin_group(String::formatted("<span style='{}'>{}</span>", styling, escape_html_entities(group.label)), log_level == JS::Console::LogLevel::Group);
|
||||||
return JS::js_undefined();
|
return JS::js_undefined();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,23 +174,23 @@ JS::ThrowCompletionOr<JS::Value> ConsoleClient::printer(JS::Console::LogLevel lo
|
||||||
StringBuilder html;
|
StringBuilder html;
|
||||||
switch (log_level) {
|
switch (log_level) {
|
||||||
case JS::Console::LogLevel::Debug:
|
case JS::Console::LogLevel::Debug:
|
||||||
html.append("<span class=\"debug\">(d) "sv);
|
html.appendff("<span class=\"debug\" style=\"{}\">(d) "sv, styling);
|
||||||
break;
|
break;
|
||||||
case JS::Console::LogLevel::Error:
|
case JS::Console::LogLevel::Error:
|
||||||
html.append("<span class=\"error\">(e) "sv);
|
html.appendff("<span class=\"error\" style=\"{}\">(e) "sv, styling);
|
||||||
break;
|
break;
|
||||||
case JS::Console::LogLevel::Info:
|
case JS::Console::LogLevel::Info:
|
||||||
html.append("<span class=\"info\">(i) "sv);
|
html.appendff("<span class=\"info\" style=\"{}\">(i) "sv, styling);
|
||||||
break;
|
break;
|
||||||
case JS::Console::LogLevel::Log:
|
case JS::Console::LogLevel::Log:
|
||||||
html.append("<span class=\"log\"> "sv);
|
html.appendff("<span class=\"log\" style=\"{}\"> "sv, styling);
|
||||||
break;
|
break;
|
||||||
case JS::Console::LogLevel::Warn:
|
case JS::Console::LogLevel::Warn:
|
||||||
case JS::Console::LogLevel::CountReset:
|
case JS::Console::LogLevel::CountReset:
|
||||||
html.append("<span class=\"warn\">(w) "sv);
|
html.appendff("<span class=\"warn\" style=\"{}\">(w) "sv, styling);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
html.append("<span>"sv);
|
html.appendff("<span style=\"{}\">"sv, styling);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2022, Brandon Scott <xeon.productions@gmail.com>
|
* Copyright (c) 2022, Brandon Scott <xeon.productions@gmail.com>
|
||||||
* Copyright (c) 2020, Hunter Salyer <thefalsehonesty@gmail.com>
|
* Copyright (c) 2020, Hunter Salyer <thefalsehonesty@gmail.com>
|
||||||
* Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
|
* Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org>
|
||||||
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
|
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
@ -32,6 +32,12 @@ private:
|
||||||
virtual void clear() override;
|
virtual void clear() override;
|
||||||
virtual JS::ThrowCompletionOr<JS::Value> printer(JS::Console::LogLevel log_level, PrinterArguments) override;
|
virtual JS::ThrowCompletionOr<JS::Value> printer(JS::Console::LogLevel log_level, PrinterArguments) override;
|
||||||
|
|
||||||
|
virtual void add_css_style_to_current_message(StringView style) override
|
||||||
|
{
|
||||||
|
m_current_message_style.append(style);
|
||||||
|
m_current_message_style.append(';');
|
||||||
|
}
|
||||||
|
|
||||||
SimpleWebView& m_view;
|
SimpleWebView& m_view;
|
||||||
|
|
||||||
WeakPtr<JS::Interpreter> m_interpreter;
|
WeakPtr<JS::Interpreter> m_interpreter;
|
||||||
|
@ -55,6 +61,8 @@ private:
|
||||||
};
|
};
|
||||||
Vector<ConsoleOutput> m_message_log;
|
Vector<ConsoleOutput> m_message_log;
|
||||||
|
|
||||||
|
StringBuilder m_current_message_style;
|
||||||
|
|
||||||
WeakPtr<JS::Realm> m_realm;
|
WeakPtr<JS::Realm> m_realm;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue