Merge remote-tracking branch 'upstream/main'

This commit is contained in:
Raiden1411
2023-11-03 09:38:45 +00:00
16 changed files with 127 additions and 23 deletions

View File

@@ -2169,19 +2169,19 @@ pub fn performBindingAction(self: *Surface, action: input.Binding.Action) !bool
.reload_config => try self.app.reloadConfig(self.rt_app),
.csi => |data| {
// We need to send the CSI sequence as a single write request.
.csi, .esc => |data| {
// We need to send the CSI/ESC sequence as a single write request.
// If you split it across two then the shell can interpret it
// as two literals.
var buf: [128]u8 = undefined;
const full_data = try std.fmt.bufPrint(&buf, "\x1b[{s}", .{data});
const full_data = try std.fmt.bufPrint(&buf, "\x1b{s}{s}", .{if(action==.csi)"["else"", data});
_ = self.io_thread.mailbox.push(try termio.Message.writeReq(
self.alloc,
full_data,
), .{ .forever = {} });
try self.io_thread.wakeup.notify();
// CSI triggers a scroll.
// CSI/ESC triggers a scroll.
{
self.renderer_state.mutex.lock();
defer self.renderer_state.mutex.unlock();

View File

@@ -353,6 +353,7 @@ pub const Surface = struct {
win.setScrollCallback(scrollCallback);
win.setCursorPosCallback(cursorPosCallback);
win.setMouseButtonCallback(mouseButtonCallback);
win.setDropCallback(dropCallback);
// Build our result
self.* = .{
@@ -964,4 +965,39 @@ pub const Surface = struct {
return;
};
}
fn dropCallback(window: glfw.Window, paths: [][*:0]const u8) void {
const tracy = trace(@src());
defer tracy.end();
const surface = window.getUserPointer(CoreSurface) orelse return;
var list = std.ArrayList(u8).init(surface.alloc);
defer list.deinit();
for (paths) |path| {
const path_slice = std.mem.span(path);
// preallocate worst case of escaping every char + space
list.ensureTotalCapacity(path_slice.len * 2 + 1) catch |err| {
log.err("error in drop callback err={}", .{err});
return;
};
const writer = list.writer();
for (path_slice) |c| {
if (std.mem.indexOfScalar(u8, "\\ ()[]{}<>\"'`!#$&;|*?\t", c)) |_| {
writer.print("\\{c}", .{c}) catch unreachable; // memory preallocated
} else writer.writeByte(c) catch unreachable; // same here
}
writer.writeByte(' ') catch unreachable; // separate paths
surface.textCallback(list.items) catch |err| {
log.err("error in drop callback err={}", .{err});
return;
};
list.clearRetainingCapacity(); // avoid unnecessary reallocations
}
}
};

View File

@@ -19,6 +19,7 @@ const internal_os = @import("../../os/main.zig");
const Config = configpkg.Config;
const CoreApp = @import("../../App.zig");
const CoreSurface = @import("../../Surface.zig");
const build_options = @import("build_options");
const Surface = @import("Surface.zig");
const Window = @import("Window.zig");
@@ -52,6 +53,9 @@ running: bool = true,
pub fn init(core_app: *CoreApp, opts: Options) !App {
_ = opts;
// Initialize libadwaita
if (build_options.libadwaita) c.adw_init();
// Load our configuration
var config = try Config.load(core_app.alloc);
errdefer config.deinit();
@@ -63,6 +67,18 @@ pub fn init(core_app: *CoreApp, opts: Options) !App {
}
}
// Set the style based on our configuration file
if (build_options.libadwaita) {
c.adw_style_manager_set_color_scheme(
c.adw_style_manager_get_default(),
switch (config.@"window-theme") {
.system => c.ADW_COLOR_SCHEME_PREFER_LIGHT,
.dark => c.ADW_COLOR_SCHEME_FORCE_DARK,
.light => c.ADW_COLOR_SCHEME_FORCE_LIGHT,
},
);
}
// The "none" cursor is used for hiding the cursor
const cursor_none = c.gdk_cursor_new_from_name("none", null);
errdefer if (cursor_none) |cursor| c.g_object_unref(cursor);

View File

@@ -1,5 +1,6 @@
const c = @cImport({
@cInclude("gtk/gtk.h");
@cInclude("libadwaita-1/adwaita.h");
});
pub usingnamespace c;

View File

@@ -321,6 +321,8 @@ command: ?[]const u8 = null,
/// is removed, and the key will be sent through to the child command
/// if it is printable.
/// - "csi:text" - Send a CSI sequence. i.e. "csi:A" sends "cursor up".
/// - "esc:text" - Send an Escape sequence. i.e. "esc:d" deletes to the
/// end of the word to the right.
///
/// Some notes for the action:
///
@@ -378,7 +380,7 @@ keybind: Keybinds = .{},
/// also be set to "light" or "dark" to force a specific theme regardless
/// of the system settings.
///
/// This is currently only supported on macOS.
/// This is currently only supported on macOS and linux.
@"window-theme": WindowTheme = .system,
/// The initial window size. This size is in terminal grid cells by default.

View File

@@ -1,6 +1,7 @@
const std = @import("std");
const assert = std.debug.assert;
const Allocator = std.mem.Allocator;
const ziglyph = @import("ziglyph");
const font = @import("../main.zig");
const shape = @import("../shape.zig");
const terminal = @import("../../terminal/main.zig");
@@ -109,12 +110,20 @@ pub const RunIterator = struct {
// presentation format must be directly adjacent to the codepoint.
var it = self.row.codepointIterator(j);
if (it.next()) |cp| {
if (cp == 0xFE0E) break :p font.Presentation.text;
if (cp == 0xFE0F) break :p font.Presentation.emoji;
if (cp == 0xFE0E) break :p .text;
if (cp == 0xFE0F) break :p .emoji;
}
break :p null;
} else null;
} else emoji: {
// If we're not a grapheme, our individual char could be
// an emoji so we want to check if we expect emoji presentation.
if (ziglyph.emoji.isEmojiPresentation(@intCast(cell.char))) {
break :emoji .emoji;
}
break :emoji .text;
};
// If our cursor is on this line then we break the run around the
// cursor. This means that any row with a cursor has at least

View File

@@ -117,6 +117,9 @@ pub const Action = union(enum) {
/// without the CSI header ("ESC ]" or "\x1b]").
csi: []const u8,
/// Send an ESC sequence.
esc: []const u8,
/// Send data to the pty depending on whether cursor key mode is
/// enabled ("application") or disabled ("normal").
cursor_key: CursorKey,
@@ -665,6 +668,12 @@ test "parse: action with string" {
try testing.expect(binding.action == .csi);
try testing.expectEqualStrings("A", binding.action.csi);
}
// parameter
{
const binding = try parse("a=esc:A");
try testing.expect(binding.action == .esc);
try testing.expectEqualStrings("A", binding.action.esc);
}
}
test "parse: action with enum" {