aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/terminal.vala
diff options
context:
space:
mode:
authorWynn Wolf Arbor2019-10-30 19:11:16 +0100
committerWynn Wolf Arbor2020-02-04 14:33:13 +0100
commit00702a3b764139a28b4de89f48ec1e38f1c58150 (patch)
tree8ab9563b3d462a60335ec489d2371df474201d0d /terminal.vala
parentf72f05cd8e157e5f433dca21de2a8d7fb2411436 (diff)
downloadweltschmerz-00702a3b764139a28b4de89f48ec1e38f1c58150.tar.gz
Improve configuration handling
This commit improves and simplifies weltschmerz's configuration handling. Obtaining and parsing the KeyFile is split out into ConfigReader, which is fully agnostic of the specific configuration values. Config now contains all configuration values in the form of primitive types or class instances, and no longer delegates access to the KeyFile structure directly. This means that the configuration file is read once, and then kept in the Config instance. Indirectly this commit also fixes a bug where weltschmerz would segfault if one of the palette entries contained an invalid value.
Diffstat (limited to 'terminal.vala')
-rw-r--r--terminal.vala73
1 files changed, 13 insertions, 60 deletions
diff --git a/terminal.vala b/terminal.vala
index a7cfb6b..99c21ce 100644
--- a/terminal.vala
+++ b/terminal.vala
@@ -18,23 +18,6 @@ class Terminal : Gtk.Overlay {
const double FONT_SCALE_MAX = 3.583180799999999; // 1.2 ^ 7
const double FONT_SCALE_FACTOR = 1.2;
- struct PaletteEntry {
- string name;
- string normal;
- string bright;
- }
-
- const PaletteEntry[] DEFAULT_PALETTE = {
- { "black", "black", "grey50" },
- { "red", "red3", "red" },
- { "green", "green3", "green" },
- { "yellow", "yellow3", "yellow" },
- { "blue", "blue2", "#5c5cff" },
- { "magenta", "magenta3", "magenta" },
- { "cyan", "cyan3", "cyan" },
- { "white", "grey90", "white" },
- };
-
public Gtk.Window window { get; construct set; }
[GtkChild] Gtk.Button search_button_down;
[GtkChild] Gtk.Button search_button_up;
@@ -83,10 +66,10 @@ class Terminal : Gtk.Overlay {
public void load_config(bool reload) {
var conf = new Config();
- Gtk.PolicyType policy = conf.boolean("misc", "scrollbar", true) ? Gtk.PolicyType.AUTOMATIC : Gtk.PolicyType.NEVER;
+ Gtk.PolicyType policy = conf.scrollbar ? Gtk.PolicyType.AUTOMATIC : Gtk.PolicyType.NEVER;
scrolled_window.set_policy(policy, policy);
- vte.set_font(Pango.FontDescription.from_string(conf.value("misc", "font", "Monospace 12")));
+ vte.set_font(conf.font);
var geometry = Gdk.Geometry() {
// This must be kept in sync with the padding size in terminal.css
base_width = 2 * 2,
@@ -96,50 +79,20 @@ class Terminal : Gtk.Overlay {
};
window.set_geometry_hints(null, geometry, BASE_SIZE | RESIZE_INC);
- vte.set_mouse_autohide(conf.boolean("misc", "autohide-mouse", false));
- vte.set_scrollback_lines(conf.integer("misc", "scrollback", 10000));
-
- var cursor = conf.value("misc", "cursor-shape", "block");
- switch (cursor) {
- case "block":
- vte.set_cursor_shape(BLOCK);
- break;
- case "beam":
- vte.set_cursor_shape(IBEAM);
- break;
- case "underline":
- vte.set_cursor_shape(UNDERLINE);
- break;
- default:
- conf.append_warning("invalid cursor '%s'".printf(cursor));
- vte.set_cursor_shape(BLOCK);
- break;
- }
-
- var foreground = conf.colour("foreground", null);
- var background = conf.colour("background", null);
-
- var palette = new Gdk.RGBA[16];
- for (int i = 0; i < DEFAULT_PALETTE.length; i++) {
- var entry = DEFAULT_PALETTE[i];
- palette[i] = conf.colour("normal." + entry.name, entry.normal);
- palette[i + 8] = conf.colour("bright." + entry.name, entry.bright);
- }
-
- vte.set_colors(foreground, background, palette);
-
- vte.set_color_bold(conf.colour("bold", null));
-
- vte.set_color_cursor_foreground(conf.colour("cursor.foreground", null));
- vte.set_color_cursor(conf.colour("cursor.background", null));
+ vte.set_mouse_autohide(conf.autohide_mouse);
+ vte.set_scrollback_lines(conf.scrollback);
+ vte.set_cursor_shape(conf.cursor_shape);
- vte.set_color_highlight_foreground(conf.colour("selection.foreground", null));
- vte.set_color_highlight(conf.colour("selection.background", null));
+ vte.set_colors(conf.foreground, conf.background, conf.palette);
+ vte.set_color_bold(conf.bold);
+ vte.set_color_cursor_foreground(conf.cursor_foreground);
+ vte.set_color_cursor(conf.cursor_background);
+ vte.set_color_highlight_foreground(conf.selection_foreground);
+ vte.set_color_highlight(conf.selection_background);
- var warnings = conf.done();
- if (warnings.length > 0) {
+ if (conf.get_warnings().length > 0) {
string header = "<b>Configuration loaded with warnings:</b>\n";
- infobar_show(header + string.joinv("\n", warnings), Gtk.MessageType.WARNING);
+ infobar_show(header + string.joinv("\n", conf.get_warnings()), Gtk.MessageType.WARNING);
} else if (reload) {
infobar_show("Configuration loaded successfully.", Gtk.MessageType.INFO, 3);
}