This commit is contained in:
Mitchell Hashimoto
2023-11-29 15:05:28 -08:00
parent dcbe0b8a5f
commit 995e4e3757
3 changed files with 37 additions and 4 deletions

View File

@ -2013,7 +2013,10 @@ pub fn mouseButtonCallback(
fn linkAtPos( fn linkAtPos(
self: *Surface, self: *Surface,
pos: apprt.CursorPos, pos: apprt.CursorPos,
) !?DerivedConfig.Link { ) !?struct {
DerivedConfig.Link,
terminal.Selection,
} {
// If we have no configured links we can save a lot of work // If we have no configured links we can save a lot of work
if (self.config.links.len == 0) return null; if (self.config.links.len == 0) return null;
@ -2037,7 +2040,7 @@ fn linkAtPos(
defer match.deinit(); defer match.deinit();
const sel = match.selection(); const sel = match.selection();
if (!sel.contains(mouse_pt)) continue; if (!sel.contains(mouse_pt)) continue;
return link; return .{ link, sel };
} }
} }
@ -2046,9 +2049,22 @@ fn linkAtPos(
/// Attempt to invoke the action of any link that is under the /// Attempt to invoke the action of any link that is under the
/// given position. /// given position.
///
/// Requires the renderer state mutex is held.
fn processLinks(self: *Surface, pos: apprt.CursorPos) !bool { fn processLinks(self: *Surface, pos: apprt.CursorPos) !bool {
const link = try self.linkAtPos(pos) orelse return false; const link, const sel = try self.linkAtPos(pos) orelse return false;
log.info("link clicked action={}", .{link.action}); switch (link.action) {
.open => {
const str = try self.io.terminal.screen.selectionString(
self.alloc,
sel,
false,
);
defer self.alloc.free(str);
try internal_os.open(self.alloc, str);
},
}
return true; return true;
} }

View File

@ -9,6 +9,7 @@ pub usingnamespace @import("homedir.zig");
pub usingnamespace @import("locale.zig"); pub usingnamespace @import("locale.zig");
pub usingnamespace @import("macos_version.zig"); pub usingnamespace @import("macos_version.zig");
pub usingnamespace @import("mouse.zig"); pub usingnamespace @import("mouse.zig");
pub usingnamespace @import("open.zig");
pub usingnamespace @import("pipe.zig"); pub usingnamespace @import("pipe.zig");
pub usingnamespace @import("resourcesdir.zig"); pub usingnamespace @import("resourcesdir.zig");
pub const TempDir = @import("TempDir.zig"); pub const TempDir = @import("TempDir.zig");

16
src/os/open.zig Normal file
View File

@ -0,0 +1,16 @@
const std = @import("std");
const builtin = @import("builtin");
const Allocator = std.mem.Allocator;
/// Open a URL in the default handling application.
pub fn open(alloc: Allocator, url: []const u8) !void {
const argv = switch (builtin.os.tag) {
.linux => &.{ "xdg-open", url },
.macos => &.{ "open", url },
.windows => &.{ "rundll32", "url.dll,FileProtocolHandler", url },
else => @compileError("unsupported OS"),
};
var exe = std.process.Child.init(argv, alloc);
try exe.spawn();
}