mirror of
https://github.com/RGBCube/serenity
synced 2025-05-30 18:28:10 +00:00
HackStudio: Make C++ keywords bold :^)
Now that we can specify the font of a GTextEditor::Span, use this to make C++ keywords show up in bold text. Also tweak colors a bit.
This commit is contained in:
parent
59107a7cfe
commit
2b19badd74
1 changed files with 15 additions and 9 deletions
|
@ -191,24 +191,28 @@ void run(TerminalWrapper& wrapper)
|
|||
wrapper.run_command("make run");
|
||||
}
|
||||
|
||||
static Color color_for_token_type(CppToken::Type type)
|
||||
struct TextStyle {
|
||||
Color color;
|
||||
const Font* font { nullptr };
|
||||
};
|
||||
|
||||
static TextStyle style_for_token_type(CppToken::Type type)
|
||||
{
|
||||
switch (type) {
|
||||
case CppToken::Type::Keyword:
|
||||
return Color::Green;
|
||||
return { Color::Black, &Font::default_bold_fixed_width_font() };
|
||||
case CppToken::Type::Identifier:
|
||||
return Color::Blue;
|
||||
return { Color::Blue };
|
||||
case CppToken::Type::DoubleQuotedString:
|
||||
case CppToken::Type::SingleQuotedString:
|
||||
return Color::Red;
|
||||
case CppToken::Type::Number:
|
||||
return Color::Blue;
|
||||
return { Color::Red };
|
||||
case CppToken::Type::PreprocessorStatement:
|
||||
return Color::Magenta;
|
||||
return { Color::Magenta };
|
||||
case CppToken::Type::Comment:
|
||||
return Color::MidGray;
|
||||
return { Color::from_rgb(0x008200) };
|
||||
default:
|
||||
return Color::Black;
|
||||
return { Color::Black };
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -235,7 +239,9 @@ void open_file(const String& filename)
|
|||
GTextEditor::Span span;
|
||||
span.start = { token.m_start.line, token.m_start.column };
|
||||
span.end = { token.m_end.line, token.m_end.column };
|
||||
span.color = color_for_token_type(token.m_type);
|
||||
auto style = style_for_token_type(token.m_type);
|
||||
span.color = style.color;
|
||||
span.font = style.font;
|
||||
spans.append(span);
|
||||
}
|
||||
g_text_editor->set_spans(spans);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue