Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ AM_CPPFLAGS = $(TERMDEPS_CFLAGS)

AM_CFLAGS = -Wall -Wno-discarded-qualifiers -Wno-pointer-sign -Wno-unused-but-set-variable -Wno-unused-variable

VALAFLAGS = --pkg=gtk+-3.0 --pkg=vte-2.91 --pkg=pango --pkg=posix --enable-checking
VALAFLAGS = --pkg=gtk4 --pkg=vte-2.91-gtk4 --pkg=pango --pkg=posix --enable-checking

# the terminal

Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ AM_SILENT_RULES([yes])
AM_PROG_VALAC([0.14.0])
AM_PROG_CC_C_O

PKG_CHECK_MODULES(TERMDEPS, [gtk+-3.0 vte-2.91 >= 0.66.0])
PKG_CHECK_MODULES(TERMDEPS, [gtk4 vte-2.91-gtk4 >= 0.66.0])

AC_CONFIG_FILES([Makefile])

Expand Down
6 changes: 3 additions & 3 deletions packit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ downstream_package_name: simple-term
jobs:
- job: copr_build
trigger: pull_request
targets: [fedora-all]
targets: [fedora-37, fedora-38, fedora-rawhide]

- job: copr_build
trigger: commit
branch: main
targets: [fedora-all]
targets: [fedora-37, fedora-38, fedora-rawhide]
owner: mh21
project: simple-term-latest

- job: copr_build
trigger: release
targets: [fedora-all]
targets: [fedora-37, fedora-38, fedora-rawhide]
owner: mh21
project: simple-term
4 changes: 2 additions & 2 deletions simple-term.spec
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ Source0: https://github.com/mh21/simple-term/archive/refs/tags/v%{version}.tar.g

BuildRequires: gnome-common
BuildRequires: vala
BuildRequires: gtk3-devel
BuildRequires: vte291-devel
BuildRequires: gtk4-devel
BuildRequires: vte291-gtk4-devel

%description
Simple vte-based terminal
Expand Down
32 changes: 17 additions & 15 deletions simple-term.vala
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,29 @@ class TerminalWindow : Gtk.Window
private const string link_expr = "(((file|http|ftp|https)://)|(www|ftp)[-A-Za-z0-9]*\\.)[-A-Za-z0-9\\.]+(:[0-9]*)?(/[-A-Za-z0-9_\\$\\.\\+\\!\\*\\(\\),;:@&=\\?/~\\#\\%]*[^]'\\.}>\\) ,\\\"])?";
private int link_tag;

private const Gdk.ModifierType key_mask = Gdk.ModifierType.SHIFT_MASK | Gdk.ModifierType.CONTROL_MASK | Gdk.ModifierType.MOD1_MASK |
private const Gdk.ModifierType key_mask = Gdk.ModifierType.SHIFT_MASK | Gdk.ModifierType.CONTROL_MASK | Gdk.ModifierType.ALT_MASK |
Gdk.ModifierType.SUPER_MASK | Gdk.ModifierType.HYPER_MASK | Gdk.ModifierType.META_MASK;

public TerminalWindow(Gtk.Application app, string[] command, string? title,
string? font, string fg, string bg, string palette, string? role)
string? font, string fg, string bg, string palette)
{
Object(application: app);

this.title = title != null ? title : string.joinv(" ", command);
this.font = font;

terminal = new Vte.Terminal();
add(terminal);
set_child(terminal);

terminal.child_exited.connect(() => { destroy(); });
terminal.decrease_font_size.connect(decrease_font_size_cb);
terminal.increase_font_size.connect(increase_font_size_cb);
terminal.window_title_changed.connect(window_title_changed_cb);
/*
terminal.key_press_event.connect(key_press_event_cb);
terminal.button_press_event.connect(button_press_event_cb);
terminal.drag_data_received.connect(drag_data_received_cb);
*/

terminal.set_audible_bell(false);
terminal.set_cursor_blink_mode(Vte.CursorBlinkMode.SYSTEM);
Expand All @@ -69,9 +71,6 @@ class TerminalWindow : Gtk.Window
if (font != null)
terminal.set_font(Pango.FontDescription.from_string(this.font));

if (role != null)
this.set_role(role);

try {
var regex = new Vte.Regex.for_match(link_expr, -1, PCRE2_MULTILINE);
link_tag = terminal.match_add_regex(regex, 0);
Expand All @@ -81,9 +80,11 @@ class TerminalWindow : Gtk.Window
// ignored
}

/*
Gtk.drag_dest_set(terminal, Gtk.DestDefaults.ALL, {}, Gdk.DragAction.COPY);
Gtk.drag_dest_add_uri_targets(terminal); // prefer URIs to text
Gtk.drag_dest_add_text_targets(terminal);
*/

try {
terminal.spawn_sync(Vte.PtyFlags.DEFAULT,
Expand All @@ -99,10 +100,10 @@ class TerminalWindow : Gtk.Window
Idle.add(() => { destroy(); return false; });
}

show_all();
present();
}

private static Gdk.RGBA? get_color(string str)
private static Gdk.RGBA? parse_color(string str)
{
var color = Gdk.RGBA();
if (!color.parse(str)) {
Expand Down Expand Up @@ -133,7 +134,7 @@ class TerminalWindow : Gtk.Window
if (editor == null || editor[0] == '\0')
editor = "vi";
new TerminalWindow(this.get_application(), { editor, file.get_path() }, null,
this.font, this.fg, this.bg, this.palette, "scrollback-edit");
this.font, this.fg, this.bg, this.palette);
// after 10 seconds the editor should have opened the file, remove
// it from the filesystem again
Timeout.add_seconds(10, () => { file.delete_async.begin(); return false; });
Expand All @@ -143,6 +144,7 @@ class TerminalWindow : Gtk.Window
}
}

/*
public override bool delete_event(Gdk.EventAny event)
{
var pty = terminal.get_pty();
Expand All @@ -165,6 +167,7 @@ class TerminalWindow : Gtk.Window
dialog.destroy();
return result != Gtk.ResponseType.ACCEPT;
}
*/

private void decrease_font_size_cb()
{
Expand All @@ -181,6 +184,7 @@ class TerminalWindow : Gtk.Window
set_title(terminal.get_window_title());
}

/*
private bool button_press_event_cb(Gdk.EventButton event)
{
if (((event.state & key_mask) == Gdk.ModifierType.CONTROL_MASK) && (event.button == 1)) {
Expand Down Expand Up @@ -239,6 +243,7 @@ class TerminalWindow : Gtk.Window
}
Gtk.drag_finish(context, true, false, time);
}
*/

public void update_colors(string fg, string bg, string palette)
{
Expand All @@ -248,8 +253,8 @@ class TerminalWindow : Gtk.Window

Gdk.RGBA[] colors = null;
foreach (var color in palette.split(","))
colors += get_color(color);
terminal.set_colors(get_color(fg), get_color(bg), colors);
colors += parse_color(color);
terminal.set_colors(parse_color(fg), parse_color(bg), colors);
}
}

Expand All @@ -270,7 +275,6 @@ class Application: Gtk.Application
string fg = "black";
string bg = "#ffffdd";
string palette = "#000000,#aa0000,#00aa00,#aa5400,#0000aa,#aa00aa,#00aaaa,#aaaaaa,#545454,#ff5454,#54ff54,#ffff54,#5454ff,#ff54ff,#54ffff,#ffffff";
string? role = null;
bool update_colors = false;

for (int i = 1; i < argv.length; ++i) {
Expand All @@ -290,8 +294,6 @@ class Application: Gtk.Application
} else if (argv[i] == "-e") {
command = argv[i + 1:argv.length];
i = argv.length - 1;
} else if (argv[i] == "-role") {
role = argv[++i];
} else if (argv[i] == "-update") {
update_colors = true;
}
Expand All @@ -315,7 +317,7 @@ class Application: Gtk.Application
command = { shell };
}

new TerminalWindow(this, command, title, font, fg, bg, palette, role);
new TerminalWindow(this, command, title, font, fg, bg, palette);
return 0;
}

Expand Down