Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions demo/Views/CSSView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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");

Expand Down
10 changes: 10 additions & 0 deletions lib/Constants.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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";
}

/**
Expand Down
18 changes: 18 additions & 0 deletions lib/Styles/Granite/_classes.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
32 changes: 32 additions & 0 deletions lib/Widgets/TerminalView.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2025 elementary, Inc. (https://elementary.io)
* SPDX-License-Identifier: GPL-2.0-or-later
*/

[Version (since = "7.7.0")]
public class Granite.TerminalView : Gtk.ScrolledWindow {

public TerminalView () {
this.add_css_class (Granite.CssClass.TERMINAL);
}

public TerminalView.with_textview (
Gtk.TextView view = new Gtk.TextView () {
cursor_visible = true,
margin_end = 6,
editable = false,
margin_start = 6,
monospace = true,
pixels_below_lines = 3,
wrap_mode = Gtk.WrapMode.WORD
}
) {
this.child = view;
}

// We may not need this, as we could use an un-editable TextView and
// simplify the API
public TerminalView.with_label (Gtk.Label label) {
this.child = label;
}
}
1 change: 1 addition & 0 deletions lib/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ libgranite_sources = files(
'Widgets/SettingsSidebar.vala',
'Widgets/Settings.vala',
'Widgets/SwitchModelButton.vala',
'Widgets/TerminalView.vala',
'Widgets/TimePicker.vala',
'Widgets/ToolBox.vala',
'Widgets/Toast.vala',
Expand Down
Loading