From 9e3e8d62ff269853b799d7e6f8ea205bbfc89b02 Mon Sep 17 00:00:00 2001 From: William Kelso Date: Tue, 13 May 2025 14:49:27 -0400 Subject: [PATCH] add terminal cssclass --- demo/Views/CSSView.vala | 5 +++-- lib/Constants.vala | 10 ++++++++++ lib/Styles/Granite/_classes.scss | 18 ++++++++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/demo/Views/CSSView.vala b/demo/Views/CSSView.vala index 6e70df169..8b5321417 100644 --- a/demo/Views/CSSView.vala +++ b/demo/Views/CSSView.vala @@ -84,7 +84,8 @@ public class CSSView : DemoPage { card_box.append (card); card_box.append (card_checkered); - var terminal_label = new Granite.HeaderLabel ("\"terminal\" style class"); + var terminal_label = new Granite.HeaderLabel + ("\"Granite.CssClass.TERMINAL\""); var terminal = new Gtk.Label ("[ 73%] Linking C executable granite-demo\n[100%] Built target granite-demo") { selectable = true, @@ -97,7 +98,7 @@ public class CSSView : DemoPage { min_content_height = 70, child = terminal }; - terminal_scroll.add_css_class (Granite.STYLE_CLASS_TERMINAL); + terminal_scroll.add_css_class (Granite.CssClass.TERMINAL); var accent_color_label = new Granite.HeaderLabel ("Colored labels and icons"); diff --git a/lib/Constants.vala b/lib/Constants.vala index f7438e168..18f1e5760 100644 --- a/lib/Constants.vala +++ b/lib/Constants.vala @@ -131,6 +131,7 @@ namespace Granite { * When used with {@link Gtk.Label} this style includes internal padding. When used with {@link Gtk.TextView} * interal padding will need to be set with {@link Gtk.Container.border_width} */ + [Version (deprecated = true, deprecated_since = "7.7.0", replacement = "Granite.CssClass.TERMINAL")] public const string STYLE_CLASS_TERMINAL = "terminal"; /** * Style class for title label text in a {@link Granite.MessageDialog} @@ -290,6 +291,15 @@ namespace Granite { * Style class for non-terminal text that uses a monospace font. */ public const string MONOSPACE = "monospace"; + + /** + * Style class for {@link Gtk.Label} or {@link Gtk.TextView} to emulate the appearance of Terminal. This includes + * text color, background color, selection highlighting, and selecting the system monospace font. + * + * When used with {@link Gtk.Label} this style includes internal padding. When used with {@link Gtk.TextView} + * interal padding will need to be set with {@link Gtk.Container.border_width} + */ + public const string TERMINAL = "terminal"; } /** diff --git a/lib/Styles/Granite/_classes.scss b/lib/Styles/Granite/_classes.scss index eaf129810..05436f6ff 100644 --- a/lib/Styles/Granite/_classes.scss +++ b/lib/Styles/Granite/_classes.scss @@ -48,3 +48,21 @@ paper { font-family: monospace; } +.terminal { + font-family: monospace; + + background-color: $fg-color; + color: bg-color(0); + + padding: rem(12px) rem(18px); + + & selection { + background-color: bg-color(0); + color: $fg-color; + + &:backdrop { + // Cancelling values set in non-terminal selection + background-color: inherit; + } + } +}