refactor: lots more writergate fixes - first successful build
This commit is contained in:
parent
5094aa8c85
commit
bf0d4402ea
48 changed files with 404 additions and 413 deletions
|
|
@ -6,8 +6,8 @@
|
||||||
|
|
||||||
.dependencies = .{
|
.dependencies = .{
|
||||||
.syntax = .{
|
.syntax = .{
|
||||||
.url = "git+https://github.com/neurocyte/flow-syntax?ref=master#4c0218f805ef75c379903f402bfe764da636399e",
|
.url = "git+https://github.com/neurocyte/flow-syntax?ref=master#05938cb0256b6028458234880bb750e0c368d750",
|
||||||
.hash = "flow_syntax-0.1.0-X8jOofgHAQAaHF-0YdLYjmCvuXNxId3zGR01Q6ee8R1F",
|
.hash = "flow_syntax-0.1.0-X8jOofgHAQBCPwteYCfJmIpwXgJo_4HmJeSp6tTf2xCf",
|
||||||
},
|
},
|
||||||
.flags = .{
|
.flags = .{
|
||||||
.url = "git+https://github.com/neurocyte/flags?ref=main#984b27948da3e4e40a253f76c85b51ec1a9ada11",
|
.url = "git+https://github.com/neurocyte/flags?ref=main#984b27948da3e4e40a253f76c85b51ec1a9ada11",
|
||||||
|
|
@ -18,8 +18,8 @@
|
||||||
.hash = "dizzy-1.0.0-q40X4YCRAAAGYO9QOZiYYSOwiiFlqZlecMuQcxPiBcXM",
|
.hash = "dizzy-1.0.0-q40X4YCRAAAGYO9QOZiYYSOwiiFlqZlecMuQcxPiBcXM",
|
||||||
},
|
},
|
||||||
.thespian = .{
|
.thespian = .{
|
||||||
.url = "git+https://github.com/neurocyte/thespian?ref=master#aa6c78f5cbda65def81e0e85296e94bdf7089f01",
|
.url = "git+https://github.com/neurocyte/thespian?ref=master#9361399898102fc03e497129f922a6eed00b7dd5",
|
||||||
.hash = "thespian-0.0.1-owFOjhAbBgAPbQ42WGwZqu3NLJR_3VgeAEsG4Ff8NK9O",
|
.hash = "thespian-0.0.1-owFOjr8eBgAlww8h9LxP3qYiPBzHp464MRyJ4gt5TsF3",
|
||||||
},
|
},
|
||||||
.themes = .{
|
.themes = .{
|
||||||
.url = "https://github.com/neurocyte/flow-themes/releases/download/master-952f9f630ea9544088fd30293666ee0650b7a690/flow-themes.tar.gz",
|
.url = "https://github.com/neurocyte/flow-themes/releases/download/master-952f9f630ea9544088fd30293666ee0650b7a690/flow-themes.tar.gz",
|
||||||
|
|
@ -30,8 +30,8 @@
|
||||||
.hash = "fuzzig-0.1.1-Ji0xivxIAQBD0g8O_NV_0foqoPf3elsg9Sc3pNfdVH4D",
|
.hash = "fuzzig-0.1.1-Ji0xivxIAQBD0g8O_NV_0foqoPf3elsg9Sc3pNfdVH4D",
|
||||||
},
|
},
|
||||||
.vaxis = .{
|
.vaxis = .{
|
||||||
.url = "git+https://github.com/neurocyte/libvaxis?ref=main#35c384757b713c206d11efd76448eaea429f587e",
|
.url = "git+https://github.com/neurocyte/libvaxis?ref=main#04d6aceeef0d8b220a6084fad1a989853afece65",
|
||||||
.hash = "vaxis-0.5.1-BWNV_GQeCQBDaH91XVg4ql_F5RBv__F_Y-_eQ2nCuyNk",
|
.hash = "vaxis-0.5.1-BWNV_BMgCQDXdZzABeY4F_xwgE7nHFtYEP07KgEwJWo8",
|
||||||
},
|
},
|
||||||
.zeit = .{
|
.zeit = .{
|
||||||
.url = "git+https://github.com/rockorager/zeit?ref=zig-0.15#ed2ca60db118414bda2b12df2039e33bad3b0b88",
|
.url = "git+https://github.com/rockorager/zeit?ref=zig-0.15#ed2ca60db118414bda2b12df2039e33bad3b0b88",
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,6 @@ pub const Manager = @import("Manager.zig");
|
||||||
pub const Cursor = @import("Cursor.zig");
|
pub const Cursor = @import("Cursor.zig");
|
||||||
pub const View = @import("View.zig");
|
pub const View = @import("View.zig");
|
||||||
pub const Selection = @import("Selection.zig");
|
pub const Selection = @import("Selection.zig");
|
||||||
pub const MetaWriter = std.ArrayListUnmanaged(u8).Writer;
|
|
||||||
|
|
||||||
pub const Metrics = struct {
|
pub const Metrics = struct {
|
||||||
ctx: *const anyopaque,
|
ctx: *const anyopaque,
|
||||||
|
|
@ -410,7 +409,7 @@ const Node = union(enum) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_from_line_begin_const(self: *const Node, line: usize, f: Walker.F, ctx: *anyopaque, metrics: Metrics) !bool {
|
pub fn walk_from_line_begin_const(self: *const Node, line: usize, f: Walker.F, ctx: *anyopaque, metrics: Metrics) anyerror!bool {
|
||||||
const result = self.walk_from_line_begin_const_internal(line, f, ctx, metrics);
|
const result = self.walk_from_line_begin_const_internal(line, f, ctx, metrics);
|
||||||
if (result.err) |e| return e;
|
if (result.err) |e| return e;
|
||||||
return result.found_;
|
return result.found_;
|
||||||
|
|
@ -498,7 +497,7 @@ const Node = union(enum) {
|
||||||
|
|
||||||
const EgcF = *const fn (ctx: *anyopaque, egc: []const u8, wcwidth: usize, metrics: Metrics) Walker;
|
const EgcF = *const fn (ctx: *anyopaque, egc: []const u8, wcwidth: usize, metrics: Metrics) Walker;
|
||||||
|
|
||||||
pub fn walk_egc_forward(self: *const Node, line: usize, walker_f: EgcF, walker_ctx: *anyopaque, metrics_: Metrics) !void {
|
pub fn walk_egc_forward(self: *const Node, line: usize, walker_f: EgcF, walker_ctx: *anyopaque, metrics_: Metrics) anyerror!void {
|
||||||
const Ctx = struct {
|
const Ctx = struct {
|
||||||
walker_f: EgcF,
|
walker_f: EgcF,
|
||||||
walker_ctx: @TypeOf(walker_ctx),
|
walker_ctx: @TypeOf(walker_ctx),
|
||||||
|
|
@ -1541,10 +1540,10 @@ pub fn redo(self: *Self) error{Stop}![]const u8 {
|
||||||
return h.meta;
|
return h.meta;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write_state(self: *const Self, writer: MetaWriter) error{ Stop, OutOfMemory }!void {
|
pub fn write_state(self: *const Self, writer: *std.Io.Writer) error{ Stop, OutOfMemory, WriteFailed }!void {
|
||||||
var content = std.ArrayListUnmanaged(u8).empty;
|
var content: std.Io.Writer.Allocating = .init(self.external_allocator);
|
||||||
defer content.deinit(self.external_allocator);
|
defer content.deinit();
|
||||||
try self.root.store(content.writer(self.external_allocator), self.file_eol_mode);
|
try self.root.store(&content.writer, self.file_eol_mode);
|
||||||
const dirty = self.is_dirty();
|
const dirty = self.is_dirty();
|
||||||
|
|
||||||
try cbor.writeArrayHeader(writer, 9);
|
try cbor.writeArrayHeader(writer, 9);
|
||||||
|
|
@ -1556,7 +1555,7 @@ pub fn write_state(self: *const Self, writer: MetaWriter) error{ Stop, OutOfMemo
|
||||||
try cbor.writeValue(writer, dirty);
|
try cbor.writeValue(writer, dirty);
|
||||||
try cbor.writeValue(writer, self.meta);
|
try cbor.writeValue(writer, self.meta);
|
||||||
try cbor.writeValue(writer, self.file_type_name);
|
try cbor.writeValue(writer, self.file_type_name);
|
||||||
try cbor.writeValue(writer, content.items);
|
try cbor.writeValue(writer, content.written());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const ExtractStateOperation = enum { none, open_file };
|
pub const ExtractStateOperation = enum { none, open_file };
|
||||||
|
|
|
||||||
|
|
@ -188,7 +188,7 @@ pub fn test_at(self: *const Self, root: Buffer.Root, pred: *const fn (c: []const
|
||||||
return root.test_at(pred, self.row, self.col, metrics);
|
return root.test_at(pred, self.row, self.col, metrics);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write(self: *const Self, writer: Buffer.MetaWriter) !void {
|
pub fn write(self: *const Self, writer: *std.Io.Writer) !void {
|
||||||
try cbor.writeValue(writer, .{
|
try cbor.writeValue(writer, .{
|
||||||
self.row,
|
self.row,
|
||||||
self.col,
|
self.col,
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ pub fn open_scratch(self: *Self, file_path: []const u8, content: []const u8) Buf
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write_state(self: *const Self, writer: Buffer.MetaWriter) error{ Stop, OutOfMemory }!void {
|
pub fn write_state(self: *const Self, writer: *std.Io.Writer) error{ Stop, OutOfMemory, WriteFailed }!void {
|
||||||
const buffers = self.list_unordered(self.allocator) catch return;
|
const buffers = self.list_unordered(self.allocator) catch return;
|
||||||
defer self.allocator.free(buffers);
|
defer self.allocator.free(buffers);
|
||||||
try cbor.writeArrayHeader(writer, buffers.len);
|
try cbor.writeArrayHeader(writer, buffers.len);
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
const cbor = @import("cbor");
|
const cbor = @import("cbor");
|
||||||
|
const Writer = @import("std").Io.Writer;
|
||||||
|
|
||||||
const Buffer = @import("Buffer.zig");
|
const Buffer = @import("Buffer.zig");
|
||||||
const Cursor = @import("Cursor.zig");
|
const Cursor = @import("Cursor.zig");
|
||||||
|
|
@ -45,7 +46,7 @@ pub fn normalize(self: *Self) void {
|
||||||
if (self.is_reversed()) self.reverse();
|
if (self.is_reversed()) self.reverse();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write(self: *const Self, writer: Buffer.MetaWriter) !void {
|
pub fn write(self: *const Self, writer: *Writer) !void {
|
||||||
try cbor.writeArrayHeader(writer, 2);
|
try cbor.writeArrayHeader(writer, 2);
|
||||||
try self.begin.write(writer);
|
try self.begin.write(writer);
|
||||||
try self.end.write(writer);
|
try self.end.write(writer);
|
||||||
|
|
|
||||||
|
|
@ -124,7 +124,7 @@ pub fn clamp(self: *Self, cursor: *const Cursor, abs: bool) void {
|
||||||
self.clamp_col(cursor, abs);
|
self.clamp_col(cursor, abs);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write(self: *const Self, writer: Buffer.MetaWriter) !void {
|
pub fn write(self: *const Self, writer: *std.Io.Writer) !void {
|
||||||
try cbor.writeValue(writer, .{
|
try cbor.writeValue(writer, .{
|
||||||
self.row,
|
self.row,
|
||||||
self.col,
|
self.col,
|
||||||
|
|
|
||||||
|
|
@ -39,9 +39,9 @@ pub const AsyncDiffer = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn text_from_root(root: Buffer.Root, eol_mode: Buffer.EolMode) ![]const u8 {
|
fn text_from_root(root: Buffer.Root, eol_mode: Buffer.EolMode) ![]const u8 {
|
||||||
var text = std.ArrayList(u8).init(std.heap.c_allocator);
|
var text: std.Io.Writer.Allocating = .init(std.heap.c_allocator);
|
||||||
defer text.deinit();
|
defer text.deinit();
|
||||||
try root.store(text.writer(), eol_mode);
|
try root.store(&text.writer, eol_mode);
|
||||||
return text.toOwnedSlice();
|
return text.toOwnedSlice();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -753,9 +753,9 @@ pub fn get_or_create_namespace_config_file(allocator: std.mem.Allocator, namespa
|
||||||
const KeyEventSequenceFmt = struct {
|
const KeyEventSequenceFmt = struct {
|
||||||
key_events: []const KeyEvent,
|
key_events: []const KeyEvent,
|
||||||
|
|
||||||
pub fn format(self: @This(), comptime _: []const u8, _: std.fmt.FormatOptions, writer: anytype) !void {
|
pub fn format(self: @This(), writer: anytype) !void {
|
||||||
for (self.key_events) |key_event|
|
for (self.key_events) |key_event|
|
||||||
try writer.print(" {}", .{input.key_event_short_fmt(key_event)});
|
try writer.print(" {f}", .{input.key_event_short_fmt(key_event)});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -207,7 +207,7 @@ pub fn putstr(self: *Plane, text: []const u8) !usize {
|
||||||
|
|
||||||
pub fn putstr_unicode(self: *Plane, text: []const u8) !usize {
|
pub fn putstr_unicode(self: *Plane, text: []const u8) !usize {
|
||||||
var result: usize = 0;
|
var result: usize = 0;
|
||||||
var iter = self.window.screen.unicode.graphemeIterator(text);
|
var iter = self.window.unicode.graphemeIterator(text);
|
||||||
while (iter.next()) |grapheme| {
|
while (iter.next()) |grapheme| {
|
||||||
const s_ = grapheme.bytes(text);
|
const s_ = grapheme.bytes(text);
|
||||||
const s = switch (s_[0]) {
|
const s = switch (s_[0]) {
|
||||||
|
|
|
||||||
|
|
@ -169,7 +169,7 @@ fn tryUtf8Decode(bytes: []const u8) !u21 {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ucs32_to_utf8(ucs32: []const u32, utf8: []u8) !usize {
|
pub fn ucs32_to_utf8(ucs32: []const u32, utf8: []u8) error{ Utf8CannotEncodeSurrogateHalf, CodepointTooLarge }!usize {
|
||||||
return @intCast(try unicode.utf8Encode(@intCast(ucs32[0]), utf8));
|
return @intCast(try unicode.utf8Encode(@intCast(ucs32[0]), utf8));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -392,7 +392,7 @@ pub fn key_short_fmt(key_: Key) struct {
|
||||||
var key_string = utils.key_id_string_short(self.key);
|
var key_string = utils.key_id_string_short(self.key);
|
||||||
var buf: [6]u8 = undefined;
|
var buf: [6]u8 = undefined;
|
||||||
if (key_string.len == 0) {
|
if (key_string.len == 0) {
|
||||||
const bytes = try ucs32_to_utf8(&[_]u32{self.key}, &buf);
|
const bytes = ucs32_to_utf8(&[_]u32{self.key}, &buf) catch return error.WriteFailed;
|
||||||
key_string = buf[0..bytes];
|
key_string = buf[0..bytes];
|
||||||
}
|
}
|
||||||
try writer.writeAll(key_string);
|
try writer.writeAll(key_string);
|
||||||
|
|
|
||||||
|
|
@ -85,7 +85,7 @@ pub fn init(allocator: std.mem.Allocator, handler_ctx: *anyopaque, no_alternate:
|
||||||
.no_alternate = no_alternate,
|
.no_alternate = no_alternate,
|
||||||
.event_buffer = .init(allocator),
|
.event_buffer = .init(allocator),
|
||||||
.input_buffer = .init(allocator),
|
.input_buffer = .init(allocator),
|
||||||
.bracketed_paste_buffer = std.ArrayList(u8).init(allocator),
|
.bracketed_paste_buffer = .init(allocator),
|
||||||
.handler_ctx = handler_ctx,
|
.handler_ctx = handler_ctx,
|
||||||
.logger = log.logger(log_name),
|
.logger = log.logger(log_name),
|
||||||
.loop = undefined,
|
.loop = undefined,
|
||||||
|
|
@ -96,7 +96,7 @@ pub fn init(allocator: std.mem.Allocator, handler_ctx: *anyopaque, no_alternate:
|
||||||
pub fn deinit(self: *Self) void {
|
pub fn deinit(self: *Self) void {
|
||||||
panic_cleanup = null;
|
panic_cleanup = null;
|
||||||
self.loop.stop();
|
self.loop.stop();
|
||||||
self.vx.deinit(self.allocator, self.tty.anyWriter());
|
self.vx.deinit(self.allocator, self.tty.writer());
|
||||||
self.tty.deinit();
|
self.tty.deinit();
|
||||||
self.allocator.free(self.tty_buffer);
|
self.allocator.free(self.tty_buffer);
|
||||||
self.bracketed_paste_buffer.deinit();
|
self.bracketed_paste_buffer.deinit();
|
||||||
|
|
@ -117,7 +117,7 @@ pub fn panic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace, ret_
|
||||||
const cleanup = panic_cleanup;
|
const cleanup = panic_cleanup;
|
||||||
panic_cleanup = null;
|
panic_cleanup = null;
|
||||||
if (cleanup) |self| {
|
if (cleanup) |self| {
|
||||||
self.vx.deinit(self.allocator, self.tty.anyWriter());
|
self.vx.deinit(self.allocator, self.tty.writer());
|
||||||
self.tty.deinit();
|
self.tty.deinit();
|
||||||
}
|
}
|
||||||
return std.debug.defaultPanic(msg, ret_addr orelse @returnAddress());
|
return std.debug.defaultPanic(msg, ret_addr orelse @returnAddress());
|
||||||
|
|
@ -158,7 +158,7 @@ fn handle_crash(sig: i32, info: *const std.posix.siginfo_t, ctx_ptr: ?*anyopaque
|
||||||
panic_cleanup = null;
|
panic_cleanup = null;
|
||||||
|
|
||||||
if (cleanup) |self| {
|
if (cleanup) |self| {
|
||||||
self.vx.deinit(self.allocator, self.tty.anyWriter());
|
self.vx.deinit(self.allocator, self.tty.writer());
|
||||||
self.tty.deinit();
|
self.tty.deinit();
|
||||||
}
|
}
|
||||||
if (builtin.os.tag == .linux and jit_debugger_enabled) {
|
if (builtin.os.tag == .linux and jit_debugger_enabled) {
|
||||||
|
|
@ -194,14 +194,14 @@ pub fn run(self: *Self) Error!void {
|
||||||
self.vx.enable_workarounds = true;
|
self.vx.enable_workarounds = true;
|
||||||
|
|
||||||
panic_cleanup = .{ .allocator = self.allocator, .tty = &self.tty, .vx = &self.vx };
|
panic_cleanup = .{ .allocator = self.allocator, .tty = &self.tty, .vx = &self.vx };
|
||||||
if (!self.no_alternate) self.vx.enterAltScreen(self.tty.anyWriter()) catch return error.TtyWriteError;
|
if (!self.no_alternate) self.vx.enterAltScreen(self.tty.writer()) catch return error.TtyWriteError;
|
||||||
if (builtin.os.tag == .windows) {
|
if (builtin.os.tag == .windows) {
|
||||||
try self.resize(.{ .rows = 25, .cols = 80, .x_pixel = 0, .y_pixel = 0 }); // dummy resize to fully init vaxis
|
try self.resize(.{ .rows = 25, .cols = 80, .x_pixel = 0, .y_pixel = 0 }); // dummy resize to fully init vaxis
|
||||||
} else {
|
} else {
|
||||||
self.sigwinch() catch return error.TtyWriteError;
|
self.sigwinch() catch return error.TtyWriteError;
|
||||||
}
|
}
|
||||||
self.vx.setBracketedPaste(self.tty.anyWriter(), true) catch return error.TtyWriteError;
|
self.vx.setBracketedPaste(self.tty.writer(), true) catch return error.TtyWriteError;
|
||||||
self.vx.queryTerminalSend(self.tty.anyWriter()) catch return error.TtyWriteError;
|
self.vx.queryTerminalSend(self.tty.writer()) catch return error.TtyWriteError;
|
||||||
|
|
||||||
self.loop = Loop.init(&self.tty, &self.vx);
|
self.loop = Loop.init(&self.tty, &self.vx);
|
||||||
try self.loop.start();
|
try self.loop.start();
|
||||||
|
|
@ -209,8 +209,8 @@ pub fn run(self: *Self) Error!void {
|
||||||
|
|
||||||
pub fn render(self: *Self) !void {
|
pub fn render(self: *Self) !void {
|
||||||
if (in_panic.load(.acquire)) return;
|
if (in_panic.load(.acquire)) return;
|
||||||
try self.vx.render(&self.tty.writer.interface);
|
try self.vx.render(self.tty.writer());
|
||||||
try self.tty.writer.interface.flush();
|
try self.tty.writer().flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn sigwinch(self: *Self) !void {
|
pub fn sigwinch(self: *Self) !void {
|
||||||
|
|
@ -219,7 +219,7 @@ pub fn sigwinch(self: *Self) !void {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn resize(self: *Self, ws: vaxis.Winsize) error{ TtyWriteError, OutOfMemory, WriteFailed }!void {
|
fn resize(self: *Self, ws: vaxis.Winsize) error{ TtyWriteError, OutOfMemory, WriteFailed }!void {
|
||||||
self.vx.resize(self.allocator, self.tty.anyWriter(), ws) catch return error.TtyWriteError;
|
self.vx.resize(self.allocator, self.tty.writer(), ws) catch return error.TtyWriteError;
|
||||||
self.vx.queueRefresh();
|
self.vx.queueRefresh();
|
||||||
if (self.dispatch_event) |f| f(self.handler_ctx, try self.fmtmsg(.{"resize"}));
|
if (self.dispatch_event) |f| f(self.handler_ctx, try self.fmtmsg(.{"resize"}));
|
||||||
}
|
}
|
||||||
|
|
@ -373,8 +373,8 @@ pub fn process_renderer_event(self: *Self, msg: []const u8) Error!void {
|
||||||
},
|
},
|
||||||
.cap_da1 => {
|
.cap_da1 => {
|
||||||
self.queries_done = true;
|
self.queries_done = true;
|
||||||
self.vx.enableDetectedFeatures(self.tty.anyWriter()) catch |e| self.logger.err("enable features", e);
|
self.vx.enableDetectedFeatures(self.tty.writer()) catch |e| self.logger.err("enable features", e);
|
||||||
self.vx.setMouseMode(self.tty.anyWriter(), true) catch return error.TtyWriteError;
|
self.vx.setMouseMode(self.tty.writer(), true) catch return error.TtyWriteError;
|
||||||
},
|
},
|
||||||
.cap_kitty_keyboard => {
|
.cap_kitty_keyboard => {
|
||||||
self.logger.print("kitty keyboard capability detected", .{});
|
self.logger.print("kitty keyboard capability detected", .{});
|
||||||
|
|
@ -451,37 +451,37 @@ fn handle_bracketed_paste_error(self: *Self, e: Error) !void {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_terminal_title(self: *Self, text: []const u8) void {
|
pub fn set_terminal_title(self: *Self, text: []const u8) void {
|
||||||
self.vx.setTitle(self.tty.anyWriter(), text) catch {};
|
self.vx.setTitle(self.tty.writer(), text) catch {};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_terminal_style(self: *Self, style_: Style) void {
|
pub fn set_terminal_style(self: *Self, style_: Style) void {
|
||||||
if (style_.fg) |color|
|
if (style_.fg) |color|
|
||||||
self.vx.setTerminalForegroundColor(self.tty.anyWriter(), vaxis.Cell.Color.rgbFromUint(@intCast(color.color)).rgb) catch {};
|
self.vx.setTerminalForegroundColor(self.tty.writer(), vaxis.Cell.Color.rgbFromUint(@intCast(color.color)).rgb) catch {};
|
||||||
if (style_.bg) |color|
|
if (style_.bg) |color|
|
||||||
self.vx.setTerminalBackgroundColor(self.tty.anyWriter(), vaxis.Cell.Color.rgbFromUint(@intCast(color.color)).rgb) catch {};
|
self.vx.setTerminalBackgroundColor(self.tty.writer(), vaxis.Cell.Color.rgbFromUint(@intCast(color.color)).rgb) catch {};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_terminal_cursor_color(self: *Self, color: Color) void {
|
pub fn set_terminal_cursor_color(self: *Self, color: Color) void {
|
||||||
self.vx.setTerminalCursorColor(self.tty.anyWriter(), vaxis.Cell.Color.rgbFromUint(@intCast(color.color)).rgb) catch {};
|
self.vx.setTerminalCursorColor(self.tty.writer(), vaxis.Cell.Color.rgbFromUint(@intCast(color.color)).rgb) catch {};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_terminal_secondary_cursor_color(self: *Self, color: Color) void {
|
pub fn set_terminal_secondary_cursor_color(self: *Self, color: Color) void {
|
||||||
const rgb = RGB.from_u24(color.color);
|
const rgb = RGB.from_u24(color.color);
|
||||||
self.tty.anyWriter().print("\x1b[>40;2:{d}:{d}:{d} q", .{ rgb.r, rgb.g, rgb.b }) catch {};
|
self.tty.writer().print("\x1b[>40;2:{d}:{d}:{d} q", .{ rgb.r, rgb.g, rgb.b }) catch {};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_terminal_working_directory(self: *Self, absolute_path: []const u8) void {
|
pub fn set_terminal_working_directory(self: *Self, absolute_path: []const u8) void {
|
||||||
self.vx.setTerminalWorkingDirectory(self.tty.anyWriter(), absolute_path) catch {};
|
self.vx.setTerminalWorkingDirectory(self.tty.writer(), absolute_path) catch {};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn copy_to_system_clipboard(self: *Self, text: []const u8) void {
|
pub fn copy_to_system_clipboard(self: *Self, text: []const u8) void {
|
||||||
var bufferedWriter = self.tty.bufferedWriter();
|
var writer = self.tty.writer();
|
||||||
self.vx.copyToSystemClipboard(bufferedWriter.writer().any(), text, self.allocator) catch |e| log.logger(log_name).err("copy_to_system_clipboard", e);
|
self.vx.copyToSystemClipboard(writer, text, self.allocator) catch |e| log.logger(log_name).err("copy_to_system_clipboard", e);
|
||||||
bufferedWriter.flush() catch @panic("flush failed");
|
writer.flush() catch @panic("flush failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn request_system_clipboard(self: *Self) void {
|
pub fn request_system_clipboard(self: *Self) void {
|
||||||
self.vx.requestSystemClipboard(self.tty.anyWriter()) catch |e| log.logger(log_name).err("request_system_clipboard", e);
|
self.vx.requestSystemClipboard(self.tty.writer()) catch |e| log.logger(log_name).err("request_system_clipboard", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
const win32 = struct {
|
const win32 = struct {
|
||||||
|
|
@ -555,11 +555,11 @@ pub fn cursor_disable(self: *Self) void {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn clear_all_multi_cursors(self: *Self) !void {
|
pub fn clear_all_multi_cursors(self: *Self) !void {
|
||||||
try self.tty.anyWriter().print("\x1b[>0;4 q", .{});
|
try self.tty.writer().print("\x1b[>0;4 q", .{});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn show_multi_cursor_yx(self: *Self, y: c_int, x: c_int) !void {
|
pub fn show_multi_cursor_yx(self: *Self, y: c_int, x: c_int) !void {
|
||||||
try self.tty.anyWriter().print("\x1b[>29;2:{d}:{d} q", .{ y + 1, x + 1 });
|
try self.tty.writer().print("\x1b[>29;2:{d}:{d} q", .{ y + 1, x + 1 });
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sync_mod_state(self: *Self, keypress: u32, modifiers: vaxis.Key.Modifiers) !void {
|
fn sync_mod_state(self: *Self, keypress: u32, modifiers: vaxis.Key.Modifiers) !void {
|
||||||
|
|
@ -644,7 +644,7 @@ const Loop = struct {
|
||||||
pub fn stop(self: *Loop) void {
|
pub fn stop(self: *Loop) void {
|
||||||
self.should_quit = true;
|
self.should_quit = true;
|
||||||
// trigger a read
|
// trigger a read
|
||||||
self.vaxis.deviceStatusReport(self.tty.anyWriter()) catch {};
|
self.vaxis.deviceStatusReport(self.tty.writer()) catch {};
|
||||||
|
|
||||||
if (self.thread) |thread| {
|
if (self.thread) |thread| {
|
||||||
thread.join();
|
thread.join();
|
||||||
|
|
|
||||||
|
|
@ -1097,7 +1097,7 @@ pub fn printSourceAtAddress(debug_info: *SelfInfo, out_stream: anytype, address:
|
||||||
}
|
}
|
||||||
|
|
||||||
fn printLineInfo(
|
fn printLineInfo(
|
||||||
out_stream: anytype,
|
out_stream: *std.Io.Writer,
|
||||||
source_location: ?SourceLocation,
|
source_location: ?SourceLocation,
|
||||||
address: usize,
|
address: usize,
|
||||||
symbol_name: []const u8,
|
symbol_name: []const u8,
|
||||||
|
|
@ -1128,7 +1128,7 @@ fn printLineInfo(
|
||||||
// The caret already takes one char
|
// The caret already takes one char
|
||||||
const space_needed = @as(usize, @intCast(sl.column - 1));
|
const space_needed = @as(usize, @intCast(sl.column - 1));
|
||||||
|
|
||||||
try out_stream.writeByteNTimes(' ', space_needed);
|
for (0..space_needed) |_| try out_stream.writeByte(' ');
|
||||||
try tty_config.setColor(out_stream, .green);
|
try tty_config.setColor(out_stream, .green);
|
||||||
try out_stream.writeAll("^");
|
try out_stream.writeAll("^");
|
||||||
try tty_config.setColor(out_stream, .reset);
|
try tty_config.setColor(out_stream, .reset);
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,7 @@ const Process = struct {
|
||||||
query: []const u8,
|
query: []const u8,
|
||||||
receiver: Receiver,
|
receiver: Receiver,
|
||||||
sp: ?tp.subprocess = null,
|
sp: ?tp.subprocess = null,
|
||||||
output: std.ArrayList(u8),
|
output: std.Io.Writer.Allocating,
|
||||||
parent: tp.pid,
|
parent: tp.pid,
|
||||||
tag: [:0]const u8,
|
tag: [:0]const u8,
|
||||||
logger: log.Logger,
|
logger: log.Logger,
|
||||||
|
|
@ -90,7 +90,7 @@ const Process = struct {
|
||||||
.allocator = allocator,
|
.allocator = allocator,
|
||||||
.query = try allocator.dupe(u8, query),
|
.query = try allocator.dupe(u8, query),
|
||||||
.receiver = Receiver.init(receive, self),
|
.receiver = Receiver.init(receive, self),
|
||||||
.output = std.ArrayList(u8).init(allocator),
|
.output = .init(allocator),
|
||||||
.parent = tp.self_pid().clone(),
|
.parent = tp.self_pid().clone(),
|
||||||
.tag = try allocator.dupeZ(u8, tag),
|
.tag = try allocator.dupeZ(u8, tag),
|
||||||
.logger = log.logger(@typeName(Self)),
|
.logger = log.logger(@typeName(Self)),
|
||||||
|
|
@ -157,7 +157,7 @@ const Process = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_output(self: *Process, bytes: []const u8) !void {
|
fn handle_output(self: *Process, bytes: []const u8) !void {
|
||||||
try self.output.appendSlice(bytes);
|
try self.output.writer.writeAll(bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_terminated(self: *Process, m: tp.message) !void {
|
fn handle_terminated(self: *Process, m: tp.message) !void {
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@ pub const Error = error{
|
||||||
BadArrayAllocExtract,
|
BadArrayAllocExtract,
|
||||||
InvalidMapType,
|
InvalidMapType,
|
||||||
InvalidUnion,
|
InvalidUnion,
|
||||||
|
WriteFailed,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const OutputHandler = fn (context: usize, parent: tp.pid_ref, arg0: []const u8, output: []const u8) void;
|
pub const OutputHandler = fn (context: usize, parent: tp.pid_ref, arg0: []const u8, output: []const u8) void;
|
||||||
|
|
@ -300,20 +301,20 @@ const Process = struct {
|
||||||
fn parse_arg0_to_argv(allocator: std.mem.Allocator, arg0: *[]const u8) !tp.message {
|
fn parse_arg0_to_argv(allocator: std.mem.Allocator, arg0: *[]const u8) !tp.message {
|
||||||
// this is horribly simplistic
|
// this is horribly simplistic
|
||||||
// TODO: add quotes parsing and workspace variables, etc.
|
// TODO: add quotes parsing and workspace variables, etc.
|
||||||
var args = std.ArrayList([]const u8).init(allocator);
|
var args: std.ArrayList([]const u8) = .empty;
|
||||||
defer args.deinit();
|
defer args.deinit(allocator);
|
||||||
|
|
||||||
var it = std.mem.splitScalar(u8, arg0.*, ' ');
|
var it = std.mem.splitScalar(u8, arg0.*, ' ');
|
||||||
while (it.next()) |arg|
|
while (it.next()) |arg|
|
||||||
try args.append(arg);
|
try args.append(allocator, arg);
|
||||||
|
|
||||||
var msg_cb = std.ArrayList(u8).init(allocator);
|
var msg_cb: std.Io.Writer.Allocating = .init(allocator);
|
||||||
defer msg_cb.deinit();
|
defer msg_cb.deinit();
|
||||||
|
|
||||||
try cbor.writeArrayHeader(msg_cb.writer(), args.items.len);
|
try cbor.writeArrayHeader(&msg_cb.writer, args.items.len);
|
||||||
for (args.items) |arg|
|
for (args.items) |arg|
|
||||||
try cbor.writeValue(msg_cb.writer(), arg);
|
try cbor.writeValue(&msg_cb.writer, arg);
|
||||||
|
|
||||||
_ = try cbor.match(msg_cb.items, .{ tp.extract(arg0), tp.more });
|
_ = try cbor.match(msg_cb.written(), .{ tp.extract(arg0), tp.more });
|
||||||
return .{ .buf = try msg_cb.toOwnedSlice() };
|
return .{ .buf = try msg_cb.toOwnedSlice() };
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ fn remove_prefix_in_line(prefix: []const u8, text: []const u8, writer: TextWrite
|
||||||
|
|
||||||
pub fn toggle_prefix_in_text(prefix: []const u8, text: []const u8, allocator: std.mem.Allocator) ![]const u8 {
|
pub fn toggle_prefix_in_text(prefix: []const u8, text: []const u8, allocator: std.mem.Allocator) ![]const u8 {
|
||||||
var result = try std.ArrayList(u8).initCapacity(allocator, prefix.len + text.len);
|
var result = try std.ArrayList(u8).initCapacity(allocator, prefix.len + text.len);
|
||||||
const writer = result.writer();
|
const writer = result.writer(allocator);
|
||||||
var pos: usize = 0;
|
var pos: usize = 0;
|
||||||
var prefix_pos: usize = std.math.maxInt(usize);
|
var prefix_pos: usize = std.math.maxInt(usize);
|
||||||
var have_prefix = true;
|
var have_prefix = true;
|
||||||
|
|
@ -87,5 +87,5 @@ pub fn toggle_prefix_in_text(prefix: []const u8, text: []const u8, allocator: st
|
||||||
_ = try writer.write("\n");
|
_ = try writer.write("\n");
|
||||||
pos = next + 1;
|
pos = next + 1;
|
||||||
}
|
}
|
||||||
return result.toOwnedSlice();
|
return result.toOwnedSlice(allocator);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -69,20 +69,22 @@ pub fn create(ctx_type: type, allocator: std.mem.Allocator, parent: Plane, opts:
|
||||||
const self = try allocator.create(Self);
|
const self = try allocator.create(Self);
|
||||||
errdefer allocator.destroy(self);
|
errdefer allocator.destroy(self);
|
||||||
self.* = .{
|
self.* = .{
|
||||||
|
.allocator = allocator,
|
||||||
.parent = parent,
|
.parent = parent,
|
||||||
.plane = n,
|
.plane = n,
|
||||||
.opts = opts,
|
.opts = opts,
|
||||||
.label = std.ArrayList(u8).init(allocator),
|
.label = .empty,
|
||||||
.text = std.ArrayList(u8).init(allocator),
|
.text = .empty,
|
||||||
.icon_width = @intCast(if (tui.config().show_fileicons) if (opts.icon) |icon| n.egc_chunk_width(icon, 0, 1) else 0 else 0),
|
.icon_width = @intCast(if (tui.config().show_fileicons) if (opts.icon) |icon| n.egc_chunk_width(icon, 0, 1) else 0 else 0),
|
||||||
};
|
};
|
||||||
try self.label.appendSlice(self.opts.label);
|
try self.label.appendSlice(self.allocator, self.opts.label);
|
||||||
self.opts.label = self.label.items;
|
self.opts.label = self.label.items;
|
||||||
return Widget.to(self);
|
return Widget.to(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn State(ctx_type: type) type {
|
pub fn State(ctx_type: type) type {
|
||||||
return struct {
|
return struct {
|
||||||
|
allocator: std.mem.Allocator,
|
||||||
parent: Plane,
|
parent: Plane,
|
||||||
plane: Plane,
|
plane: Plane,
|
||||||
active: bool = false,
|
active: bool = false,
|
||||||
|
|
@ -97,8 +99,8 @@ pub fn State(ctx_type: type) type {
|
||||||
pub const Context = ctx_type;
|
pub const Context = ctx_type;
|
||||||
|
|
||||||
pub fn deinit(self: *Self, allocator: std.mem.Allocator) void {
|
pub fn deinit(self: *Self, allocator: std.mem.Allocator) void {
|
||||||
self.text.deinit();
|
self.text.deinit(self.allocator);
|
||||||
self.label.deinit();
|
self.label.deinit(self.allocator);
|
||||||
self.plane.deinit();
|
self.plane.deinit();
|
||||||
allocator.destroy(self);
|
allocator.destroy(self);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -105,18 +105,18 @@ pub const List = struct {
|
||||||
pub fn init(allocator: Allocator) List {
|
pub fn init(allocator: Allocator) List {
|
||||||
return .{
|
return .{
|
||||||
.allocator = allocator,
|
.allocator = allocator,
|
||||||
.list = ArrayList(MessageFilter).init(allocator),
|
.list = .empty,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deinit(self: *List) void {
|
pub fn deinit(self: *List) void {
|
||||||
for (self.list.items) |*i|
|
for (self.list.items) |*i|
|
||||||
i.deinit();
|
i.deinit();
|
||||||
self.list.deinit();
|
self.list.deinit(self.allocator);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add(self: *List, h: MessageFilter) error{OutOfMemory}!void {
|
pub fn add(self: *List, h: MessageFilter) error{OutOfMemory}!void {
|
||||||
(try self.list.addOne()).* = h;
|
(try self.list.addOne(self.allocator)).* = h;
|
||||||
// @import("log").print("MessageFilter", "add: {d} {s}", .{ self.list.items.len, self.list.items[self.list.items.len - 1].vtable.type_name });
|
// @import("log").print("MessageFilter", "add: {d} {s}", .{ self.list.items.len, self.list.items[self.list.items.len - 1].vtable.type_name });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@ fn init(allocator: Allocator, parent: Plane, name: [:0]const u8, dir: Direction,
|
||||||
.plane = undefined,
|
.plane = undefined,
|
||||||
.parent = parent,
|
.parent = parent,
|
||||||
.allocator = allocator,
|
.allocator = allocator,
|
||||||
.widgets = ArrayList(WidgetState).init(allocator),
|
.widgets = .empty,
|
||||||
.layout_ = layout_,
|
.layout_ = layout_,
|
||||||
.direction = dir,
|
.direction = dir,
|
||||||
.widget_type = widget_type,
|
.widget_type = widget_type,
|
||||||
|
|
@ -96,7 +96,7 @@ pub fn layout(self: *Self) Widget.Layout {
|
||||||
pub fn deinit(self: *Self, allocator: std.mem.Allocator) void {
|
pub fn deinit(self: *Self, allocator: std.mem.Allocator) void {
|
||||||
for (self.widgets.items) |*w|
|
for (self.widgets.items) |*w|
|
||||||
w.widget.deinit(self.allocator);
|
w.widget.deinit(self.allocator);
|
||||||
self.widgets.deinit();
|
self.widgets.deinit(self.allocator);
|
||||||
self.plane.deinit();
|
self.plane.deinit();
|
||||||
allocator.destroy(self);
|
allocator.destroy(self);
|
||||||
}
|
}
|
||||||
|
|
@ -106,7 +106,7 @@ pub fn add(self: *Self, w_: Widget) !void {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn addP(self: *Self, w_: Widget) !*Widget {
|
pub fn addP(self: *Self, w_: Widget) !*Widget {
|
||||||
var w: *WidgetState = try self.widgets.addOne();
|
var w: *WidgetState = try self.widgets.addOne(self.allocator);
|
||||||
w.* = .{
|
w.* = .{
|
||||||
.widget = w_,
|
.widget = w_,
|
||||||
.layout = w_.layout(),
|
.layout = w_.layout(),
|
||||||
|
|
|
||||||
|
|
@ -14,18 +14,18 @@ widgets: ArrayList(Widget),
|
||||||
pub fn init(allocator: Allocator) Self {
|
pub fn init(allocator: Allocator) Self {
|
||||||
return .{
|
return .{
|
||||||
.allocator = allocator,
|
.allocator = allocator,
|
||||||
.widgets = ArrayList(Widget).init(allocator),
|
.widgets = .empty,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deinit(self: *Self) void {
|
pub fn deinit(self: *Self) void {
|
||||||
for (self.widgets.items) |*widget|
|
for (self.widgets.items) |*widget|
|
||||||
widget.deinit(self.allocator);
|
widget.deinit(self.allocator);
|
||||||
self.widgets.deinit();
|
self.widgets.deinit(self.allocator);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add(self: *Self, widget: Widget) !void {
|
pub fn add(self: *Self, widget: Widget) !void {
|
||||||
(try self.widgets.addOne()).* = widget;
|
(try self.widgets.addOne(self.allocator)).* = widget;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn swap(self: *Self, n: usize, widget: Widget) Widget {
|
pub fn swap(self: *Self, n: usize, widget: Widget) Widget {
|
||||||
|
|
|
||||||
|
|
@ -204,7 +204,7 @@ pub const CurSel = struct {
|
||||||
return parent;
|
return parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write(self: *const Self, writer: Buffer.MetaWriter) !void {
|
fn write(self: *const Self, writer: *std.Io.Writer) !void {
|
||||||
try cbor.writeArrayHeader(writer, 2);
|
try cbor.writeArrayHeader(writer, 2);
|
||||||
try self.cursor.write(writer);
|
try self.cursor.write(writer);
|
||||||
if (self.selection) |sel| {
|
if (self.selection) |sel| {
|
||||||
|
|
@ -395,14 +395,14 @@ pub const Editor = struct {
|
||||||
const Result = command.Result;
|
const Result = command.Result;
|
||||||
|
|
||||||
pub fn update_meta(self: *const Self) void {
|
pub fn update_meta(self: *const Self) void {
|
||||||
var meta = std.ArrayListUnmanaged(u8).empty;
|
var meta: std.Io.Writer.Allocating = .init(self.allocator);
|
||||||
defer meta.deinit(self.allocator);
|
defer meta.deinit();
|
||||||
if (self.buffer) |_| self.write_state(meta.writer(self.allocator)) catch {};
|
if (self.buffer) |_| self.write_state(&meta.writer) catch {};
|
||||||
if (self.buffer) |_| self.write_state(meta.writer(self.allocator)) catch {};
|
if (self.buffer) |_| self.write_state(&meta.writer) catch {};
|
||||||
if (self.buffer) |p| p.set_meta(meta.items) catch {};
|
if (self.buffer) |p| p.set_meta(meta.written()) catch {};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write_state(self: *const Self, writer: Buffer.MetaWriter) !void {
|
pub fn write_state(self: *const Self, writer: *std.Io.Writer) !void {
|
||||||
try cbor.writeArrayHeader(writer, 11);
|
try cbor.writeArrayHeader(writer, 11);
|
||||||
try cbor.writeValue(writer, self.file_path orelse "");
|
try cbor.writeValue(writer, self.file_path orelse "");
|
||||||
try cbor.writeValue(writer, self.last_find_query orelse "");
|
try cbor.writeValue(writer, self.last_find_query orelse "");
|
||||||
|
|
@ -514,9 +514,9 @@ pub const Editor = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn deinit(self: *Self) void {
|
fn deinit(self: *Self) void {
|
||||||
var meta = std.ArrayListUnmanaged(u8).empty;
|
var meta: std.Io.Writer.Allocating = .init(self.allocator);
|
||||||
defer meta.deinit(self.allocator);
|
defer meta.deinit();
|
||||||
if (self.buffer) |_| self.write_state(meta.writer(self.allocator)) catch {};
|
if (self.buffer) |_| self.write_state(&meta.writer) catch {};
|
||||||
for (self.diagnostics.items) |*d| d.deinit(self.allocator);
|
for (self.diagnostics.items) |*d| d.deinit(self.allocator);
|
||||||
self.diagnostics.deinit(self.allocator);
|
self.diagnostics.deinit(self.allocator);
|
||||||
self.completions.deinit(self.allocator);
|
self.completions.deinit(self.allocator);
|
||||||
|
|
@ -525,7 +525,7 @@ pub const Editor = struct {
|
||||||
self.matches.deinit(self.allocator);
|
self.matches.deinit(self.allocator);
|
||||||
self.handlers.deinit();
|
self.handlers.deinit();
|
||||||
self.logger.deinit();
|
self.logger.deinit();
|
||||||
if (self.buffer) |p| self.buffer_manager.retire(p, meta.items);
|
if (self.buffer) |p| self.buffer_manager.retire(p, meta.written());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_whitespace_mode(whitespace_mode: []const u8) WhitespaceMode {
|
fn from_whitespace_mode(whitespace_mode: []const u8) WhitespaceMode {
|
||||||
|
|
@ -623,15 +623,15 @@ pub const Editor = struct {
|
||||||
self.syntax_no_render = true;
|
self.syntax_no_render = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
var content = std.ArrayListUnmanaged(u8).empty;
|
var content: std.Io.Writer.Allocating = .init(std.heap.c_allocator);
|
||||||
defer content.deinit(std.heap.c_allocator);
|
defer content.deinit();
|
||||||
{
|
{
|
||||||
const frame_ = tracy.initZone(@src(), .{ .name = "store" });
|
const frame_ = tracy.initZone(@src(), .{ .name = "store" });
|
||||||
defer frame_.deinit();
|
defer frame_.deinit();
|
||||||
try new_buf.root.store(content.writer(std.heap.c_allocator), new_buf.file_eol_mode);
|
try new_buf.root.store(&content.writer, new_buf.file_eol_mode);
|
||||||
}
|
}
|
||||||
if (self.indent_mode == .auto)
|
if (self.indent_mode == .auto)
|
||||||
self.detect_indent_mode(content.items);
|
self.detect_indent_mode(content.written());
|
||||||
|
|
||||||
self.syntax = syntax: {
|
self.syntax = syntax: {
|
||||||
const lang_override = file_type orelse tp.env.get().str("language");
|
const lang_override = file_type orelse tp.env.get().str("language");
|
||||||
|
|
@ -642,7 +642,7 @@ pub const Editor = struct {
|
||||||
break :blk if (lang_override.len > 0)
|
break :blk if (lang_override.len > 0)
|
||||||
try file_type_config.get(lang_override)
|
try file_type_config.get(lang_override)
|
||||||
else
|
else
|
||||||
file_type_config.guess_file_type(self.file_path, content.items);
|
file_type_config.guess_file_type(self.file_path, content.written());
|
||||||
};
|
};
|
||||||
|
|
||||||
self.maybe_enable_auto_save();
|
self.maybe_enable_auto_save();
|
||||||
|
|
@ -663,7 +663,7 @@ pub const Editor = struct {
|
||||||
file_path,
|
file_path,
|
||||||
ft,
|
ft,
|
||||||
new_buf.lsp_version,
|
new_buf.lsp_version,
|
||||||
try content.toOwnedSlice(std.heap.c_allocator),
|
try content.toOwnedSlice(),
|
||||||
new_buf.is_ephemeral(),
|
new_buf.is_ephemeral(),
|
||||||
) catch |e|
|
) catch |e|
|
||||||
self.logger.print("project_manager.did_open failed: {any}", .{e});
|
self.logger.print("project_manager.did_open failed: {any}", .{e});
|
||||||
|
|
@ -740,10 +740,10 @@ pub const Editor = struct {
|
||||||
pub const set_editor_tab_width_meta: Meta = .{ .arguments = &.{.integer} };
|
pub const set_editor_tab_width_meta: Meta = .{ .arguments = &.{.integer} };
|
||||||
|
|
||||||
fn close(self: *Self) !void {
|
fn close(self: *Self) !void {
|
||||||
var meta = std.ArrayListUnmanaged(u8).empty;
|
var meta: std.Io.Writer.Allocating = .init(self.allocator);
|
||||||
defer meta.deinit(self.allocator);
|
defer meta.deinit();
|
||||||
self.write_state(meta.writer(self.allocator)) catch {};
|
self.write_state(&meta.writer) catch {};
|
||||||
if (self.buffer) |b_mut| self.buffer_manager.retire(b_mut, meta.items);
|
if (self.buffer) |b_mut| self.buffer_manager.retire(b_mut, meta.written());
|
||||||
self.cancel_all_selections();
|
self.cancel_all_selections();
|
||||||
self.buffer = null;
|
self.buffer = null;
|
||||||
self.plane.erase();
|
self.plane.erase();
|
||||||
|
|
@ -797,19 +797,19 @@ pub const Editor = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn store_undo_meta(self: *Self, allocator: Allocator) ![]u8 {
|
fn store_undo_meta(self: *Self, allocator: Allocator) ![]u8 {
|
||||||
var meta = std.ArrayListUnmanaged(u8).empty;
|
var meta: std.Io.Writer.Allocating = .init(allocator);
|
||||||
const writer = meta.writer(allocator);
|
defer meta.deinit();
|
||||||
for (self.cursels_saved.items) |*cursel_| if (cursel_.*) |*cursel|
|
for (self.cursels_saved.items) |*cursel_| if (cursel_.*) |*cursel|
|
||||||
try cursel.write(writer);
|
try cursel.write(&meta.writer);
|
||||||
return meta.toOwnedSlice(allocator);
|
return meta.toOwnedSlice();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn store_current_undo_meta(self: *Self, allocator: Allocator) ![]u8 {
|
fn store_current_undo_meta(self: *Self, allocator: Allocator) ![]u8 {
|
||||||
var meta = std.ArrayListUnmanaged(u8).empty;
|
var meta: std.Io.Writer.Allocating = .init(allocator);
|
||||||
const writer = meta.writer(allocator);
|
defer meta.deinit();
|
||||||
for (self.cursels.items) |*cursel_| if (cursel_.*) |*cursel|
|
for (self.cursels.items) |*cursel_| if (cursel_.*) |*cursel|
|
||||||
try cursel.write(writer);
|
try cursel.write(&meta.writer);
|
||||||
return meta.toOwnedSlice(allocator);
|
return meta.toOwnedSlice();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_buf(self: *Self, root: Buffer.Root) !void {
|
pub fn update_buf(self: *Self, root: Buffer.Root) !void {
|
||||||
|
|
@ -951,15 +951,13 @@ pub const Editor = struct {
|
||||||
self: *const Self,
|
self: *const Self,
|
||||||
root: Buffer.Root,
|
root: Buffer.Root,
|
||||||
sel: Selection,
|
sel: Selection,
|
||||||
writer: anytype,
|
writer: *std.Io.Writer,
|
||||||
map_error: fn (e: anyerror, stack_trace: ?*std.builtin.StackTrace) @TypeOf(writer).Error,
|
|
||||||
wcwidth_: ?*usize,
|
wcwidth_: ?*usize,
|
||||||
) @TypeOf(writer).Error!void {
|
) std.Io.Writer.Error!void {
|
||||||
const Writer = @TypeOf(writer);
|
|
||||||
const Ctx = struct {
|
const Ctx = struct {
|
||||||
col: usize = 0,
|
col: usize = 0,
|
||||||
sel: Selection,
|
sel: Selection,
|
||||||
writer: Writer,
|
writer: *std.Io.Writer,
|
||||||
wcwidth: usize = 0,
|
wcwidth: usize = 0,
|
||||||
fn walker(ctx_: *anyopaque, egc: []const u8, wcwidth: usize, _: Buffer.Metrics) Buffer.Walker {
|
fn walker(ctx_: *anyopaque, egc: []const u8, wcwidth: usize, _: Buffer.Metrics) Buffer.Walker {
|
||||||
const ctx = @as(*@This(), @ptrCast(@alignCast(ctx_)));
|
const ctx = @as(*@This(), @ptrCast(@alignCast(ctx_)));
|
||||||
|
|
@ -988,7 +986,7 @@ pub const Editor = struct {
|
||||||
ctx.sel.normalize();
|
ctx.sel.normalize();
|
||||||
if (sel.begin.eql(sel.end))
|
if (sel.begin.eql(sel.end))
|
||||||
return;
|
return;
|
||||||
root.walk_egc_forward(sel.begin.row, Ctx.walker, &ctx, self.metrics) catch |e| return map_error(e, @errorReturnTrace());
|
root.walk_egc_forward(sel.begin.row, Ctx.walker, &ctx, self.metrics) catch return error.WriteFailed;
|
||||||
if (wcwidth_) |p| p.* = ctx.wcwidth;
|
if (wcwidth_) |p| p.* = ctx.wcwidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1808,9 +1806,9 @@ pub const Editor = struct {
|
||||||
|
|
||||||
fn text_from_root(root_: ?Buffer.Root, eol_mode: Buffer.EolMode) ![]const u8 {
|
fn text_from_root(root_: ?Buffer.Root, eol_mode: Buffer.EolMode) ![]const u8 {
|
||||||
const root = root_ orelse return &.{};
|
const root = root_ orelse return &.{};
|
||||||
var text = std.ArrayList(u8).init(std.heap.c_allocator);
|
var text: std.Io.Writer.Allocating = .init(std.heap.c_allocator);
|
||||||
defer text.deinit();
|
defer text.deinit();
|
||||||
try root.store(text.writer(), eol_mode);
|
try root.store(&text.writer, eol_mode);
|
||||||
return text.toOwnedSlice();
|
return text.toOwnedSlice();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2665,9 +2663,9 @@ pub const Editor = struct {
|
||||||
old_selection.normalize();
|
old_selection.normalize();
|
||||||
const cut_text = try copy_selection(root, sel, self.allocator, self.metrics);
|
const cut_text = try copy_selection(root, sel, self.allocator, self.metrics);
|
||||||
if (cut_text.len > 100) {
|
if (cut_text.len > 100) {
|
||||||
self.logger.print("cut:{s}...", .{std.fmt.fmtSliceEscapeLower(cut_text[0..100])});
|
self.logger.print("cut:{f}...", .{std.ascii.hexEscape(cut_text[0..100], .lower)});
|
||||||
} else {
|
} else {
|
||||||
self.logger.print("cut:{s}", .{std.fmt.fmtSliceEscapeLower(cut_text)});
|
self.logger.print("cut:{f}", .{std.ascii.hexEscape(cut_text, .lower)});
|
||||||
}
|
}
|
||||||
break :ret .{ cut_text, try self.delete_selection(root, cursel, try self.buf_a()) };
|
break :ret .{ cut_text, try self.delete_selection(root, cursel, try self.buf_a()) };
|
||||||
} else error.Stop;
|
} else error.Stop;
|
||||||
|
|
@ -2826,9 +2824,9 @@ pub const Editor = struct {
|
||||||
};
|
};
|
||||||
if (text.items.len > 0) {
|
if (text.items.len > 0) {
|
||||||
if (text.items.len > 100) {
|
if (text.items.len > 100) {
|
||||||
self.logger.print("copy:{s}...", .{std.fmt.fmtSliceEscapeLower(text.items[0..100])});
|
self.logger.print("copy:{f}...", .{std.ascii.hexEscape(text.items[0..100], .lower)});
|
||||||
} else {
|
} else {
|
||||||
self.logger.print("copy:{s}", .{std.fmt.fmtSliceEscapeLower(text.items)});
|
self.logger.print("copy:{f}", .{std.ascii.hexEscape(text.items, .lower)});
|
||||||
}
|
}
|
||||||
self.set_clipboard(try text.toOwnedSlice(self.allocator));
|
self.set_clipboard(try text.toOwnedSlice(self.allocator));
|
||||||
}
|
}
|
||||||
|
|
@ -2837,7 +2835,7 @@ pub const Editor = struct {
|
||||||
|
|
||||||
fn copy_cursel_file_name(
|
fn copy_cursel_file_name(
|
||||||
self: *const Self,
|
self: *const Self,
|
||||||
writer: anytype,
|
writer: *std.Io.Writer,
|
||||||
) Result {
|
) Result {
|
||||||
if (self.file_path) |file_path|
|
if (self.file_path) |file_path|
|
||||||
try writer.writeAll(file_path)
|
try writer.writeAll(file_path)
|
||||||
|
|
@ -2848,7 +2846,7 @@ pub const Editor = struct {
|
||||||
fn copy_cursel_file_name_and_location(
|
fn copy_cursel_file_name_and_location(
|
||||||
self: *const Self,
|
self: *const Self,
|
||||||
cursel: *const CurSel,
|
cursel: *const CurSel,
|
||||||
writer: anytype,
|
writer: *std.Io.Writer,
|
||||||
) Result {
|
) Result {
|
||||||
try self.copy_cursel_file_name(writer);
|
try self.copy_cursel_file_name(writer);
|
||||||
if (cursel.selection) |sel_| {
|
if (cursel.selection) |sel_| {
|
||||||
|
|
@ -2876,8 +2874,9 @@ pub const Editor = struct {
|
||||||
pub fn copy_file_name(self: *Self, ctx: Context) Result {
|
pub fn copy_file_name(self: *Self, ctx: Context) Result {
|
||||||
var mode: enum { all, primary_only, file_name_only } = .all;
|
var mode: enum { all, primary_only, file_name_only } = .all;
|
||||||
_ = ctx.args.match(.{tp.extract(&mode)}) catch false;
|
_ = ctx.args.match(.{tp.extract(&mode)}) catch false;
|
||||||
var text: std.ArrayListUnmanaged(u8) = .empty;
|
var buffer: std.Io.Writer.Allocating = .init(self.allocator);
|
||||||
const writer = text.writer(self.allocator);
|
defer buffer.deinit();
|
||||||
|
const writer = &buffer.writer;
|
||||||
var first = true;
|
var first = true;
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
.file_name_only => try self.copy_cursel_file_name(writer),
|
.file_name_only => try self.copy_cursel_file_name(writer),
|
||||||
|
|
@ -2890,16 +2889,13 @@ pub const Editor = struct {
|
||||||
try self.copy_cursel_file_name_and_location(cursel, writer);
|
try self.copy_cursel_file_name_and_location(cursel, writer);
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
if (text.items.len > 0) {
|
const text = try buffer.toOwnedSlice();
|
||||||
if (text.items.len > 100)
|
if (text.len > 0) {
|
||||||
self.logger.print("copy:{s}...", .{
|
if (text.len > 100)
|
||||||
std.fmt.fmtSliceEscapeLower(text.items[0..100]),
|
self.logger.print("copy:{f}...", .{std.ascii.hexEscape(text[0..100], .lower)})
|
||||||
})
|
|
||||||
else
|
else
|
||||||
self.logger.print("copy:{s}", .{
|
self.logger.print("copy:{f}", .{std.ascii.hexEscape(text, .lower)});
|
||||||
std.fmt.fmtSliceEscapeLower(text.items),
|
self.set_clipboard(text);
|
||||||
});
|
|
||||||
self.set_clipboard(try text.toOwnedSlice(self.allocator));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub const copy_file_name_meta: Meta = .{
|
pub const copy_file_name_meta: Meta = .{
|
||||||
|
|
@ -2924,9 +2920,9 @@ pub const Editor = struct {
|
||||||
};
|
};
|
||||||
if (text.items.len > 0) {
|
if (text.items.len > 0) {
|
||||||
if (text.items.len > 100) {
|
if (text.items.len > 100) {
|
||||||
self.logger.print("copy:{s}...", .{std.fmt.fmtSliceEscapeLower(text.items[0..100])});
|
self.logger.print("copy:{f}...", .{std.ascii.hexEscape(text.items[0..100], .lower)});
|
||||||
} else {
|
} else {
|
||||||
self.logger.print("copy:{s}", .{std.fmt.fmtSliceEscapeLower(text.items)});
|
self.logger.print("copy:{f}", .{std.ascii.hexEscape(text.items, .lower)});
|
||||||
}
|
}
|
||||||
self.set_clipboard_internal(try text.toOwnedSlice(self.allocator));
|
self.set_clipboard_internal(try text.toOwnedSlice(self.allocator));
|
||||||
}
|
}
|
||||||
|
|
@ -2959,9 +2955,9 @@ pub const Editor = struct {
|
||||||
};
|
};
|
||||||
if (text.items.len > 0) {
|
if (text.items.len > 0) {
|
||||||
if (text.items.len > 100) {
|
if (text.items.len > 100) {
|
||||||
self.logger.print("copy:{s}...", .{std.fmt.fmtSliceEscapeLower(text.items[0..100])});
|
self.logger.print("copy:{f}...", .{std.ascii.hexEscape(text.items[0..100], .lower)});
|
||||||
} else {
|
} else {
|
||||||
self.logger.print("copy:{s}", .{std.fmt.fmtSliceEscapeLower(text.items)});
|
self.logger.print("copy:{f}", .{std.ascii.hexEscape(text.items, .lower)});
|
||||||
}
|
}
|
||||||
self.set_clipboard_internal(try text.toOwnedSlice(self.allocator));
|
self.set_clipboard_internal(try text.toOwnedSlice(self.allocator));
|
||||||
}
|
}
|
||||||
|
|
@ -4485,20 +4481,20 @@ pub const Editor = struct {
|
||||||
}
|
}
|
||||||
pub const insert_line_meta: Meta = .{ .description = "Insert line" };
|
pub const insert_line_meta: Meta = .{ .description = "Insert line" };
|
||||||
|
|
||||||
fn generate_leading_ws(self: *Self, writer: anytype, leading_ws: usize) !void {
|
fn generate_leading_ws(self: *Self, writer: *std.Io.Writer, leading_ws: usize) !void {
|
||||||
return switch (self.indent_mode) {
|
return switch (self.indent_mode) {
|
||||||
.spaces, .auto => generate_leading_spaces(writer, leading_ws),
|
.spaces, .auto => generate_leading_spaces(writer, leading_ws),
|
||||||
.tabs => generate_leading_tabs(writer, leading_ws, self.tab_width),
|
.tabs => generate_leading_tabs(writer, leading_ws, self.tab_width),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn generate_leading_spaces(writer: anytype, leading_ws: usize) !void {
|
fn generate_leading_spaces(writer: *std.Io.Writer, leading_ws: usize) !void {
|
||||||
var width = leading_ws;
|
var width = leading_ws;
|
||||||
while (width > 0) : (width -= 1)
|
while (width > 0) : (width -= 1)
|
||||||
try writer.writeByte(' ');
|
try writer.writeByte(' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
fn generate_leading_tabs(writer: anytype, leading_ws: usize, tab_width: usize) !void {
|
fn generate_leading_tabs(writer: *std.Io.Writer, leading_ws: usize, tab_width: usize) !void {
|
||||||
var width = leading_ws;
|
var width = leading_ws;
|
||||||
while (width > 0) if (width >= tab_width) {
|
while (width > 0) if (width >= tab_width) {
|
||||||
width -= tab_width;
|
width -= tab_width;
|
||||||
|
|
@ -4516,12 +4512,12 @@ pub const Editor = struct {
|
||||||
const leading_ws = @min(find_first_non_ws(root, row, self.metrics), cursel.cursor.col);
|
const leading_ws = @min(find_first_non_ws(root, row, self.metrics), cursel.cursor.col);
|
||||||
var sfa = std.heap.stackFallback(512, self.allocator);
|
var sfa = std.heap.stackFallback(512, self.allocator);
|
||||||
const allocator = sfa.get();
|
const allocator = sfa.get();
|
||||||
var stream = std.ArrayListUnmanaged(u8).empty;
|
var stream: std.Io.Writer.Allocating = .init(allocator);
|
||||||
defer stream.deinit(allocator);
|
defer stream.deinit();
|
||||||
var writer = stream.writer(allocator);
|
const writer = &stream.writer;
|
||||||
_ = try writer.write("\n");
|
_ = try writer.write("\n");
|
||||||
try self.generate_leading_ws(&writer, leading_ws);
|
try self.generate_leading_ws(writer, leading_ws);
|
||||||
var root_ = try self.insert(root, cursel, stream.items, b_allocator);
|
var root_ = try self.insert(root, cursel, stream.written(), b_allocator);
|
||||||
if (mode == .collapse_ws)
|
if (mode == .collapse_ws)
|
||||||
root_ = self.collapse_trailing_ws_line(root_, row, b_allocator);
|
root_ = self.collapse_trailing_ws_line(root_, row, b_allocator);
|
||||||
const leading_ws_ = find_first_non_ws(root_, cursel.cursor.row, self.metrics);
|
const leading_ws_ = find_first_non_ws(root_, cursel.cursor.row, self.metrics);
|
||||||
|
|
@ -4593,12 +4589,11 @@ pub const Editor = struct {
|
||||||
try move_cursor_left(root, &cursel.cursor, self.metrics);
|
try move_cursor_left(root, &cursel.cursor, self.metrics);
|
||||||
var sfa = std.heap.stackFallback(512, self.allocator);
|
var sfa = std.heap.stackFallback(512, self.allocator);
|
||||||
const allocator = sfa.get();
|
const allocator = sfa.get();
|
||||||
var stream = std.ArrayListUnmanaged(u8).empty;
|
var stream: std.Io.Writer.Allocating = .init(allocator);
|
||||||
defer stream.deinit(allocator);
|
defer stream.deinit();
|
||||||
var writer = stream.writer(self.allocator);
|
try self.generate_leading_ws(&stream.writer, leading_ws);
|
||||||
try self.generate_leading_ws(&writer, leading_ws);
|
if (stream.written().len > 0)
|
||||||
if (stream.items.len > 0)
|
root = try self.insert(root, cursel, stream.written(), b.allocator);
|
||||||
root = try self.insert(root, cursel, stream.items, b.allocator);
|
|
||||||
root = self.collapse_trailing_ws_line(root, row, b.allocator);
|
root = self.collapse_trailing_ws_line(root, row, b.allocator);
|
||||||
};
|
};
|
||||||
try self.update_buf(root);
|
try self.update_buf(root);
|
||||||
|
|
@ -4627,13 +4622,12 @@ pub const Editor = struct {
|
||||||
try move_cursor_end(root, &cursel.cursor, self.metrics);
|
try move_cursor_end(root, &cursel.cursor, self.metrics);
|
||||||
var sfa = std.heap.stackFallback(512, self.allocator);
|
var sfa = std.heap.stackFallback(512, self.allocator);
|
||||||
const allocator = sfa.get();
|
const allocator = sfa.get();
|
||||||
var stream = std.ArrayListUnmanaged(u8).empty;
|
var stream: std.Io.Writer.Allocating = .init(allocator);
|
||||||
defer stream.deinit(allocator);
|
defer stream.deinit();
|
||||||
var writer = stream.writer(allocator);
|
try stream.writer.writeAll("\n");
|
||||||
_ = try writer.write("\n");
|
try self.generate_leading_ws(&stream.writer, leading_ws);
|
||||||
try self.generate_leading_ws(&writer, leading_ws);
|
if (stream.written().len > 0)
|
||||||
if (stream.items.len > 0)
|
root = try self.insert(root, cursel, stream.written(), b.allocator);
|
||||||
root = try self.insert(root, cursel, stream.items, b.allocator);
|
|
||||||
root = self.collapse_trailing_ws_line(root, row, b.allocator);
|
root = self.collapse_trailing_ws_line(root, row, b.allocator);
|
||||||
};
|
};
|
||||||
try self.update_buf(root);
|
try self.update_buf(root);
|
||||||
|
|
@ -4777,14 +4771,14 @@ pub const Editor = struct {
|
||||||
self.syntax_refresh_full = true;
|
self.syntax_refresh_full = true;
|
||||||
if (self.syntax_last_rendered_root == null)
|
if (self.syntax_last_rendered_root == null)
|
||||||
self.syntax_refresh_full = true;
|
self.syntax_refresh_full = true;
|
||||||
var content_ = std.ArrayListUnmanaged(u8).empty;
|
var content_: std.Io.Writer.Allocating = .init(self.allocator);
|
||||||
defer content_.deinit(self.allocator);
|
defer content_.deinit();
|
||||||
{
|
{
|
||||||
const frame = tracy.initZone(@src(), .{ .name = "editor store syntax" });
|
const frame = tracy.initZone(@src(), .{ .name = "editor store syntax" });
|
||||||
defer frame.deinit();
|
defer frame.deinit();
|
||||||
try root.store(content_.writer(self.allocator), eol_mode);
|
try root.store(&content_.writer, eol_mode);
|
||||||
}
|
}
|
||||||
const content = try content_.toOwnedSliceSentinel(self.allocator, 0);
|
const content = try content_.toOwnedSliceSentinel(0);
|
||||||
defer self.allocator.free(content);
|
defer self.allocator.free(content);
|
||||||
if (self.syntax_refresh_full) {
|
if (self.syntax_refresh_full) {
|
||||||
{
|
{
|
||||||
|
|
@ -4803,18 +4797,18 @@ pub const Editor = struct {
|
||||||
} else {
|
} else {
|
||||||
if (self.syntax_last_rendered_root) |root_src| {
|
if (self.syntax_last_rendered_root) |root_src| {
|
||||||
self.syntax_last_rendered_root = null;
|
self.syntax_last_rendered_root = null;
|
||||||
var old_content = std.ArrayListUnmanaged(u8).empty;
|
var old_content: std.Io.Writer.Allocating = .init(self.allocator);
|
||||||
defer old_content.deinit(self.allocator);
|
defer old_content.deinit();
|
||||||
{
|
{
|
||||||
const frame = tracy.initZone(@src(), .{ .name = "editor store syntax" });
|
const frame = tracy.initZone(@src(), .{ .name = "editor store syntax" });
|
||||||
defer frame.deinit();
|
defer frame.deinit();
|
||||||
try root_src.store(old_content.writer(self.allocator), eol_mode);
|
try root_src.store(&old_content.writer, eol_mode);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
const frame = tracy.initZone(@src(), .{ .name = "editor diff syntax" });
|
const frame = tracy.initZone(@src(), .{ .name = "editor diff syntax" });
|
||||||
defer frame.deinit();
|
defer frame.deinit();
|
||||||
const diff = @import("diff");
|
const diff = @import("diff");
|
||||||
const edits = try diff.diff(self.allocator, content, old_content.items);
|
const edits = try diff.diff(self.allocator, content, old_content.written());
|
||||||
defer self.allocator.free(edits);
|
defer self.allocator.free(edits);
|
||||||
for (edits) |edit|
|
for (edits) |edit|
|
||||||
syntax_process_edit(syn, edit);
|
syntax_process_edit(syn, edit);
|
||||||
|
|
@ -4835,10 +4829,10 @@ pub const Editor = struct {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var content = std.ArrayListUnmanaged(u8).empty;
|
var content: std.Io.Writer.Allocating = .init(self.allocator);
|
||||||
defer content.deinit(self.allocator);
|
defer content.deinit();
|
||||||
try root.store(content.writer(self.allocator), eol_mode);
|
try root.store(&content.writer, eol_mode);
|
||||||
self.syntax = file_type_config.create_syntax_guess_file_type(self.allocator, content.items, self.file_path, tui.query_cache()) catch |e| switch (e) {
|
self.syntax = file_type_config.create_syntax_guess_file_type(self.allocator, content.written(), self.file_path, tui.query_cache()) catch |e| switch (e) {
|
||||||
error.NotFound => null,
|
error.NotFound => null,
|
||||||
else => return e,
|
else => return e,
|
||||||
};
|
};
|
||||||
|
|
@ -4846,7 +4840,7 @@ pub const Editor = struct {
|
||||||
if (self.syntax) |syn| {
|
if (self.syntax) |syn| {
|
||||||
const frame = tracy.initZone(@src(), .{ .name = "editor parse syntax" });
|
const frame = tracy.initZone(@src(), .{ .name = "editor parse syntax" });
|
||||||
defer frame.deinit();
|
defer frame.deinit();
|
||||||
try syn.refresh_full(content.items);
|
try syn.refresh_full(content.written());
|
||||||
self.syntax_last_rendered_root = root;
|
self.syntax_last_rendered_root = root;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -4891,7 +4885,7 @@ pub const Editor = struct {
|
||||||
const tree = root.debug_render_chunks(self.allocator, primary.cursor.row, self.metrics) catch |e|
|
const tree = root.debug_render_chunks(self.allocator, primary.cursor.row, self.metrics) catch |e|
|
||||||
return self.logger.print("line {d}: {any}", .{ primary.cursor.row, e });
|
return self.logger.print("line {d}: {any}", .{ primary.cursor.row, e });
|
||||||
defer self.allocator.free(tree);
|
defer self.allocator.free(tree);
|
||||||
self.logger.print("line {d}:{s}", .{ primary.cursor.row, std.fmt.fmtSliceEscapeLower(tree) });
|
self.logger.print("line {d}:{f}", .{ primary.cursor.row, std.ascii.hexEscape(tree, .lower) });
|
||||||
}
|
}
|
||||||
pub const dump_current_line_meta: Meta = .{ .description = "Debug: dump current line" };
|
pub const dump_current_line_meta: Meta = .{ .description = "Debug: dump current line" };
|
||||||
|
|
||||||
|
|
@ -4901,7 +4895,7 @@ pub const Editor = struct {
|
||||||
const tree = root.debug_line_render_tree(self.allocator, primary.cursor.row) catch |e|
|
const tree = root.debug_line_render_tree(self.allocator, primary.cursor.row) catch |e|
|
||||||
return self.logger.print("line {d} ast: {any}", .{ primary.cursor.row, e });
|
return self.logger.print("line {d} ast: {any}", .{ primary.cursor.row, e });
|
||||||
defer self.allocator.free(tree);
|
defer self.allocator.free(tree);
|
||||||
self.logger.print("line {d} ast:{s}", .{ primary.cursor.row, std.fmt.fmtSliceEscapeLower(tree) });
|
self.logger.print("line {d} ast:{f}", .{ primary.cursor.row, std.ascii.hexEscape(tree, .lower) });
|
||||||
}
|
}
|
||||||
pub const dump_current_line_tree_meta: Meta = .{ .description = "Debug: dump current line (tree)" };
|
pub const dump_current_line_tree_meta: Meta = .{ .description = "Debug: dump current line (tree)" };
|
||||||
|
|
||||||
|
|
@ -5606,12 +5600,12 @@ pub const Editor = struct {
|
||||||
const frame = tracy.initZone(@src(), .{ .name = "editor diff syntax" });
|
const frame = tracy.initZone(@src(), .{ .name = "editor diff syntax" });
|
||||||
defer frame.deinit();
|
defer frame.deinit();
|
||||||
|
|
||||||
var content_ = std.ArrayListUnmanaged(u8).empty;
|
var content_: std.Io.Writer.Allocating = .init(self.allocator);
|
||||||
defer content_.deinit(self.allocator);
|
defer content_.deinit();
|
||||||
const root = self.buf_root() catch return;
|
const root = self.buf_root() catch return;
|
||||||
const eol_mode = self.buf_eol_mode() catch return;
|
const eol_mode = self.buf_eol_mode() catch return;
|
||||||
try root.store(content_.writer(self.allocator), eol_mode);
|
try root.store(&content_.writer, eol_mode);
|
||||||
const content = content_.items;
|
const content = content_.written();
|
||||||
var last_begin_row: usize = 0;
|
var last_begin_row: usize = 0;
|
||||||
var last_begin_col_pos: usize = 0;
|
var last_begin_col_pos: usize = 0;
|
||||||
var last_end_row: usize = 0;
|
var last_end_row: usize = 0;
|
||||||
|
|
@ -5792,12 +5786,11 @@ pub const Editor = struct {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (self.get_formatter()) |fmtr| {
|
if (self.get_formatter()) |fmtr| {
|
||||||
var args = std.ArrayListUnmanaged(u8).empty;
|
var args: std.Io.Writer.Allocating = .init(self.allocator);
|
||||||
defer args.deinit(self.allocator);
|
defer args.deinit();
|
||||||
const writer = args.writer(self.allocator);
|
try cbor.writeArrayHeader(&args.writer, fmtr.len);
|
||||||
try cbor.writeArrayHeader(writer, fmtr.len);
|
for (fmtr) |arg| try cbor.writeValue(&args.writer, arg);
|
||||||
for (fmtr) |arg| try cbor.writeValue(writer, arg);
|
try self.filter_cmd(.{ .buf = try args.toOwnedSlice() });
|
||||||
try self.filter_cmd(.{ .buf = try args.toOwnedSlice(self.allocator) });
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return tp.exit("no formatter");
|
return tp.exit("no formatter");
|
||||||
|
|
@ -5842,9 +5835,10 @@ pub const Editor = struct {
|
||||||
sp.close() catch {};
|
sp.close() catch {};
|
||||||
sp.deinit();
|
sp.deinit();
|
||||||
}
|
}
|
||||||
var buffer = sp.bufferedWriter();
|
var sp_buf: [tp.subprocess.max_chunk_size]u8 = undefined;
|
||||||
try self.write_range(state.before_root, sel, buffer.writer(), tp.exit_error, null);
|
var writer = sp.writer(&sp_buf);
|
||||||
try buffer.flush();
|
try self.write_range(state.before_root, sel, &writer.interface, null);
|
||||||
|
try writer.interface.flush();
|
||||||
self.logger.print("filter: sent", .{});
|
self.logger.print("filter: sent", .{});
|
||||||
state.work_root = try state.work_root.delete_range(sel, buf_a_, null, self.metrics);
|
state.work_root = try state.work_root.delete_range(sel, buf_a_, null, self.metrics);
|
||||||
}
|
}
|
||||||
|
|
@ -5988,34 +5982,20 @@ pub const Editor = struct {
|
||||||
saved.cursor = sel.end;
|
saved.cursor = sel.end;
|
||||||
break :ret sel;
|
break :ret sel;
|
||||||
};
|
};
|
||||||
var result = std.ArrayList(u8).init(self.allocator);
|
var range: std.Io.Writer.Allocating = .init(self.allocator);
|
||||||
defer result.deinit();
|
defer range.deinit();
|
||||||
const writer: struct {
|
self.write_range(root, sel.*, &range.writer, null) catch return error.Stop;
|
||||||
self_: *Self,
|
|
||||||
result: *std.ArrayList(u8),
|
|
||||||
allocator: std.mem.Allocator,
|
|
||||||
|
|
||||||
const Error = @typeInfo(@typeInfo(@TypeOf(Buffer.unicode.LetterCasing.toUpperStr)).@"fn".return_type.?).error_union.error_set;
|
const bytes = range.written();
|
||||||
pub fn write(writer: *@This(), bytes: []const u8) Error!void {
|
|
||||||
const letter_casing = Buffer.unicode.get_letter_casing();
|
const letter_casing = Buffer.unicode.get_letter_casing();
|
||||||
const flipped = if (letter_casing.isLowerStr(bytes))
|
const flipped = if (letter_casing.isLowerStr(bytes))
|
||||||
try letter_casing.toUpperStr(writer.self_.allocator, bytes)
|
letter_casing.toUpperStr(self.allocator, bytes) catch return error.Stop
|
||||||
else
|
else
|
||||||
try letter_casing.toLowerStr(writer.self_.allocator, bytes);
|
letter_casing.toLowerStr(self.allocator, bytes) catch return error.Stop;
|
||||||
defer writer.self_.allocator.free(flipped);
|
defer self.allocator.free(flipped);
|
||||||
return writer.result.appendSlice(flipped);
|
|
||||||
}
|
|
||||||
fn map_error(e: anyerror, _: ?*std.builtin.StackTrace) Error {
|
|
||||||
return @errorCast(e);
|
|
||||||
}
|
|
||||||
} = .{
|
|
||||||
.self_ = self,
|
|
||||||
.result = &result,
|
|
||||||
.allocator = allocator,
|
|
||||||
};
|
|
||||||
self.write_range(root, sel.*, writer, @TypeOf(writer).map_error, null) catch return error.Stop;
|
|
||||||
root = try self.delete_selection(root, cursel, allocator);
|
root = try self.delete_selection(root, cursel, allocator);
|
||||||
root = self.insert(root, cursel, writer.result.items, allocator) catch return error.Stop;
|
root = self.insert(root, cursel, flipped, allocator) catch return error.Stop;
|
||||||
cursel.* = saved;
|
cursel.* = saved;
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
@ -6089,17 +6069,17 @@ pub const Editor = struct {
|
||||||
};
|
};
|
||||||
|
|
||||||
if (self.file_type) |ft| {
|
if (self.file_type) |ft| {
|
||||||
var content = std.ArrayListUnmanaged(u8).empty;
|
var content: std.Io.Writer.Allocating = .init(self.allocator);
|
||||||
defer content.deinit(std.heap.c_allocator);
|
defer content.deinit();
|
||||||
const root = try self.buf_root();
|
const root = try self.buf_root();
|
||||||
try root.store(content.writer(std.heap.c_allocator), try self.buf_eol_mode());
|
try root.store(&content.writer, try self.buf_eol_mode());
|
||||||
|
|
||||||
if (self.buffer) |buffer| if (self.file_path) |file_path|
|
if (self.buffer) |buffer| if (self.file_path) |file_path|
|
||||||
project_manager.did_open(
|
project_manager.did_open(
|
||||||
file_path,
|
file_path,
|
||||||
ft,
|
ft,
|
||||||
buffer.lsp_version,
|
buffer.lsp_version,
|
||||||
try content.toOwnedSlice(std.heap.c_allocator),
|
try content.toOwnedSlice(),
|
||||||
if (self.buffer) |p| p.is_ephemeral() else true,
|
if (self.buffer) |p| p.is_ephemeral() else true,
|
||||||
) catch |e|
|
) catch |e|
|
||||||
self.logger.print("project_manager.did_open failed: {any}", .{e});
|
self.logger.print("project_manager.did_open failed: {any}", .{e});
|
||||||
|
|
@ -6378,6 +6358,7 @@ pub const EditorWidget = struct {
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const PosToWidthCache = struct {
|
pub const PosToWidthCache = struct {
|
||||||
|
allocator: std.mem.Allocator,
|
||||||
cache: std.ArrayList(usize),
|
cache: std.ArrayList(usize),
|
||||||
cached_line: usize = std.math.maxInt(usize),
|
cached_line: usize = std.math.maxInt(usize),
|
||||||
cached_root: ?Buffer.Root = null,
|
cached_root: ?Buffer.Root = null,
|
||||||
|
|
@ -6386,12 +6367,13 @@ pub const PosToWidthCache = struct {
|
||||||
|
|
||||||
pub fn init(allocator: Allocator) !Self {
|
pub fn init(allocator: Allocator) !Self {
|
||||||
return .{
|
return .{
|
||||||
|
.allocator = allocator,
|
||||||
.cache = try .initCapacity(allocator, 2048),
|
.cache = try .initCapacity(allocator, 2048),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deinit(self: *Self) void {
|
pub fn deinit(self: *Self) void {
|
||||||
self.cache.deinit();
|
self.cache.deinit(self.allocator);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn range_to_selection(self: *Self, range: syntax.Range, root: Buffer.Root, metrics: Buffer.Metrics) ?Selection {
|
pub fn range_to_selection(self: *Self, range: syntax.Range, root: Buffer.Root, metrics: Buffer.Metrics) ?Selection {
|
||||||
|
|
@ -6401,7 +6383,7 @@ pub const PosToWidthCache = struct {
|
||||||
self.cache.clearRetainingCapacity();
|
self.cache.clearRetainingCapacity();
|
||||||
self.cached_line = start.row;
|
self.cached_line = start.row;
|
||||||
self.cached_root = root;
|
self.cached_root = root;
|
||||||
root.get_line_width_map(self.cached_line, &self.cache, metrics) catch return null;
|
root.get_line_width_map(self.cached_line, &self.cache, self.allocator, metrics) catch return null;
|
||||||
}
|
}
|
||||||
const start_col = if (start.column < self.cache.items.len) self.cache.items[start.column] else start.column;
|
const start_col = if (start.column < self.cache.items.len) self.cache.items[start.column] else start.column;
|
||||||
const end_col = if (end.row == start.row and end.column < self.cache.items.len) self.cache.items[end.column] else root.pos_to_width(end.row, end.column, metrics) catch end.column;
|
const end_col = if (end.row == start.row and end.column < self.cache.items.len) self.cache.items[end.column] else root.pos_to_width(end.row, end.column, metrics) catch end.column;
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ pub fn create(allocator: Allocator, parent: Widget, event_source: Widget, editor
|
||||||
.symbols = tui.config().gutter_symbols,
|
.symbols = tui.config().gutter_symbols,
|
||||||
.editor = editor,
|
.editor = editor,
|
||||||
.diff_ = try diff.create(),
|
.diff_ = try diff.create(),
|
||||||
.diff_symbols = std.ArrayList(Symbol).init(allocator),
|
.diff_symbols = .empty,
|
||||||
};
|
};
|
||||||
try tui.message_filters().add(MessageFilter.bind(self, filter_receive));
|
try tui.message_filters().add(MessageFilter.bind(self, filter_receive));
|
||||||
try event_source.subscribe(EventHandler.bind(self, handle_event));
|
try event_source.subscribe(EventHandler.bind(self, handle_event));
|
||||||
|
|
@ -68,7 +68,7 @@ pub fn widget(self: *Self) Widget {
|
||||||
|
|
||||||
pub fn deinit(self: *Self, allocator: Allocator) void {
|
pub fn deinit(self: *Self, allocator: Allocator) void {
|
||||||
self.diff_symbols_clear();
|
self.diff_symbols_clear();
|
||||||
self.diff_symbols.deinit();
|
self.diff_symbols.deinit(self.allocator);
|
||||||
tui.message_filters().remove_ptr(self);
|
tui.message_filters().remove_ptr(self);
|
||||||
self.plane.deinit();
|
self.plane.deinit();
|
||||||
allocator.destroy(self);
|
allocator.destroy(self);
|
||||||
|
|
@ -351,22 +351,21 @@ fn diff_result(from: tp.pid_ref, edits: []diff.Diff) void {
|
||||||
|
|
||||||
fn diff_result_send(from: tp.pid_ref, edits: []diff.Diff) !void {
|
fn diff_result_send(from: tp.pid_ref, edits: []diff.Diff) !void {
|
||||||
var buf: [tp.max_message_size]u8 = undefined;
|
var buf: [tp.max_message_size]u8 = undefined;
|
||||||
var stream = std.io.fixedBufferStream(&buf);
|
var writer: std.Io.Writer = .fixed(&buf);
|
||||||
const writer = stream.writer();
|
try cbor.writeArrayHeader(&writer, 2);
|
||||||
try cbor.writeArrayHeader(writer, 2);
|
try cbor.writeValue(&writer, "DIFF");
|
||||||
try cbor.writeValue(writer, "DIFF");
|
try cbor.writeArrayHeader(&writer, edits.len);
|
||||||
try cbor.writeArrayHeader(writer, edits.len);
|
|
||||||
for (edits) |edit| {
|
for (edits) |edit| {
|
||||||
try cbor.writeArrayHeader(writer, 4);
|
try cbor.writeArrayHeader(&writer, 4);
|
||||||
try cbor.writeValue(writer, switch (edit.kind) {
|
try cbor.writeValue(&writer, switch (edit.kind) {
|
||||||
.insert => "I",
|
.insert => "I",
|
||||||
.delete => "D",
|
.delete => "D",
|
||||||
});
|
});
|
||||||
try cbor.writeValue(writer, edit.line);
|
try cbor.writeValue(&writer, edit.line);
|
||||||
try cbor.writeValue(writer, edit.offset);
|
try cbor.writeValue(&writer, edit.offset);
|
||||||
try cbor.writeValue(writer, edit.bytes);
|
try cbor.writeValue(&writer, edit.bytes);
|
||||||
}
|
}
|
||||||
from.send_raw(tp.message{ .buf = stream.getWritten() }) catch return;
|
from.send_raw(tp.message{ .buf = writer.buffered() }) catch return;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn process_diff(self: *Self, cb: []const u8) MessageFilter.Error!void {
|
pub fn process_diff(self: *Self, cb: []const u8) MessageFilter.Error!void {
|
||||||
|
|
@ -403,7 +402,7 @@ fn process_edit(self: *Self, kind: Kind, line: usize, offset: usize, bytes: []co
|
||||||
self.diff_symbols.items[self.diff_symbols.items.len - 1].kind = .modified;
|
self.diff_symbols.items[self.diff_symbols.items.len - 1].kind = .modified;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
(try self.diff_symbols.addOne()).* = switch (kind) {
|
(try self.diff_symbols.addOne(self.allocator)).* = switch (kind) {
|
||||||
.insert => ret: {
|
.insert => ret: {
|
||||||
if (offset > 0)
|
if (offset > 0)
|
||||||
break :ret .{ .kind = .modified, .line = line };
|
break :ret .{ .kind = .modified, .line = line };
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ pub fn create(allocator: Allocator, parent: Plane) !Widget {
|
||||||
.allocator = allocator,
|
.allocator = allocator,
|
||||||
.plane = try Plane.init(&(Widget.Box{}).opts(name), parent),
|
.plane = try Plane.init(&(Widget.Box{}).opts(name), parent),
|
||||||
.logger = log.logger(@typeName(Self)),
|
.logger = log.logger(@typeName(Self)),
|
||||||
.entries = std.ArrayList(Entry).init(allocator),
|
.entries = .empty,
|
||||||
.menu = try Menu.create(*Self, allocator, tui.plane(), .{
|
.menu = try Menu.create(*Self, allocator, tui.plane(), .{
|
||||||
.ctx = self,
|
.ctx = self,
|
||||||
.style = widget_type,
|
.style = widget_type,
|
||||||
|
|
@ -105,15 +105,14 @@ pub fn walk(self: *Self, walk_ctx: *anyopaque, f: Widget.WalkFn, w: *Widget) boo
|
||||||
|
|
||||||
pub fn add_item(self: *Self, entry_: Entry) !void {
|
pub fn add_item(self: *Self, entry_: Entry) !void {
|
||||||
const idx = self.entries.items.len;
|
const idx = self.entries.items.len;
|
||||||
const entry = (try self.entries.addOne());
|
const entry = (try self.entries.addOne(self.allocator));
|
||||||
entry.* = entry_;
|
entry.* = entry_;
|
||||||
entry.path = try self.allocator.dupe(u8, entry_.path);
|
entry.path = try self.allocator.dupe(u8, entry_.path);
|
||||||
entry.lines = try self.allocator.dupe(u8, entry_.lines);
|
entry.lines = try self.allocator.dupe(u8, entry_.lines);
|
||||||
var label = std.ArrayList(u8).init(self.allocator);
|
var label: std.Io.Writer.Allocating = .init(self.allocator);
|
||||||
defer label.deinit();
|
defer label.deinit();
|
||||||
const writer = label.writer();
|
cbor.writeValue(&label.writer, idx) catch return;
|
||||||
cbor.writeValue(writer, idx) catch return;
|
self.menu.add_item_with_handler(label.written(), handle_menu_action) catch return;
|
||||||
self.menu.add_item_with_handler(label.items, handle_menu_action) catch return;
|
|
||||||
self.menu.resize(self.box);
|
self.menu.resize(self.box);
|
||||||
self.update_scrollbar();
|
self.update_scrollbar();
|
||||||
}
|
}
|
||||||
|
|
@ -182,7 +181,7 @@ fn handle_render_menu(self: *Self, button: *Button.State(*Menu.State(*Self)), th
|
||||||
.Warning => button.plane.set_style(style_warning),
|
.Warning => button.plane.set_style(style_warning),
|
||||||
.Error => button.plane.set_style(style_error),
|
.Error => button.plane.set_style(style_error),
|
||||||
}
|
}
|
||||||
_ = button.plane.print("{s}", .{std.fmt.fmtSliceEscapeLower(entry.lines)}) catch {};
|
_ = button.plane.print("{f}", .{std.ascii.hexEscape(entry.lines, .lower)}) catch {};
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -160,14 +160,14 @@ fn add_menu_command(self: *Self, command_name: []const u8, description: []const
|
||||||
self.menu_w = self.menu_label_max + 2 + padding.left + padding.right;
|
self.menu_w = self.menu_label_max + 2 + padding.left + padding.right;
|
||||||
}
|
}
|
||||||
|
|
||||||
var value = std.ArrayList(u8).init(self.allocator);
|
var value: std.Io.Writer.Allocating = .init(self.allocator);
|
||||||
defer value.deinit();
|
defer value.deinit();
|
||||||
const writer = value.writer();
|
const writer = &value.writer;
|
||||||
try cbor.writeValue(writer, description);
|
try cbor.writeValue(writer, description);
|
||||||
try cbor.writeValue(writer, hint);
|
try cbor.writeValue(writer, hint);
|
||||||
try cbor.writeValue(writer, command_name);
|
try cbor.writeValue(writer, command_name);
|
||||||
|
|
||||||
try menu.add_item_with_handler(value.items, menu_action);
|
try menu.add_item_with_handler(value.written(), menu_action);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update(self: *Self) void {
|
pub fn update(self: *Self) void {
|
||||||
|
|
|
||||||
|
|
@ -19,14 +19,14 @@ pub fn create(allocator: Allocator, parent: Plane) !Widget {
|
||||||
self.* = .{
|
self.* = .{
|
||||||
.allocator = allocator,
|
.allocator = allocator,
|
||||||
.plane = try Plane.init(&(Widget.Box{}).opts(name), parent),
|
.plane = try Plane.init(&(Widget.Box{}).opts(name), parent),
|
||||||
.lines = std.ArrayList([]const u8).init(allocator),
|
.lines = .empty,
|
||||||
};
|
};
|
||||||
return Widget.to(self);
|
return Widget.to(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deinit(self: *Self, allocator: Allocator) void {
|
pub fn deinit(self: *Self, allocator: Allocator) void {
|
||||||
self.clear();
|
self.clear();
|
||||||
self.lines.deinit();
|
self.lines.deinit(self.allocator);
|
||||||
self.plane.deinit();
|
self.plane.deinit();
|
||||||
allocator.destroy(self);
|
allocator.destroy(self);
|
||||||
}
|
}
|
||||||
|
|
@ -47,7 +47,7 @@ pub fn set_content(self: *Self, content: []const u8) !void {
|
||||||
self.clear();
|
self.clear();
|
||||||
var iter = std.mem.splitScalar(u8, content, '\n');
|
var iter = std.mem.splitScalar(u8, content, '\n');
|
||||||
while (iter.next()) |line|
|
while (iter.next()) |line|
|
||||||
(try self.lines.addOne()).* = try self.allocator.dupe(u8, line);
|
(try self.lines.addOne(self.allocator)).* = try self.allocator.dupe(u8, line);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn render(self: *Self, theme: *const Widget.Theme) bool {
|
pub fn render(self: *Self, theme: *const Widget.Theme) bool {
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ const eql = @import("std").mem.eql;
|
||||||
const time = @import("std").time;
|
const time = @import("std").time;
|
||||||
const Allocator = @import("std").mem.Allocator;
|
const Allocator = @import("std").mem.Allocator;
|
||||||
const ArrayList = @import("std").ArrayList;
|
const ArrayList = @import("std").ArrayList;
|
||||||
|
const Writer = @import("std").Io.Writer;
|
||||||
|
|
||||||
const tp = @import("thespian");
|
const tp = @import("thespian");
|
||||||
|
|
||||||
|
|
@ -38,7 +39,7 @@ pub fn create(allocator: Allocator, parent: Plane) !Widget {
|
||||||
.allocator = allocator,
|
.allocator = allocator,
|
||||||
.parent = parent,
|
.parent = parent,
|
||||||
.plane = n,
|
.plane = n,
|
||||||
.buffer = Buffer.init(allocator),
|
.buffer = .empty,
|
||||||
};
|
};
|
||||||
try tui.input_listeners().add(EventHandler.bind(self, listen));
|
try tui.input_listeners().add(EventHandler.bind(self, listen));
|
||||||
return Widget.to(self);
|
return Widget.to(self);
|
||||||
|
|
@ -47,8 +48,8 @@ pub fn create(allocator: Allocator, parent: Plane) !Widget {
|
||||||
pub fn deinit(self: *Self, allocator: Allocator) void {
|
pub fn deinit(self: *Self, allocator: Allocator) void {
|
||||||
tui.input_listeners().remove_ptr(self);
|
tui.input_listeners().remove_ptr(self);
|
||||||
for (self.buffer.items) |item|
|
for (self.buffer.items) |item|
|
||||||
self.buffer.allocator.free(item.json);
|
self.allocator.free(item.json);
|
||||||
self.buffer.deinit();
|
self.buffer.deinit(self.allocator);
|
||||||
self.plane.deinit();
|
self.plane.deinit();
|
||||||
allocator.destroy(self);
|
allocator.destroy(self);
|
||||||
}
|
}
|
||||||
|
|
@ -93,7 +94,7 @@ fn append(self: *Self, json: []const u8) !void {
|
||||||
break :ret ts - last.time;
|
break :ret ts - last.time;
|
||||||
} else 0;
|
} else 0;
|
||||||
self.last_count = 0;
|
self.last_count = 0;
|
||||||
(try self.buffer.addOne()).* = .{
|
(try self.buffer.addOne(self.allocator)).* = .{
|
||||||
.time = ts,
|
.time = ts,
|
||||||
.tdiff = tdiff,
|
.tdiff = tdiff,
|
||||||
.json = try self.allocator.dupeZ(u8, json),
|
.json = try self.allocator.dupeZ(u8, json),
|
||||||
|
|
@ -104,9 +105,9 @@ pub fn listen(self: *Self, _: tp.pid_ref, m: tp.message) tp.result {
|
||||||
if (try m.match(.{ "M", tp.more })) return;
|
if (try m.match(.{ "M", tp.more })) return;
|
||||||
var buf: [4096]u8 = undefined;
|
var buf: [4096]u8 = undefined;
|
||||||
const json = m.to_json(&buf) catch |e| return tp.exit_error(e, @errorReturnTrace());
|
const json = m.to_json(&buf) catch |e| return tp.exit_error(e, @errorReturnTrace());
|
||||||
var result = ArrayList(u8).init(self.allocator);
|
var result: Writer.Allocating = .init(self.allocator);
|
||||||
defer result.deinit();
|
defer result.deinit();
|
||||||
const writer = result.writer();
|
const writer = &result.writer;
|
||||||
writer.writeAll(json) catch |e| return tp.exit_error(e, @errorReturnTrace());
|
writer.writeAll(json) catch |e| return tp.exit_error(e, @errorReturnTrace());
|
||||||
|
|
||||||
var event: input.Event = 0;
|
var event: input.Event = 0;
|
||||||
|
|
@ -123,9 +124,9 @@ pub fn listen(self: *Self, _: tp.pid_ref, m: tp.message) tp.result {
|
||||||
tp.extract(&modifiers),
|
tp.extract(&modifiers),
|
||||||
})) {
|
})) {
|
||||||
const key_event = input.KeyEvent.from_message(event, keypress, keypress_shifted, text, modifiers);
|
const key_event = input.KeyEvent.from_message(event, keypress, keypress_shifted, text, modifiers);
|
||||||
writer.print(" -> {}", .{key_event}) catch |e| return tp.exit_error(e, @errorReturnTrace());
|
writer.print(" -> {f}", .{key_event}) catch |e| return tp.exit_error(e, @errorReturnTrace());
|
||||||
}
|
}
|
||||||
self.append(result.items) catch |e| return tp.exit_error(e, @errorReturnTrace());
|
self.append(result.written()) catch |e| return tp.exit_error(e, @errorReturnTrace());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn receive(_: *Self, _: tp.pid_ref, _: tp.message) error{Exit}!bool {
|
pub fn receive(_: *Self, _: tp.pid_ref, _: tp.message) error{Exit}!bool {
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ const eql = @import("std").mem.eql;
|
||||||
const fmt = @import("std").fmt;
|
const fmt = @import("std").fmt;
|
||||||
const time = @import("std").time;
|
const time = @import("std").time;
|
||||||
const Allocator = @import("std").mem.Allocator;
|
const Allocator = @import("std").mem.Allocator;
|
||||||
const ArrayList = @import("std").ArrayList;
|
const array_list = @import("std").array_list;
|
||||||
|
|
||||||
const tp = @import("thespian");
|
const tp = @import("thespian");
|
||||||
const cbor = @import("cbor");
|
const cbor = @import("cbor");
|
||||||
|
|
@ -12,7 +12,7 @@ const Plane = @import("renderer").Plane;
|
||||||
const Widget = @import("Widget.zig");
|
const Widget = @import("Widget.zig");
|
||||||
const MessageFilter = @import("MessageFilter.zig");
|
const MessageFilter = @import("MessageFilter.zig");
|
||||||
|
|
||||||
const escape = fmt.fmtSliceEscapeLower;
|
const escape = @import("std").ascii.hexEscape;
|
||||||
|
|
||||||
pub const name = @typeName(Self);
|
pub const name = @typeName(Self);
|
||||||
|
|
||||||
|
|
@ -30,7 +30,7 @@ const Entry = struct {
|
||||||
tdiff: i64,
|
tdiff: i64,
|
||||||
level: Level,
|
level: Level,
|
||||||
};
|
};
|
||||||
const Buffer = ArrayList(Entry);
|
const Buffer = array_list.Managed(Entry);
|
||||||
|
|
||||||
const Level = enum {
|
const Level = enum {
|
||||||
info,
|
info,
|
||||||
|
|
@ -65,7 +65,7 @@ pub fn render(self: *Self, theme: *const Widget.Theme) bool {
|
||||||
if (first) first = false else _ = self.plane.putstr("\n") catch return false;
|
if (first) first = false else _ = self.plane.putstr("\n") catch return false;
|
||||||
self.output_tdiff(item.tdiff) catch return false;
|
self.output_tdiff(item.tdiff) catch return false;
|
||||||
self.plane.set_style(if (item.level == .err) style_error else style_info);
|
self.plane.set_style(if (item.level == .err) style_error else style_info);
|
||||||
_ = self.plane.print("{s}: {s}", .{ escape(item.src), escape(item.msg) }) catch {};
|
_ = self.plane.print("{f}: {f}", .{ escape(item.src, .lower), escape(item.msg, .lower) }) catch {};
|
||||||
self.plane.set_style(style_normal);
|
self.plane.set_style(style_normal);
|
||||||
}
|
}
|
||||||
if (last_count > 0)
|
if (last_count > 0)
|
||||||
|
|
@ -128,7 +128,7 @@ fn append_error(buffer: *Buffer, src: []const u8, context: []const u8, msg_: []c
|
||||||
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
|
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
|
||||||
defer arena.deinit();
|
defer arena.deinit();
|
||||||
var sfa = std.heap.stackFallback(4096, arena.allocator());
|
var sfa = std.heap.stackFallback(4096, arena.allocator());
|
||||||
var msg = std.ArrayList(u8).init(sfa.get());
|
var msg = std.array_list.Managed(u8).init(sfa.get());
|
||||||
try fmt.format(msg.writer(), "error in {s}: {s}", .{ context, msg_ });
|
try fmt.format(msg.writer(), "error in {s}: {s}", .{ context, msg_ });
|
||||||
try append(buffer, src, msg.items, .err);
|
try append(buffer, src, msg.items, .err);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -253,14 +253,14 @@ fn open_style_config(self: *Self, Style: type) command.Result {
|
||||||
break :blk .{ style, style_bufs };
|
break :blk .{ style, style_bufs };
|
||||||
} else .{ Style{}, &.{} };
|
} else .{ Style{}, &.{} };
|
||||||
defer root.free_config(self.allocator, style_bufs);
|
defer root.free_config(self.allocator, style_bufs);
|
||||||
var conf = std.ArrayListUnmanaged(u8).empty;
|
var conf: std.Io.Writer.Allocating = .init(self.allocator);
|
||||||
defer conf.deinit(self.allocator);
|
defer conf.deinit();
|
||||||
root.write_config_to_writer(Style, style, conf.writer(self.allocator)) catch {};
|
root.write_config_to_writer(Style, style, &conf.writer) catch {};
|
||||||
tui.reset_drag_context();
|
tui.reset_drag_context();
|
||||||
try self.create_editor();
|
try self.create_editor();
|
||||||
try command.executeName("open_scratch_buffer", command.fmt(.{
|
try command.executeName("open_scratch_buffer", command.fmt(.{
|
||||||
file_name[0 .. file_name.len - ".json".len],
|
file_name[0 .. file_name.len - ".json".len],
|
||||||
conf.items,
|
conf.written(),
|
||||||
"conf",
|
"conf",
|
||||||
}));
|
}));
|
||||||
if (self.get_active_buffer()) |buffer| buffer.mark_not_ephemeral();
|
if (self.get_active_buffer()) |buffer| buffer.mark_not_ephemeral();
|
||||||
|
|
@ -387,9 +387,9 @@ const cmds = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
const f_ = project_manager.normalize_file_path(file orelse return);
|
const f_ = project_manager.normalize_file_path(file orelse return);
|
||||||
var buf = std.ArrayList(u8).init(self.allocator);
|
var buf: std.ArrayList(u8) = .empty;
|
||||||
defer buf.deinit();
|
defer buf.deinit(self.allocator);
|
||||||
const f = project_manager.expand_home(&buf, f_);
|
const f = project_manager.expand_home(self.allocator, &buf, f_);
|
||||||
const same_file = if (self.get_active_file_path()) |fp| std.mem.eql(u8, fp, f) else false;
|
const same_file = if (self.get_active_file_path()) |fp| std.mem.eql(u8, fp, f) else false;
|
||||||
const have_editor_metadata = if (self.buffer_manager.get_buffer_for_file(f)) |_| true else false;
|
const have_editor_metadata = if (self.buffer_manager.get_buffer_for_file(f)) |_| true else false;
|
||||||
|
|
||||||
|
|
@ -556,11 +556,11 @@ const cmds = struct {
|
||||||
pub fn create_new_file(self: *Self, _: Ctx) Result {
|
pub fn create_new_file(self: *Self, _: Ctx) Result {
|
||||||
var n: usize = 1;
|
var n: usize = 1;
|
||||||
var found_unique = false;
|
var found_unique = false;
|
||||||
var name = std.ArrayList(u8).init(self.allocator);
|
var name: std.ArrayList(u8) = .empty;
|
||||||
defer name.deinit();
|
defer name.deinit(self.allocator);
|
||||||
while (!found_unique) {
|
while (!found_unique) {
|
||||||
name.clearRetainingCapacity();
|
name.clearRetainingCapacity();
|
||||||
try name.writer().print("Untitled-{d}", .{n});
|
try name.writer(self.allocator).print("Untitled-{d}", .{n});
|
||||||
if (self.buffer_manager.get_buffer_for_file(name.items)) |_| {
|
if (self.buffer_manager.get_buffer_for_file(name.items)) |_| {
|
||||||
n += 1;
|
n += 1;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -580,9 +580,9 @@ const cmds = struct {
|
||||||
|
|
||||||
if (self.get_active_editor()) |editor| {
|
if (self.get_active_editor()) |editor| {
|
||||||
const buffer = editor.buffer orelse return;
|
const buffer = editor.buffer orelse return;
|
||||||
var content = std.ArrayListUnmanaged(u8).empty;
|
var content: std.Io.Writer.Allocating = .init(self.allocator);
|
||||||
defer content.deinit(self.allocator);
|
defer content.deinit();
|
||||||
try buffer.root.store(content.writer(self.allocator), buffer.file_eol_mode);
|
try buffer.root.store(&content.writer, buffer.file_eol_mode);
|
||||||
|
|
||||||
var existing = false;
|
var existing = false;
|
||||||
if (self.buffer_manager.get_buffer_for_file(file_path)) |new_buffer| {
|
if (self.buffer_manager.get_buffer_for_file(file_path)) |new_buffer| {
|
||||||
|
|
@ -601,7 +601,7 @@ const cmds = struct {
|
||||||
if (self.get_active_editor()) |new_editor| {
|
if (self.get_active_editor()) |new_editor| {
|
||||||
const new_buffer = new_editor.buffer orelse return;
|
const new_buffer = new_editor.buffer orelse return;
|
||||||
if (existing) new_editor.update_buf(new_buffer.root) catch {}; // store an undo point
|
if (existing) new_editor.update_buf(new_buffer.root) catch {}; // store an undo point
|
||||||
try new_buffer.reset_from_string_and_update(content.items);
|
try new_buffer.reset_from_string_and_update(content.written());
|
||||||
new_buffer.mark_not_ephemeral();
|
new_buffer.mark_not_ephemeral();
|
||||||
new_buffer.mark_dirty();
|
new_buffer.mark_dirty();
|
||||||
new_editor.clamp();
|
new_editor.clamp();
|
||||||
|
|
@ -1310,8 +1310,9 @@ fn create_home_split(self: *Self) !void {
|
||||||
pub fn write_restore_info(self: *Self) void {
|
pub fn write_restore_info(self: *Self) void {
|
||||||
var sfa = std.heap.stackFallback(512, self.allocator);
|
var sfa = std.heap.stackFallback(512, self.allocator);
|
||||||
const a = sfa.get();
|
const a = sfa.get();
|
||||||
var meta = std.ArrayListUnmanaged(u8).empty;
|
var meta: std.Io.Writer.Allocating = .init(a);
|
||||||
const writer = meta.writer(a);
|
defer meta.deinit();
|
||||||
|
const writer = &meta.writer;
|
||||||
|
|
||||||
if (self.get_active_editor()) |editor| {
|
if (self.get_active_editor()) |editor| {
|
||||||
cbor.writeValue(writer, editor.file_path) catch return;
|
cbor.writeValue(writer, editor.file_path) catch return;
|
||||||
|
|
@ -1330,7 +1331,7 @@ pub fn write_restore_info(self: *Self) void {
|
||||||
const file_name = root.get_restore_file_name() catch return;
|
const file_name = root.get_restore_file_name() catch return;
|
||||||
var file = std.fs.createFileAbsolute(file_name, .{ .truncate = true }) catch return;
|
var file = std.fs.createFileAbsolute(file_name, .{ .truncate = true }) catch return;
|
||||||
defer file.close();
|
defer file.close();
|
||||||
file.writeAll(meta.items) catch return;
|
file.writeAll(meta.written()) catch return;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_restore_info(self: *Self) !void {
|
fn read_restore_info(self: *Self) !void {
|
||||||
|
|
@ -1370,15 +1371,15 @@ fn read_restore_info(self: *Self) !void {
|
||||||
|
|
||||||
fn send_buffer_did_open(allocator: std.mem.Allocator, buffer: *Buffer) !void {
|
fn send_buffer_did_open(allocator: std.mem.Allocator, buffer: *Buffer) !void {
|
||||||
const ft = try file_type_config.get(buffer.file_type_name orelse return) orelse return;
|
const ft = try file_type_config.get(buffer.file_type_name orelse return) orelse return;
|
||||||
var content = std.ArrayListUnmanaged(u8).empty;
|
var content: std.Io.Writer.Allocating = .init(allocator);
|
||||||
defer content.deinit(allocator);
|
defer content.deinit();
|
||||||
try buffer.root.store(content.writer(allocator), buffer.file_eol_mode);
|
try buffer.root.store(&content.writer, buffer.file_eol_mode);
|
||||||
|
|
||||||
try project_manager.did_open(
|
try project_manager.did_open(
|
||||||
buffer.get_file_path(),
|
buffer.get_file_path(),
|
||||||
ft,
|
ft,
|
||||||
buffer.lsp_version,
|
buffer.lsp_version,
|
||||||
try content.toOwnedSlice(allocator),
|
try content.toOwnedSlice(),
|
||||||
buffer.is_ephemeral(),
|
buffer.is_ephemeral(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -235,9 +235,11 @@ const cmds_ = struct {
|
||||||
const ed = mv.get_active_editor() orelse return;
|
const ed = mv.get_active_editor() orelse return;
|
||||||
const root = ed.buf_root() catch return;
|
const root = ed.buf_root() catch return;
|
||||||
var first = true;
|
var first = true;
|
||||||
var text = std.ArrayList(u8).init(ed.allocator);
|
var buffer: std.Io.Writer.Allocating = .init(ed.allocator);
|
||||||
|
defer buffer.deinit();
|
||||||
|
const writer = &buffer.writer;
|
||||||
|
|
||||||
if (ed.get_primary().selection) |sel| if (sel.begin.col == 0 and sel.end.row > sel.begin.row) try text.appendSlice("\n");
|
if (ed.get_primary().selection) |sel| if (sel.begin.col == 0 and sel.end.row > sel.begin.row) try writer.writeAll("\n");
|
||||||
|
|
||||||
for (ed.cursels.items) |*cursel_| if (cursel_.*) |*cursel| {
|
for (ed.cursels.items) |*cursel_| if (cursel_.*) |*cursel| {
|
||||||
if (cursel.selection) |sel| {
|
if (cursel.selection) |sel| {
|
||||||
|
|
@ -245,18 +247,19 @@ const cmds_ = struct {
|
||||||
if (first) {
|
if (first) {
|
||||||
first = false;
|
first = false;
|
||||||
} else {
|
} else {
|
||||||
try text.appendSlice("\n");
|
try writer.writeAll("\n");
|
||||||
}
|
}
|
||||||
try text.appendSlice(copy_text);
|
try writer.writeAll(copy_text);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if (text.items.len > 0) {
|
const text = buffer.written();
|
||||||
if (text.items.len > 100) {
|
if (text.len > 0) {
|
||||||
ed.logger.print("copy:{s}...", .{std.fmt.fmtSliceEscapeLower(text.items[0..100])});
|
if (text.len > 100) {
|
||||||
|
ed.logger.print("copy:{f}...", .{std.ascii.hexEscape(text[0..100], .lower)});
|
||||||
} else {
|
} else {
|
||||||
ed.logger.print("copy:{s}", .{std.fmt.fmtSliceEscapeLower(text.items)});
|
ed.logger.print("copy:{f}", .{std.ascii.hexEscape(text, .lower)});
|
||||||
}
|
}
|
||||||
ed.set_clipboard_internal(text.items);
|
ed.set_clipboard_internal(text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub const copy_helix_meta: Meta = .{ .description = "Copy selection to clipboard (helix)" };
|
pub const copy_helix_meta: Meta = .{ .description = "Copy selection to clipboard (helix)" };
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ pub fn Create(options: type) type {
|
||||||
errdefer allocator.destroy(self);
|
errdefer allocator.destroy(self);
|
||||||
self.* = .{
|
self.* = .{
|
||||||
.allocator = allocator,
|
.allocator = allocator,
|
||||||
.input = std.ArrayList(u8).init(allocator),
|
.input = .empty,
|
||||||
};
|
};
|
||||||
try self.commands.init(self);
|
try self.commands.init(self);
|
||||||
if (@hasDecl(options, "restore_state"))
|
if (@hasDecl(options, "restore_state"))
|
||||||
|
|
@ -39,7 +39,7 @@ pub fn Create(options: type) type {
|
||||||
|
|
||||||
pub fn deinit(self: *Self) void {
|
pub fn deinit(self: *Self) void {
|
||||||
self.commands.deinit();
|
self.commands.deinit();
|
||||||
self.input.deinit();
|
self.input.deinit(self.allocator);
|
||||||
self.allocator.destroy(self);
|
self.allocator.destroy(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -47,7 +47,7 @@ pub fn Create(options: type) type {
|
||||||
var text: []const u8 = undefined;
|
var text: []const u8 = undefined;
|
||||||
|
|
||||||
if (try m.match(.{ "system_clipboard", tp.extract(&text) })) {
|
if (try m.match(.{ "system_clipboard", tp.extract(&text) })) {
|
||||||
self.input.appendSlice(text) catch |e| return tp.exit_error(e, @errorReturnTrace());
|
self.input.appendSlice(self.allocator, text) catch |e| return tp.exit_error(e, @errorReturnTrace());
|
||||||
}
|
}
|
||||||
self.update_mini_mode_text();
|
self.update_mini_mode_text();
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -96,7 +96,7 @@ pub fn Create(options: type) type {
|
||||||
return error.InvalidMiniBufferInsertCodePointArgument;
|
return error.InvalidMiniBufferInsertCodePointArgument;
|
||||||
var buf: [32]u8 = undefined;
|
var buf: [32]u8 = undefined;
|
||||||
const bytes = try input.ucs32_to_utf8(&[_]u32{egc}, &buf);
|
const bytes = try input.ucs32_to_utf8(&[_]u32{egc}, &buf);
|
||||||
try self.input.appendSlice(buf[0..bytes]);
|
try self.input.appendSlice(self.allocator, buf[0..bytes]);
|
||||||
self.update_mini_mode_text();
|
self.update_mini_mode_text();
|
||||||
}
|
}
|
||||||
pub const mini_mode_insert_code_point_meta: Meta = .{ .arguments = &.{.integer} };
|
pub const mini_mode_insert_code_point_meta: Meta = .{ .arguments = &.{.integer} };
|
||||||
|
|
@ -105,7 +105,7 @@ pub fn Create(options: type) type {
|
||||||
var bytes: []const u8 = undefined;
|
var bytes: []const u8 = undefined;
|
||||||
if (!try ctx.args.match(.{tp.extract(&bytes)}))
|
if (!try ctx.args.match(.{tp.extract(&bytes)}))
|
||||||
return error.InvalidMiniBufferInsertBytesArgument;
|
return error.InvalidMiniBufferInsertBytesArgument;
|
||||||
try self.input.appendSlice(bytes);
|
try self.input.appendSlice(self.allocator, bytes);
|
||||||
self.update_mini_mode_text();
|
self.update_mini_mode_text();
|
||||||
}
|
}
|
||||||
pub const mini_mode_insert_bytes_meta: Meta = .{ .arguments = &.{.string} };
|
pub const mini_mode_insert_bytes_meta: Meta = .{ .arguments = &.{.string} };
|
||||||
|
|
|
||||||
|
|
@ -47,10 +47,10 @@ pub fn Create(options: type) type {
|
||||||
errdefer allocator.destroy(self);
|
errdefer allocator.destroy(self);
|
||||||
self.* = .{
|
self.* = .{
|
||||||
.allocator = allocator,
|
.allocator = allocator,
|
||||||
.file_path = std.ArrayList(u8).init(allocator),
|
.file_path = .empty,
|
||||||
.query = std.ArrayList(u8).init(allocator),
|
.query = .empty,
|
||||||
.match = std.ArrayList(u8).init(allocator),
|
.match = .empty,
|
||||||
.entries = std.ArrayList(Entry).init(allocator),
|
.entries = .empty,
|
||||||
};
|
};
|
||||||
try self.commands.init(self);
|
try self.commands.init(self);
|
||||||
try tui.message_filters().add(MessageFilter.bind(self, receive_path_entry));
|
try tui.message_filters().add(MessageFilter.bind(self, receive_path_entry));
|
||||||
|
|
@ -68,10 +68,10 @@ pub fn Create(options: type) type {
|
||||||
self.commands.deinit();
|
self.commands.deinit();
|
||||||
tui.message_filters().remove_ptr(self);
|
tui.message_filters().remove_ptr(self);
|
||||||
self.clear_entries();
|
self.clear_entries();
|
||||||
self.entries.deinit();
|
self.entries.deinit(self.allocator);
|
||||||
self.match.deinit();
|
self.match.deinit(self.allocator);
|
||||||
self.query.deinit();
|
self.query.deinit(self.allocator);
|
||||||
self.file_path.deinit();
|
self.file_path.deinit(self.allocator);
|
||||||
self.rendered_mini_buffer.deinit(self.allocator);
|
self.rendered_mini_buffer.deinit(self.allocator);
|
||||||
self.allocator.destroy(self);
|
self.allocator.destroy(self);
|
||||||
}
|
}
|
||||||
|
|
@ -80,7 +80,7 @@ pub fn Create(options: type) type {
|
||||||
var text: []const u8 = undefined;
|
var text: []const u8 = undefined;
|
||||||
|
|
||||||
if (try m.match(.{ "system_clipboard", tp.extract(&text) })) {
|
if (try m.match(.{ "system_clipboard", tp.extract(&text) })) {
|
||||||
self.file_path.appendSlice(text) catch |e| return tp.exit_error(e, @errorReturnTrace());
|
self.file_path.appendSlice(self.allocator, text) catch |e| return tp.exit_error(e, @errorReturnTrace());
|
||||||
}
|
}
|
||||||
self.update_mini_mode_text();
|
self.update_mini_mode_text();
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -102,14 +102,14 @@ pub fn Create(options: type) type {
|
||||||
self.match.clearRetainingCapacity();
|
self.match.clearRetainingCapacity();
|
||||||
self.clear_entries();
|
self.clear_entries();
|
||||||
if (root.is_directory(self.file_path.items)) {
|
if (root.is_directory(self.file_path.items)) {
|
||||||
try self.query.appendSlice(self.file_path.items);
|
try self.query.appendSlice(self.allocator, self.file_path.items);
|
||||||
} else if (self.file_path.items.len > 0) blk: {
|
} else if (self.file_path.items.len > 0) blk: {
|
||||||
const basename_begin = std.mem.lastIndexOfScalar(u8, self.file_path.items, std.fs.path.sep) orelse {
|
const basename_begin = std.mem.lastIndexOfScalar(u8, self.file_path.items, std.fs.path.sep) orelse {
|
||||||
try self.match.appendSlice(self.file_path.items);
|
try self.match.appendSlice(self.allocator, self.file_path.items);
|
||||||
break :blk;
|
break :blk;
|
||||||
};
|
};
|
||||||
try self.query.appendSlice(self.file_path.items[0 .. basename_begin + 1]);
|
try self.query.appendSlice(self.allocator, self.file_path.items[0 .. basename_begin + 1]);
|
||||||
try self.match.appendSlice(self.file_path.items[basename_begin + 1 ..]);
|
try self.match.appendSlice(self.allocator, self.file_path.items[basename_begin + 1 ..]);
|
||||||
}
|
}
|
||||||
// log.logger("file_browser").print("query: '{s}' match: '{s}'", .{ self.query.items, self.match.items });
|
// log.logger("file_browser").print("query: '{s}' match: '{s}'", .{ self.query.items, self.match.items });
|
||||||
try project_manager.request_path_files(max_complete_paths, self.query.items);
|
try project_manager.request_path_files(max_complete_paths, self.query.items);
|
||||||
|
|
@ -125,7 +125,7 @@ pub fn Create(options: type) type {
|
||||||
if (self.match.items.len > 0) {
|
if (self.match.items.len > 0) {
|
||||||
try self.construct_path(self.query.items, self.match.items, .file, 0);
|
try self.construct_path(self.query.items, self.match.items, .file, 0);
|
||||||
} else {
|
} else {
|
||||||
try self.file_path.appendSlice(self.query.items);
|
try self.file_path.appendSlice(self.allocator, self.query.items);
|
||||||
}
|
}
|
||||||
self.update_mini_mode_text();
|
self.update_mini_mode_text();
|
||||||
return;
|
return;
|
||||||
|
|
@ -177,7 +177,7 @@ pub fn Create(options: type) type {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_entry(self: *Self, file_name: []const u8, entry_type: EntryType, file_type: []const u8, icon: []const u8, color: u24) !void {
|
fn add_entry(self: *Self, file_name: []const u8, entry_type: EntryType, file_type: []const u8, icon: []const u8, color: u24) !void {
|
||||||
(try self.entries.addOne()).* = .{
|
(try self.entries.addOne(self.allocator)).* = .{
|
||||||
.name = try self.allocator.dupe(u8, file_name),
|
.name = try self.allocator.dupe(u8, file_name),
|
||||||
.type = entry_type,
|
.type = entry_type,
|
||||||
.file_type = try self.allocator.dupe(u8, file_type),
|
.file_type = try self.allocator.dupe(u8, file_type),
|
||||||
|
|
@ -212,12 +212,12 @@ pub fn Create(options: type) type {
|
||||||
fn construct_path(self: *Self, path_: []const u8, entry_name: []const u8, entry_type: EntryType, entry_no: usize) error{OutOfMemory}!void {
|
fn construct_path(self: *Self, path_: []const u8, entry_name: []const u8, entry_type: EntryType, entry_no: usize) error{OutOfMemory}!void {
|
||||||
self.matched_entry = entry_no;
|
self.matched_entry = entry_no;
|
||||||
const path = project_manager.normalize_file_path(path_);
|
const path = project_manager.normalize_file_path(path_);
|
||||||
try self.file_path.appendSlice(path);
|
try self.file_path.appendSlice(self.allocator, path);
|
||||||
if (path.len > 0 and path[path.len - 1] != std.fs.path.sep)
|
if (path.len > 0 and path[path.len - 1] != std.fs.path.sep)
|
||||||
try self.file_path.append(std.fs.path.sep);
|
try self.file_path.append(self.allocator, std.fs.path.sep);
|
||||||
try self.file_path.appendSlice(entry_name);
|
try self.file_path.appendSlice(self.allocator, entry_name);
|
||||||
if (entry_type == .dir)
|
if (entry_type == .dir)
|
||||||
try self.file_path.append(std.fs.path.sep);
|
try self.file_path.append(self.allocator, std.fs.path.sep);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn match_path(self: *Self) !void {
|
fn match_path(self: *Self) !void {
|
||||||
|
|
@ -351,7 +351,7 @@ pub fn Create(options: type) type {
|
||||||
self.complete_trigger_count = 0;
|
self.complete_trigger_count = 0;
|
||||||
var buf: [32]u8 = undefined;
|
var buf: [32]u8 = undefined;
|
||||||
const bytes = try input.ucs32_to_utf8(&[_]u32{egc}, &buf);
|
const bytes = try input.ucs32_to_utf8(&[_]u32{egc}, &buf);
|
||||||
try self.file_path.appendSlice(buf[0..bytes]);
|
try self.file_path.appendSlice(self.allocator, buf[0..bytes]);
|
||||||
self.update_mini_mode_text();
|
self.update_mini_mode_text();
|
||||||
}
|
}
|
||||||
pub const mini_mode_insert_code_point_meta: Meta = .{ .arguments = &.{.integer} };
|
pub const mini_mode_insert_code_point_meta: Meta = .{ .arguments = &.{.integer} };
|
||||||
|
|
@ -361,7 +361,7 @@ pub fn Create(options: type) type {
|
||||||
if (!try ctx.args.match(.{tp.extract(&bytes)}))
|
if (!try ctx.args.match(.{tp.extract(&bytes)}))
|
||||||
return error.InvalidFileBrowserInsertBytesArgument;
|
return error.InvalidFileBrowserInsertBytesArgument;
|
||||||
self.complete_trigger_count = 0;
|
self.complete_trigger_count = 0;
|
||||||
try self.file_path.appendSlice(bytes);
|
try self.file_path.appendSlice(self.allocator, bytes);
|
||||||
self.update_mini_mode_text();
|
self.update_mini_mode_text();
|
||||||
}
|
}
|
||||||
pub const mini_mode_insert_bytes_meta: Meta = .{ .arguments = &.{.string} };
|
pub const mini_mode_insert_bytes_meta: Meta = .{ .arguments = &.{.string} };
|
||||||
|
|
|
||||||
|
|
@ -32,8 +32,8 @@ pub fn create(allocator: Allocator, _: command.Context) !struct { tui.Mode, tui.
|
||||||
errdefer allocator.destroy(self);
|
errdefer allocator.destroy(self);
|
||||||
self.* = .{
|
self.* = .{
|
||||||
.allocator = allocator,
|
.allocator = allocator,
|
||||||
.input_ = ArrayList(u8).init(allocator),
|
.input_ = .empty,
|
||||||
.last_input = ArrayList(u8).init(allocator),
|
.last_input = .empty,
|
||||||
.start_view = editor.view,
|
.start_view = editor.view,
|
||||||
.start_cursor = editor.get_primary().cursor,
|
.start_cursor = editor.get_primary().cursor,
|
||||||
.editor = editor,
|
.editor = editor,
|
||||||
|
|
@ -42,7 +42,7 @@ pub fn create(allocator: Allocator, _: command.Context) !struct { tui.Mode, tui.
|
||||||
if (editor.get_primary().selection) |sel| ret: {
|
if (editor.get_primary().selection) |sel| ret: {
|
||||||
const text = editor.get_selection(sel, self.allocator) catch break :ret;
|
const text = editor.get_selection(sel, self.allocator) catch break :ret;
|
||||||
defer self.allocator.free(text);
|
defer self.allocator.free(text);
|
||||||
try self.input_.appendSlice(text);
|
try self.input_.appendSlice(self.allocator, text);
|
||||||
}
|
}
|
||||||
var mode = try keybind.mode("mini/find", allocator, .{
|
var mode = try keybind.mode("mini/find", allocator, .{
|
||||||
.insert_command = "mini_mode_insert_bytes",
|
.insert_command = "mini_mode_insert_bytes",
|
||||||
|
|
@ -53,8 +53,8 @@ pub fn create(allocator: Allocator, _: command.Context) !struct { tui.Mode, tui.
|
||||||
|
|
||||||
pub fn deinit(self: *Self) void {
|
pub fn deinit(self: *Self) void {
|
||||||
self.commands.deinit();
|
self.commands.deinit();
|
||||||
self.input_.deinit();
|
self.input_.deinit(self.allocator);
|
||||||
self.last_input.deinit();
|
self.last_input.deinit(self.allocator);
|
||||||
self.allocator.destroy(self);
|
self.allocator.destroy(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -74,11 +74,11 @@ pub fn receive(self: *Self, _: tp.pid_ref, m: tp.message) error{Exit}!bool {
|
||||||
fn insert_code_point(self: *Self, c: u32) !void {
|
fn insert_code_point(self: *Self, c: u32) !void {
|
||||||
var buf: [16]u8 = undefined;
|
var buf: [16]u8 = undefined;
|
||||||
const bytes = input.ucs32_to_utf8(&[_]u32{c}, &buf) catch |e| return tp.exit_error(e, @errorReturnTrace());
|
const bytes = input.ucs32_to_utf8(&[_]u32{c}, &buf) catch |e| return tp.exit_error(e, @errorReturnTrace());
|
||||||
try self.input_.appendSlice(buf[0..bytes]);
|
try self.input_.appendSlice(self.allocator, buf[0..bytes]);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn insert_bytes(self: *Self, bytes: []const u8) !void {
|
fn insert_bytes(self: *Self, bytes: []const u8) !void {
|
||||||
try self.input_.appendSlice(bytes);
|
try self.input_.appendSlice(self.allocator, bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn flush_input(self: *Self) !void {
|
fn flush_input(self: *Self) !void {
|
||||||
|
|
@ -86,7 +86,7 @@ fn flush_input(self: *Self) !void {
|
||||||
if (eql(u8, self.input_.items, self.last_input.items))
|
if (eql(u8, self.input_.items, self.last_input.items))
|
||||||
return;
|
return;
|
||||||
self.last_input.clearRetainingCapacity();
|
self.last_input.clearRetainingCapacity();
|
||||||
try self.last_input.appendSlice(self.input_.items);
|
try self.last_input.appendSlice(self.allocator, self.input_.items);
|
||||||
self.editor.find_operation = .goto_next_match;
|
self.editor.find_operation = .goto_next_match;
|
||||||
const primary = self.editor.get_primary();
|
const primary = self.editor.get_primary();
|
||||||
primary.selection = null;
|
primary.selection = null;
|
||||||
|
|
@ -136,7 +136,7 @@ fn find_history_next(self: *Self) void {
|
||||||
fn load_history(self: *Self, pos: usize) void {
|
fn load_history(self: *Self, pos: usize) void {
|
||||||
if (self.editor.find_history) |*history| {
|
if (self.editor.find_history) |*history| {
|
||||||
self.input_.clearRetainingCapacity();
|
self.input_.clearRetainingCapacity();
|
||||||
self.input_.appendSlice(history.items[pos]) catch {};
|
self.input_.appendSlice(self.allocator, history.items[pos]) catch {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -189,7 +189,7 @@ const cmds = struct {
|
||||||
pub const mini_mode_insert_bytes_meta: Meta = .{ .arguments = &.{.string} };
|
pub const mini_mode_insert_bytes_meta: Meta = .{ .arguments = &.{.string} };
|
||||||
|
|
||||||
pub fn mini_mode_delete_backwards(self: *Self, _: Ctx) Result {
|
pub fn mini_mode_delete_backwards(self: *Self, _: Ctx) Result {
|
||||||
self.input_.resize(self.input_.items.len - tui.egc_last(self.input_.items).len) catch {};
|
self.input_.resize(self.allocator, self.input_.items.len - tui.egc_last(self.input_.items).len) catch {};
|
||||||
self.update_mini_mode_text();
|
self.update_mini_mode_text();
|
||||||
}
|
}
|
||||||
pub const mini_mode_delete_backwards_meta: Meta = .{ .description = "Delete backwards" };
|
pub const mini_mode_delete_backwards_meta: Meta = .{ .description = "Delete backwards" };
|
||||||
|
|
|
||||||
|
|
@ -14,18 +14,18 @@ pub fn load_entries(self: *Type) error{ Exit, OutOfMemory }!void {
|
||||||
var project_name_buf: [512]u8 = undefined;
|
var project_name_buf: [512]u8 = undefined;
|
||||||
const project_path = tp.env.get().str("project");
|
const project_path = tp.env.get().str("project");
|
||||||
const project_name = project_manager.abbreviate_home(&project_name_buf, project_path);
|
const project_name = project_manager.abbreviate_home(&project_name_buf, project_path);
|
||||||
try self.file_path.appendSlice(project_name);
|
try self.file_path.appendSlice(self.allocator, project_name);
|
||||||
try self.file_path.append(std.fs.path.sep);
|
try self.file_path.append(self.allocator, std.fs.path.sep);
|
||||||
const editor = tui.get_active_editor() orelse return;
|
const editor = tui.get_active_editor() orelse return;
|
||||||
if (editor.file_path) |old_path|
|
if (editor.file_path) |old_path|
|
||||||
if (std.mem.lastIndexOf(u8, old_path, "/")) |pos|
|
if (std.mem.lastIndexOf(u8, old_path, "/")) |pos|
|
||||||
try self.file_path.appendSlice(old_path[0 .. pos + 1]);
|
try self.file_path.appendSlice(self.allocator, old_path[0 .. pos + 1]);
|
||||||
if (editor.get_primary().selection) |sel| ret: {
|
if (editor.get_primary().selection) |sel| ret: {
|
||||||
const text = editor.get_selection(sel, self.allocator) catch break :ret;
|
const text = editor.get_selection(sel, self.allocator) catch break :ret;
|
||||||
defer self.allocator.free(text);
|
defer self.allocator.free(text);
|
||||||
if (!(text.len > 2 and std.mem.eql(u8, text[0..2], "..")))
|
if (!(text.len > 2 and std.mem.eql(u8, text[0..2], "..")))
|
||||||
self.file_path.clearRetainingCapacity();
|
self.file_path.clearRetainingCapacity();
|
||||||
try self.file_path.appendSlice(text);
|
try self.file_path.appendSlice(self.allocator, text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -34,9 +34,9 @@ pub fn name(_: *Type) []const u8 {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn select(self: *Type) void {
|
pub fn select(self: *Type) void {
|
||||||
var buf = std.ArrayList(u8).init(self.allocator);
|
var buf: std.ArrayList(u8) = .empty;
|
||||||
defer buf.deinit();
|
defer buf.deinit(self.allocator);
|
||||||
const file_path = project_manager.expand_home(&buf, self.file_path.items);
|
const file_path = project_manager.expand_home(self.allocator, &buf, self.file_path.items);
|
||||||
if (root.is_directory(file_path))
|
if (root.is_directory(file_path))
|
||||||
tp.self_pid().send(.{ "cmd", "change_project", .{file_path} }) catch {}
|
tp.self_pid().send(.{ "cmd", "change_project", .{file_path} }) catch {}
|
||||||
else if (file_path.len > 0)
|
else if (file_path.len > 0)
|
||||||
|
|
|
||||||
|
|
@ -11,13 +11,13 @@ pub const create = Type.create;
|
||||||
|
|
||||||
pub fn load_entries(self: *Type) !void {
|
pub fn load_entries(self: *Type) !void {
|
||||||
const editor = tui.get_active_editor() orelse return;
|
const editor = tui.get_active_editor() orelse return;
|
||||||
try self.file_path.appendSlice(editor.file_path orelse "");
|
try self.file_path.appendSlice(self.allocator, editor.file_path orelse "");
|
||||||
if (editor.get_primary().selection) |sel| ret: {
|
if (editor.get_primary().selection) |sel| ret: {
|
||||||
const text = editor.get_selection(sel, self.allocator) catch break :ret;
|
const text = editor.get_selection(sel, self.allocator) catch break :ret;
|
||||||
defer self.allocator.free(text);
|
defer self.allocator.free(text);
|
||||||
if (!(text.len > 2 and std.mem.eql(u8, text[0..2], "..")))
|
if (!(text.len > 2 and std.mem.eql(u8, text[0..2], "..")))
|
||||||
self.file_path.clearRetainingCapacity();
|
self.file_path.clearRetainingCapacity();
|
||||||
try self.file_path.appendSlice(text);
|
try self.file_path.appendSlice(self.allocator, text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ pub fn load_entries(palette: *Type) !usize {
|
||||||
defer palette.allocator.free(buffers);
|
defer palette.allocator.free(buffers);
|
||||||
for (buffers) |buffer| {
|
for (buffers) |buffer| {
|
||||||
const indicator = tui.get_buffer_state_indicator(buffer);
|
const indicator = tui.get_buffer_state_indicator(buffer);
|
||||||
(try palette.entries.addOne()).* = .{
|
(try palette.entries.addOne(palette.allocator)).* = .{
|
||||||
.label = buffer.get_file_path(),
|
.label = buffer.get_file_path(),
|
||||||
.icon = buffer.file_type_icon orelse "",
|
.icon = buffer.file_type_icon orelse "",
|
||||||
.color = buffer.file_type_color,
|
.color = buffer.file_type_color,
|
||||||
|
|
@ -42,15 +42,15 @@ pub fn clear_entries(palette: *Type) void {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_menu_entry(palette: *Type, entry: *Entry, matches: ?[]const usize) !void {
|
pub fn add_menu_entry(palette: *Type, entry: *Entry, matches: ?[]const usize) !void {
|
||||||
var value = std.ArrayList(u8).init(palette.allocator);
|
var value: std.Io.Writer.Allocating = .init(palette.allocator);
|
||||||
defer value.deinit();
|
defer value.deinit();
|
||||||
const writer = value.writer();
|
const writer = &value.writer;
|
||||||
try cbor.writeValue(writer, entry.label);
|
try cbor.writeValue(writer, entry.label);
|
||||||
try cbor.writeValue(writer, entry.icon);
|
try cbor.writeValue(writer, entry.icon);
|
||||||
try cbor.writeValue(writer, entry.color);
|
try cbor.writeValue(writer, entry.color);
|
||||||
try cbor.writeValue(writer, entry.indicator);
|
try cbor.writeValue(writer, entry.indicator);
|
||||||
try cbor.writeValue(writer, matches orelse &[_]usize{});
|
try cbor.writeValue(writer, matches orelse &[_]usize{});
|
||||||
try palette.menu.add_item_with_handler(value.items, select);
|
try palette.menu.add_item_with_handler(value.written(), select);
|
||||||
palette.items += 1;
|
palette.items += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ pub fn load_entries(palette: *Type) !usize {
|
||||||
const hint = hints.get(p.name) orelse "";
|
const hint = hints.get(p.name) orelse "";
|
||||||
longest_description = @max(longest_description, p.meta.description.len);
|
longest_description = @max(longest_description, p.meta.description.len);
|
||||||
longest_total = @max(longest_total, p.meta.description.len + hint.len + 1);
|
longest_total = @max(longest_total, p.meta.description.len + hint.len + 1);
|
||||||
(try palette.entries.addOne()).* = .{
|
(try palette.entries.addOne(palette.allocator)).* = .{
|
||||||
.label = if (p.meta.description.len > 0) p.meta.description else p.name,
|
.label = if (p.meta.description.len > 0) p.meta.description else p.name,
|
||||||
.name = p.name,
|
.name = p.name,
|
||||||
.hint = hint,
|
.hint = hint,
|
||||||
|
|
@ -41,14 +41,14 @@ pub fn load_entries(palette: *Type) !usize {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_menu_entry(palette: *Type, entry: *Entry, matches: ?[]const usize) !void {
|
pub fn add_menu_entry(palette: *Type, entry: *Entry, matches: ?[]const usize) !void {
|
||||||
var value = std.ArrayList(u8).init(palette.allocator);
|
var value: std.Io.Writer.Allocating = .init(palette.allocator);
|
||||||
defer value.deinit();
|
defer value.deinit();
|
||||||
const writer = value.writer();
|
const writer = &value.writer;
|
||||||
try cbor.writeValue(writer, entry.label);
|
try cbor.writeValue(writer, entry.label);
|
||||||
try cbor.writeValue(writer, entry.hint);
|
try cbor.writeValue(writer, entry.hint);
|
||||||
try cbor.writeValue(writer, matches orelse &[_]usize{});
|
try cbor.writeValue(writer, matches orelse &[_]usize{});
|
||||||
try cbor.writeValue(writer, entry.id);
|
try cbor.writeValue(writer, entry.id);
|
||||||
try palette.menu.add_item_with_handler(value.items, select);
|
try palette.menu.add_item_with_handler(value.written(), select);
|
||||||
palette.items += 1;
|
palette.items += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -93,9 +93,10 @@ fn write_state(palette: *Type) !void {
|
||||||
const state_file = try std.fmt.bufPrint(&state_file_buffer, "{s}/{s}", .{ try root.get_state_dir(), "commands" });
|
const state_file = try std.fmt.bufPrint(&state_file_buffer, "{s}/{s}", .{ try root.get_state_dir(), "commands" });
|
||||||
var file = try std.fs.createFileAbsolute(state_file, .{ .truncate = true });
|
var file = try std.fs.createFileAbsolute(state_file, .{ .truncate = true });
|
||||||
defer file.close();
|
defer file.close();
|
||||||
var buffer = std.io.bufferedWriter(file.writer());
|
var buf: [4096]u8 = undefined;
|
||||||
defer buffer.flush() catch {};
|
var file_writer = file.writer(&buf);
|
||||||
const writer = buffer.writer();
|
const writer = &file_writer.interface;
|
||||||
|
defer writer.flush() catch {};
|
||||||
|
|
||||||
for (palette.entries.items) |cmd_| {
|
for (palette.entries.items) |cmd_| {
|
||||||
if (cmd_.used_time == 0) continue;
|
if (cmd_.used_time == 0) continue;
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ pub fn load_entries(palette: *Type) !usize {
|
||||||
while (iter.len > 0) {
|
while (iter.len > 0) {
|
||||||
var cbor_item: []const u8 = undefined;
|
var cbor_item: []const u8 = undefined;
|
||||||
if (!try cbor.matchValue(&iter, cbor.extract_cbor(&cbor_item))) return error.BadCompletion;
|
if (!try cbor.matchValue(&iter, cbor.extract_cbor(&cbor_item))) return error.BadCompletion;
|
||||||
(try palette.entries.addOne()).* = .{ .cbor = cbor_item, .label = undefined, .sort_text = undefined };
|
(try palette.entries.addOne(palette.allocator)).* = .{ .cbor = cbor_item, .label = undefined, .sort_text = undefined };
|
||||||
}
|
}
|
||||||
|
|
||||||
var max_label_len: usize = 0;
|
var max_label_len: usize = 0;
|
||||||
|
|
@ -54,12 +54,12 @@ pub fn clear_entries(palette: *Type) void {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_menu_entry(palette: *Type, entry: *Entry, matches: ?[]const usize) !void {
|
pub fn add_menu_entry(palette: *Type, entry: *Entry, matches: ?[]const usize) !void {
|
||||||
var value = std.ArrayList(u8).init(palette.allocator);
|
var value: std.Io.Writer.Allocating = .init(palette.allocator);
|
||||||
defer value.deinit();
|
defer value.deinit();
|
||||||
const writer = value.writer();
|
const writer = &value.writer;
|
||||||
try writer.writeAll(entry.cbor);
|
try writer.writeAll(entry.cbor);
|
||||||
try cbor.writeValue(writer, matches orelse &[_]usize{});
|
try cbor.writeValue(writer, matches orelse &[_]usize{});
|
||||||
try palette.menu.add_item_with_handler(value.items, select);
|
try palette.menu.add_item_with_handler(value.written(), select);
|
||||||
palette.items += 1;
|
palette.items += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ pub fn Variant(comptime command: []const u8, comptime label_: []const u8, allow_
|
||||||
for (file_type_config.get_all_names()) |file_type_name| {
|
for (file_type_config.get_all_names()) |file_type_name| {
|
||||||
const file_type = try file_type_config.get(file_type_name) orelse unreachable;
|
const file_type = try file_type_config.get(file_type_name) orelse unreachable;
|
||||||
idx += 1;
|
idx += 1;
|
||||||
(try palette.entries.addOne()).* = .{
|
(try palette.entries.addOne(palette.allocator)).* = .{
|
||||||
.label = file_type.description orelse file_type_config.default.description,
|
.label = file_type.description orelse file_type_config.default.description,
|
||||||
.name = file_type.name,
|
.name = file_type.name,
|
||||||
.icon = file_type.icon orelse file_type_config.default.icon,
|
.icon = file_type.icon orelse file_type_config.default.icon,
|
||||||
|
|
@ -59,15 +59,15 @@ pub fn Variant(comptime command: []const u8, comptime label_: []const u8, allow_
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_menu_entry(palette: *Type, entry: *Entry, matches: ?[]const usize) !void {
|
pub fn add_menu_entry(palette: *Type, entry: *Entry, matches: ?[]const usize) !void {
|
||||||
var value = std.ArrayList(u8).init(palette.allocator);
|
var value: std.Io.Writer.Allocating = .init(palette.allocator);
|
||||||
defer value.deinit();
|
defer value.deinit();
|
||||||
const writer = value.writer();
|
const writer = &value.writer;
|
||||||
try cbor.writeValue(writer, entry.label);
|
try cbor.writeValue(writer, entry.label);
|
||||||
try cbor.writeValue(writer, entry.icon);
|
try cbor.writeValue(writer, entry.icon);
|
||||||
try cbor.writeValue(writer, entry.color);
|
try cbor.writeValue(writer, entry.color);
|
||||||
try cbor.writeValue(writer, entry.name);
|
try cbor.writeValue(writer, entry.name);
|
||||||
try cbor.writeValue(writer, matches orelse &[_]usize{});
|
try cbor.writeValue(writer, matches orelse &[_]usize{});
|
||||||
try palette.menu.add_item_with_handler(value.items, select);
|
try palette.menu.add_item_with_handler(value.written(), select);
|
||||||
palette.items += 1;
|
palette.items += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ pub fn load_entries(palette: *Type) !usize {
|
||||||
defer palette.allocator.free(fontfaces);
|
defer palette.allocator.free(fontfaces);
|
||||||
for (fontfaces) |fontface| {
|
for (fontfaces) |fontface| {
|
||||||
idx += 1;
|
idx += 1;
|
||||||
(try palette.entries.addOne()).* = .{ .label = fontface };
|
(try palette.entries.addOne(palette.allocator)).* = .{ .label = fontface };
|
||||||
if (previous_fontface) |previous_fontface_| if (std.mem.eql(u8, fontface, previous_fontface_)) {
|
if (previous_fontface) |previous_fontface_| if (std.mem.eql(u8, fontface, previous_fontface_)) {
|
||||||
palette.initial_selected = idx;
|
palette.initial_selected = idx;
|
||||||
};
|
};
|
||||||
|
|
@ -47,12 +47,12 @@ pub fn load_entries(palette: *Type) !usize {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_menu_entry(palette: *Type, entry: *Entry, matches: ?[]const usize) !void {
|
pub fn add_menu_entry(palette: *Type, entry: *Entry, matches: ?[]const usize) !void {
|
||||||
var value = std.ArrayList(u8).init(palette.allocator);
|
var value: std.Io.Writer.Allocating = .init(palette.allocator);
|
||||||
defer value.deinit();
|
defer value.deinit();
|
||||||
const writer = value.writer();
|
const writer = &value.writer;
|
||||||
try cbor.writeValue(writer, entry.label);
|
try cbor.writeValue(writer, entry.label);
|
||||||
try cbor.writeValue(writer, matches orelse &[_]usize{});
|
try cbor.writeValue(writer, matches orelse &[_]usize{});
|
||||||
try palette.menu.add_item_with_handler(value.items, select);
|
try palette.menu.add_item_with_handler(value.written(), select);
|
||||||
palette.items += 1;
|
palette.items += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,9 @@ pub fn load_entries(palette: *Type) !usize {
|
||||||
const hints = if (tui.input_mode()) |m| m.keybind_hints else @panic("no keybind hints");
|
const hints = if (tui.input_mode()) |m| m.keybind_hints else @panic("no keybind hints");
|
||||||
var longest_hint: usize = 0;
|
var longest_hint: usize = 0;
|
||||||
for (command.commands.items) |cmd_| if (cmd_) |p| {
|
for (command.commands.items) |cmd_| if (cmd_) |p| {
|
||||||
var label_ = std.ArrayList(u8).init(palette.allocator);
|
var label_: std.Io.Writer.Allocating = .init(palette.allocator);
|
||||||
const writer = label_.writer();
|
defer label_.deinit();
|
||||||
|
const writer = &label_.writer;
|
||||||
try writer.writeAll(p.name);
|
try writer.writeAll(p.name);
|
||||||
if (p.meta.description.len > 0) try writer.print(" ({s})", .{p.meta.description});
|
if (p.meta.description.len > 0) try writer.print(" ({s})", .{p.meta.description});
|
||||||
if (p.meta.arguments.len > 0) {
|
if (p.meta.arguments.len > 0) {
|
||||||
|
|
@ -47,7 +48,7 @@ pub fn load_entries(palette: *Type) !usize {
|
||||||
const hint = hints.get(p.name) orelse "";
|
const hint = hints.get(p.name) orelse "";
|
||||||
longest_hint = @max(longest_hint, hint.len);
|
longest_hint = @max(longest_hint, hint.len);
|
||||||
|
|
||||||
(try palette.entries.addOne()).* = .{
|
(try palette.entries.addOne(palette.allocator)).* = .{
|
||||||
.label = try label_.toOwnedSlice(),
|
.label = try label_.toOwnedSlice(),
|
||||||
.hint = hint,
|
.hint = hint,
|
||||||
.id = p.id,
|
.id = p.id,
|
||||||
|
|
@ -57,14 +58,14 @@ pub fn load_entries(palette: *Type) !usize {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_menu_entry(palette: *Type, entry: *Entry, matches: ?[]const usize) !void {
|
pub fn add_menu_entry(palette: *Type, entry: *Entry, matches: ?[]const usize) !void {
|
||||||
var value = std.ArrayList(u8).init(palette.allocator);
|
var value: std.Io.Writer.Allocating = .init(palette.allocator);
|
||||||
defer value.deinit();
|
defer value.deinit();
|
||||||
const writer = value.writer();
|
const writer = &value.writer;
|
||||||
try cbor.writeValue(writer, entry.label);
|
try cbor.writeValue(writer, entry.label);
|
||||||
try cbor.writeValue(writer, entry.hint);
|
try cbor.writeValue(writer, entry.hint);
|
||||||
try cbor.writeValue(writer, matches orelse &[_]usize{});
|
try cbor.writeValue(writer, matches orelse &[_]usize{});
|
||||||
try cbor.writeValue(writer, entry.id);
|
try cbor.writeValue(writer, entry.id);
|
||||||
try palette.menu.add_item_with_handler(value.items, select);
|
try palette.menu.add_item_with_handler(value.written(), select);
|
||||||
palette.items += 1;
|
palette.items += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -139,15 +139,15 @@ fn add_item(
|
||||||
indicator: []const u8,
|
indicator: []const u8,
|
||||||
matches: ?[]const u8,
|
matches: ?[]const u8,
|
||||||
) !void {
|
) !void {
|
||||||
var label = std.ArrayList(u8).init(self.allocator);
|
var label: std.Io.Writer.Allocating = .init(self.allocator);
|
||||||
defer label.deinit();
|
defer label.deinit();
|
||||||
const writer = label.writer();
|
const writer = &label.writer;
|
||||||
try cbor.writeValue(writer, file_name);
|
try cbor.writeValue(writer, file_name);
|
||||||
try cbor.writeValue(writer, file_icon);
|
try cbor.writeValue(writer, file_icon);
|
||||||
try cbor.writeValue(writer, file_color);
|
try cbor.writeValue(writer, file_color);
|
||||||
try cbor.writeValue(writer, indicator);
|
try cbor.writeValue(writer, indicator);
|
||||||
if (matches) |cb| _ = try writer.write(cb) else try cbor.writeValue(writer, &[_]usize{});
|
if (matches) |cb| _ = try writer.write(cb) else try cbor.writeValue(writer, &[_]usize{});
|
||||||
try self.menu.add_item_with_handler(label.items, menu_action_open_file);
|
try self.menu.add_item_with_handler(label.written(), menu_action_open_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn receive_project_manager(self: *Self, _: tp.pid_ref, m: tp.message) MessageFilter.Error!bool {
|
fn receive_project_manager(self: *Self, _: tp.pid_ref, m: tp.message) MessageFilter.Error!bool {
|
||||||
|
|
@ -259,13 +259,13 @@ fn delete_code_point(self: *Self) !void {
|
||||||
fn insert_code_point(self: *Self, c: u32) !void {
|
fn insert_code_point(self: *Self, c: u32) !void {
|
||||||
var buf: [6]u8 = undefined;
|
var buf: [6]u8 = undefined;
|
||||||
const bytes = try input.ucs32_to_utf8(&[_]u32{c}, &buf);
|
const bytes = try input.ucs32_to_utf8(&[_]u32{c}, &buf);
|
||||||
try self.inputbox.text.appendSlice(buf[0..bytes]);
|
try self.inputbox.text.appendSlice(self.allocator, buf[0..bytes]);
|
||||||
self.inputbox.cursor = tui.egc_chunk_width(self.inputbox.text.items, 0, 8);
|
self.inputbox.cursor = tui.egc_chunk_width(self.inputbox.text.items, 0, 8);
|
||||||
return self.start_query();
|
return self.start_query();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn insert_bytes(self: *Self, bytes: []const u8) !void {
|
fn insert_bytes(self: *Self, bytes: []const u8) !void {
|
||||||
try self.inputbox.text.appendSlice(bytes);
|
try self.inputbox.text.appendSlice(self.allocator, bytes);
|
||||||
self.inputbox.cursor = tui.egc_chunk_width(self.inputbox.text.items, 0, 8);
|
self.inputbox.cursor = tui.egc_chunk_width(self.inputbox.text.items, 0, 8);
|
||||||
return self.start_query();
|
return self.start_query();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ pub fn load_entries_with_args(palette: *Type, ctx: command.Context) !usize {
|
||||||
return error.InvalidMessageField;
|
return error.InvalidMessageField;
|
||||||
if (!try cbor.matchValue(&iter, cbor.extract(&open)))
|
if (!try cbor.matchValue(&iter, cbor.extract(&open)))
|
||||||
return error.InvalidMessageField;
|
return error.InvalidMessageField;
|
||||||
(try palette.entries.addOne()).* = .{ .label = try palette.allocator.dupe(u8, name_), .open = open };
|
(try palette.entries.addOne(palette.allocator)).* = .{ .label = try palette.allocator.dupe(u8, name_), .open = open };
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
@ -53,13 +53,13 @@ pub fn clear_entries(palette: *Type) void {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_menu_entry(palette: *Type, entry: *Entry, matches: ?[]const usize) !void {
|
pub fn add_menu_entry(palette: *Type, entry: *Entry, matches: ?[]const usize) !void {
|
||||||
var value = std.ArrayList(u8).init(palette.allocator);
|
var value: std.Io.Writer.Allocating = .init(palette.allocator);
|
||||||
defer value.deinit();
|
defer value.deinit();
|
||||||
const writer = value.writer();
|
const writer = &value.writer;
|
||||||
try cbor.writeValue(writer, entry.label);
|
try cbor.writeValue(writer, entry.label);
|
||||||
try cbor.writeValue(writer, if (entry.open) "-" else "");
|
try cbor.writeValue(writer, if (entry.open) "-" else "");
|
||||||
try cbor.writeValue(writer, matches orelse &[_]usize{});
|
try cbor.writeValue(writer, matches orelse &[_]usize{});
|
||||||
try palette.menu.add_item_with_handler(value.items, select);
|
try palette.menu.add_item_with_handler(value.written(), select);
|
||||||
palette.items += 1;
|
palette.items += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -78,7 +78,7 @@ pub fn Create(options: type) type {
|
||||||
.icon = if (@hasDecl(options, "icon")) options.icon else null,
|
.icon = if (@hasDecl(options, "icon")) options.icon else null,
|
||||||
}))).dynamic_cast(InputBox.State(*Self)) orelse unreachable,
|
}))).dynamic_cast(InputBox.State(*Self)) orelse unreachable,
|
||||||
.view_rows = get_view_rows(tui.screen()),
|
.view_rows = get_view_rows(tui.screen()),
|
||||||
.entries = std.ArrayList(Entry).init(allocator),
|
.entries = .empty,
|
||||||
};
|
};
|
||||||
if (self.menu.scrollbar) |scrollbar| scrollbar.style_factory = scrollbar_style;
|
if (self.menu.scrollbar) |scrollbar| scrollbar.style_factory = scrollbar_style;
|
||||||
self.longest_hint = if (@hasDecl(options, "load_entries_with_args"))
|
self.longest_hint = if (@hasDecl(options, "load_entries_with_args"))
|
||||||
|
|
@ -103,7 +103,7 @@ pub fn Create(options: type) type {
|
||||||
self.commands.deinit();
|
self.commands.deinit();
|
||||||
if (@hasDecl(options, "deinit"))
|
if (@hasDecl(options, "deinit"))
|
||||||
options.deinit(self);
|
options.deinit(self);
|
||||||
self.entries.deinit();
|
self.entries.deinit(self.allocator);
|
||||||
tui.message_filters().remove_ptr(self);
|
tui.message_filters().remove_ptr(self);
|
||||||
if (tui.mainview()) |mv| {
|
if (tui.mainview()) |mv| {
|
||||||
mv.floating_views.remove(self.menu.container_widget);
|
mv.floating_views.remove(self.menu.container_widget);
|
||||||
|
|
@ -270,7 +270,7 @@ pub fn Create(options: type) type {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn query_entries(self: *Self, query: []const u8) error{OutOfMemory}!usize {
|
fn query_entries(self: *Self, query: []const u8) error{ OutOfMemory, WriteFailed }!usize {
|
||||||
var searcher = try fuzzig.Ascii.init(
|
var searcher = try fuzzig.Ascii.init(
|
||||||
self.allocator,
|
self.allocator,
|
||||||
self.longest, // haystack max size
|
self.longest, // haystack max size
|
||||||
|
|
@ -285,12 +285,12 @@ pub fn Create(options: type) type {
|
||||||
matches: []const usize,
|
matches: []const usize,
|
||||||
};
|
};
|
||||||
|
|
||||||
var matches = std.ArrayList(Match).init(self.allocator);
|
var matches: std.ArrayList(Match) = .empty;
|
||||||
|
|
||||||
for (self.entries.items) |*entry| {
|
for (self.entries.items) |*entry| {
|
||||||
const match = searcher.scoreMatches(entry.label, query);
|
const match = searcher.scoreMatches(entry.label, query);
|
||||||
if (match.score) |score|
|
if (match.score) |score|
|
||||||
(try matches.addOne()).* = .{
|
(try matches.addOne(self.allocator)).* = .{
|
||||||
.entry = entry,
|
.entry = entry,
|
||||||
.score = score,
|
.score = score,
|
||||||
.matches = try self.allocator.dupe(usize, match.matches),
|
.matches = try self.allocator.dupe(usize, match.matches),
|
||||||
|
|
@ -343,14 +343,14 @@ pub fn Create(options: type) type {
|
||||||
fn insert_code_point(self: *Self, c: u32) !void {
|
fn insert_code_point(self: *Self, c: u32) !void {
|
||||||
var buf: [6]u8 = undefined;
|
var buf: [6]u8 = undefined;
|
||||||
const bytes = try input.ucs32_to_utf8(&[_]u32{c}, &buf);
|
const bytes = try input.ucs32_to_utf8(&[_]u32{c}, &buf);
|
||||||
try self.inputbox.text.appendSlice(buf[0..bytes]);
|
try self.inputbox.text.appendSlice(self.allocator, buf[0..bytes]);
|
||||||
self.inputbox.cursor = tui.egc_chunk_width(self.inputbox.text.items, 0, 8);
|
self.inputbox.cursor = tui.egc_chunk_width(self.inputbox.text.items, 0, 8);
|
||||||
self.view_pos = 0;
|
self.view_pos = 0;
|
||||||
return self.start_query(0);
|
return self.start_query(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn insert_bytes(self: *Self, bytes: []const u8) !void {
|
fn insert_bytes(self: *Self, bytes: []const u8) !void {
|
||||||
try self.inputbox.text.appendSlice(bytes);
|
try self.inputbox.text.appendSlice(self.allocator, bytes);
|
||||||
self.inputbox.cursor = tui.egc_chunk_width(self.inputbox.text.items, 0, 8);
|
self.inputbox.cursor = tui.egc_chunk_width(self.inputbox.text.items, 0, 8);
|
||||||
self.view_pos = 0;
|
self.view_pos = 0;
|
||||||
return self.start_query(0);
|
return self.start_query(0);
|
||||||
|
|
|
||||||
|
|
@ -30,11 +30,11 @@ pub fn load_entries(palette: *Type) !usize {
|
||||||
while (len > 0) : (len -= 1) {
|
while (len > 0) : (len -= 1) {
|
||||||
var task: []const u8 = undefined;
|
var task: []const u8 = undefined;
|
||||||
if (try cbor.matchValue(&iter, cbor.extract(&task))) {
|
if (try cbor.matchValue(&iter, cbor.extract(&task))) {
|
||||||
(try palette.entries.addOne()).* = .{ .label = try palette.allocator.dupe(u8, task) };
|
(try palette.entries.addOne(palette.allocator)).* = .{ .label = try palette.allocator.dupe(u8, task) };
|
||||||
} else return error.InvalidTaskMessageField;
|
} else return error.InvalidTaskMessageField;
|
||||||
}
|
}
|
||||||
(try palette.entries.addOne()).* = .{ .label = "", .command = "add_task" };
|
(try palette.entries.addOne(palette.allocator)).* = .{ .label = "", .command = "add_task" };
|
||||||
(try palette.entries.addOne()).* = .{ .label = "", .command = "palette_menu_delete_item" };
|
(try palette.entries.addOne(palette.allocator)).* = .{ .label = "", .command = "palette_menu_delete_item" };
|
||||||
return if (palette.entries.items.len == 0) label.len else blk: {
|
return if (palette.entries.items.len == 0) label.len else blk: {
|
||||||
var longest: usize = 0;
|
var longest: usize = 0;
|
||||||
for (palette.entries.items) |item| longest = @max(longest, item.label.len);
|
for (palette.entries.items) |item| longest = @max(longest, item.label.len);
|
||||||
|
|
@ -49,12 +49,12 @@ pub fn clear_entries(palette: *Type) void {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_menu_entry(palette: *Type, entry: *Entry, matches: ?[]const usize) !void {
|
pub fn add_menu_entry(palette: *Type, entry: *Entry, matches: ?[]const usize) !void {
|
||||||
var value = std.ArrayList(u8).init(palette.allocator);
|
var value: std.Io.Writer.Allocating = .init(palette.allocator);
|
||||||
defer value.deinit();
|
defer value.deinit();
|
||||||
const writer = value.writer();
|
const writer = &value.writer;
|
||||||
try cbor.writeValue(writer, entry);
|
try cbor.writeValue(writer, entry);
|
||||||
try cbor.writeValue(writer, matches orelse &[_]usize{});
|
try cbor.writeValue(writer, matches orelse &[_]usize{});
|
||||||
try palette.menu.add_item_with_handler(value.items, select);
|
try palette.menu.add_item_with_handler(value.written(), select);
|
||||||
palette.items += 1;
|
palette.items += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ pub fn load_entries(palette: *Type) !usize {
|
||||||
previous_theme = tui.theme().name;
|
previous_theme = tui.theme().name;
|
||||||
for (Widget.themes) |theme| {
|
for (Widget.themes) |theme| {
|
||||||
idx += 1;
|
idx += 1;
|
||||||
(try palette.entries.addOne()).* = .{
|
(try palette.entries.addOne(palette.allocator)).* = .{
|
||||||
.label = theme.description,
|
.label = theme.description,
|
||||||
.name = theme.name,
|
.name = theme.name,
|
||||||
};
|
};
|
||||||
|
|
@ -43,13 +43,13 @@ pub fn load_entries(palette: *Type) !usize {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_menu_entry(palette: *Type, entry: *Entry, matches: ?[]const usize) !void {
|
pub fn add_menu_entry(palette: *Type, entry: *Entry, matches: ?[]const usize) !void {
|
||||||
var value = std.ArrayList(u8).init(palette.allocator);
|
var value: std.Io.Writer.Allocating = .init(palette.allocator);
|
||||||
defer value.deinit();
|
defer value.deinit();
|
||||||
const writer = value.writer();
|
const writer = &value.writer;
|
||||||
try cbor.writeValue(writer, entry.label);
|
try cbor.writeValue(writer, entry.label);
|
||||||
try cbor.writeValue(writer, entry.name);
|
try cbor.writeValue(writer, entry.name);
|
||||||
try cbor.writeValue(writer, matches orelse &[_]usize{});
|
try cbor.writeValue(writer, matches orelse &[_]usize{});
|
||||||
try palette.menu.add_item_with_handler(value.items, select);
|
try palette.menu.add_item_with_handler(value.written(), select);
|
||||||
palette.items += 1;
|
palette.items += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ pub fn layout(_: *Self) Widget.Layout {
|
||||||
writer.print(" ", .{}) catch {};
|
writer.print(" ", .{}) catch {};
|
||||||
if (keybind.current_integer_argument()) |integer_argument|
|
if (keybind.current_integer_argument()) |integer_argument|
|
||||||
writer.print("{}", .{integer_argument}) catch {};
|
writer.print("{}", .{integer_argument}) catch {};
|
||||||
writer.print("{} ", .{keybind.current_key_event_sequence_fmt()}) catch {};
|
writer.print("{f} ", .{keybind.current_key_event_sequence_fmt()}) catch {};
|
||||||
const len = fbs.getWritten().len;
|
const len = fbs.getWritten().len;
|
||||||
return .{ .static = if (len > 0) len else 0 };
|
return .{ .static = if (len > 0) len else 0 };
|
||||||
}
|
}
|
||||||
|
|
@ -48,6 +48,6 @@ pub fn render(self: *Self, theme: *const Widget.Theme) bool {
|
||||||
_ = self.plane.print(" ", .{}) catch {};
|
_ = self.plane.print(" ", .{}) catch {};
|
||||||
if (keybind.current_integer_argument()) |integer_argument|
|
if (keybind.current_integer_argument()) |integer_argument|
|
||||||
_ = self.plane.print("{}", .{integer_argument}) catch {};
|
_ = self.plane.print("{}", .{integer_argument}) catch {};
|
||||||
_ = self.plane.print("{} ", .{keybind.current_key_event_sequence_fmt()}) catch {};
|
_ = self.plane.print("{f} ", .{keybind.current_key_event_sequence_fmt()}) catch {};
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ const tui = @import("../tui.zig");
|
||||||
const logview = @import("../logview.zig");
|
const logview = @import("../logview.zig");
|
||||||
|
|
||||||
plane: Plane,
|
plane: Plane,
|
||||||
msg: std.ArrayList(u8),
|
msg: std.Io.Writer.Allocating,
|
||||||
msg_counter: usize = 0,
|
msg_counter: usize = 0,
|
||||||
clear_timer: ?tp.Cancellable = null,
|
clear_timer: ?tp.Cancellable = null,
|
||||||
level: Level = .info,
|
level: Level = .info,
|
||||||
|
|
@ -31,7 +31,7 @@ pub fn create(allocator: std.mem.Allocator, parent: Plane, event_handler: ?Event
|
||||||
errdefer allocator.destroy(self);
|
errdefer allocator.destroy(self);
|
||||||
self.* = .{
|
self.* = .{
|
||||||
.plane = try Plane.init(&(Widget.Box{}).opts(@typeName(Self)), parent),
|
.plane = try Plane.init(&(Widget.Box{}).opts(@typeName(Self)), parent),
|
||||||
.msg = std.ArrayList(u8).init(allocator),
|
.msg = .init(allocator),
|
||||||
.on_event = event_handler,
|
.on_event = event_handler,
|
||||||
};
|
};
|
||||||
logview.init(allocator);
|
logview.init(allocator);
|
||||||
|
|
@ -63,7 +63,7 @@ pub fn receive(self: *Self, from: tp.pid_ref, m: tp.message) error{Exit}!bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn layout(self: *Self) Widget.Layout {
|
pub fn layout(self: *Self) Widget.Layout {
|
||||||
return .{ .static = if (self.msg.items.len > 0) self.msg.items.len + 2 else 1 };
|
return .{ .static = if (self.msg.written().len > 0) self.msg.written().len + 2 else 1 };
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn render(self: *Self, theme: *const Widget.Theme) bool {
|
pub fn render(self: *Self, theme: *const Widget.Theme) bool {
|
||||||
|
|
@ -77,7 +77,7 @@ pub fn render(self: *Self, theme: *const Widget.Theme) bool {
|
||||||
self.plane.fill(" ");
|
self.plane.fill(" ");
|
||||||
self.plane.home();
|
self.plane.home();
|
||||||
self.plane.set_style(if (self.level == .err) style_error else style_info);
|
self.plane.set_style(if (self.level == .err) style_error else style_info);
|
||||||
_ = self.plane.print(" {s} ", .{self.msg.items}) catch {};
|
_ = self.plane.print(" {s} ", .{self.msg.written()}) catch {};
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -113,9 +113,9 @@ fn process_log(self: *Self, m: tp.message) MessageFilter.Error!void {
|
||||||
try self.set(msg, .err);
|
try self.set(msg, .err);
|
||||||
} else if (try cbor.match(m.buf, .{ "log", tp.extract(&src), tp.more })) {
|
} else if (try cbor.match(m.buf, .{ "log", tp.extract(&src), tp.more })) {
|
||||||
self.level = .err;
|
self.level = .err;
|
||||||
var s = std.json.writeStream(self.msg.writer(), .{});
|
var s: std.json.Stringify = .{ .writer = &self.msg.writer };
|
||||||
var iter: []const u8 = m.buf;
|
var iter: []const u8 = m.buf;
|
||||||
try @import("cbor").JsonStream(@TypeOf(self.msg)).jsonWriteValue(&s, &iter);
|
try @import("cbor").JsonWriter.jsonWriteValue(&s, &iter);
|
||||||
Widget.need_render();
|
Widget.need_render();
|
||||||
try self.update_clear_timer();
|
try self.update_clear_timer();
|
||||||
}
|
}
|
||||||
|
|
@ -143,7 +143,7 @@ fn set(self: *Self, msg: []const u8, level: Level) !void {
|
||||||
self.msg.clearRetainingCapacity();
|
self.msg.clearRetainingCapacity();
|
||||||
var iter = std.mem.splitScalar(u8, msg, '\n');
|
var iter = std.mem.splitScalar(u8, msg, '\n');
|
||||||
const line1 = iter.next() orelse msg;
|
const line1 = iter.next() orelse msg;
|
||||||
try self.msg.appendSlice(line1);
|
try self.msg.writer.writeAll(line1);
|
||||||
self.level = level;
|
self.level = level;
|
||||||
Widget.need_render();
|
Widget.need_render();
|
||||||
try self.update_clear_timer();
|
try self.update_clear_timer();
|
||||||
|
|
|
||||||
|
|
@ -269,7 +269,7 @@ pub const TabBar = struct {
|
||||||
tp.self_pid().send(.{ "cmd", "navigate", .{ .file = buffer.get_file_path() } }) catch {};
|
tp.self_pid().send(.{ "cmd", "navigate", .{ .file = buffer.get_file_path() } }) catch {};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write_state(self: *const Self, writer: Buffer.MetaWriter) error{OutOfMemory}!void {
|
pub fn write_state(self: *const Self, writer: *std.Io.Writer) error{WriteFailed}!void {
|
||||||
try cbor.writeArrayHeader(writer, self.tabs.len);
|
try cbor.writeArrayHeader(writer, self.tabs.len);
|
||||||
for (self.tabs) |tab| try cbor.writeValue(writer, ref_to_name(tab.buffer_ref));
|
for (self.tabs) |tab| try cbor.writeValue(writer, ref_to_name(tab.buffer_ref));
|
||||||
}
|
}
|
||||||
|
|
@ -498,7 +498,7 @@ const Tab = struct {
|
||||||
return basename;
|
return basename;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_state(self: *const @This(), writer: Buffer.MetaWriter) error{OutOfMemory}!void {
|
fn write_state(self: *const @This(), writer: *std.Io.Writer) error{OutOfMemory}!void {
|
||||||
try cbor.writeArrayHeader(writer, 9);
|
try cbor.writeArrayHeader(writer, 9);
|
||||||
try cbor.writeValue(writer, self.get_file_path());
|
try cbor.writeValue(writer, self.get_file_path());
|
||||||
try cbor.writeValue(writer, self.file_exists);
|
try cbor.writeValue(writer, self.file_exists);
|
||||||
|
|
|
||||||
|
|
@ -979,11 +979,11 @@ const cmds = struct {
|
||||||
pub fn run_task(self: *Self, ctx: Ctx) Result {
|
pub fn run_task(self: *Self, ctx: Ctx) Result {
|
||||||
var task: []const u8 = undefined;
|
var task: []const u8 = undefined;
|
||||||
if (try ctx.args.match(.{tp.extract(&task)})) {
|
if (try ctx.args.match(.{tp.extract(&task)})) {
|
||||||
var buffer_name = std.ArrayList(u8).init(self.allocator);
|
var buffer_name: std.Io.Writer.Allocating = .init(self.allocator);
|
||||||
defer buffer_name.deinit();
|
defer buffer_name.deinit();
|
||||||
buffer_name.writer().print("*{s}*", .{task}) catch {};
|
buffer_name.writer.print("*{s}*", .{task}) catch {};
|
||||||
call_add_task(task);
|
call_add_task(task);
|
||||||
tp.self_pid().send(.{ "cmd", "create_scratch_buffer", .{ buffer_name.items, "", "conf" } }) catch |e| self.logger.err("task", e);
|
tp.self_pid().send(.{ "cmd", "create_scratch_buffer", .{ buffer_name.written(), "", "conf" } }) catch |e| self.logger.err("task", e);
|
||||||
tp.self_pid().send(.{ "cmd", "shell_execute_stream", .{task} }) catch |e| self.logger.err("task", e);
|
tp.self_pid().send(.{ "cmd", "shell_execute_stream", .{task} }) catch |e| self.logger.err("task", e);
|
||||||
} else {
|
} else {
|
||||||
return self.enter_overlay_mode(@import("mode/overlay/task_palette.zig").Type);
|
return self.enter_overlay_mode(@import("mode/overlay/task_palette.zig").Type);
|
||||||
|
|
@ -1134,33 +1134,33 @@ const cmds = struct {
|
||||||
return tp.exit_error(error.InvalidRunAsyncArgument, null);
|
return tp.exit_error(error.InvalidRunAsyncArgument, null);
|
||||||
len -= 1;
|
len -= 1;
|
||||||
|
|
||||||
var args = std.ArrayList([]const u8).init(self.allocator);
|
var args: std.ArrayList([]const u8) = .empty;
|
||||||
defer args.deinit();
|
defer args.deinit(self.allocator);
|
||||||
while (len > 0) : (len -= 1) {
|
while (len > 0) : (len -= 1) {
|
||||||
var arg: []const u8 = undefined;
|
var arg: []const u8 = undefined;
|
||||||
if (try cbor.matchValue(&iter, cbor.extract_cbor(&arg))) {
|
if (try cbor.matchValue(&iter, cbor.extract_cbor(&arg))) {
|
||||||
try args.append(arg);
|
try args.append(self.allocator, arg);
|
||||||
} else return tp.exit_error(error.InvalidRunAsyncArgument, null);
|
} else return tp.exit_error(error.InvalidRunAsyncArgument, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
var args_cb = std.ArrayList(u8).init(self.allocator);
|
var args_cb: std.Io.Writer.Allocating = .init(self.allocator);
|
||||||
defer args_cb.deinit();
|
defer args_cb.deinit();
|
||||||
{
|
{
|
||||||
const writer = args_cb.writer();
|
const writer = &args_cb.writer;
|
||||||
try cbor.writeArrayHeader(writer, args.items.len);
|
try cbor.writeArrayHeader(writer, args.items.len);
|
||||||
for (args.items) |arg| try writer.writeAll(arg);
|
for (args.items) |arg| try writer.writeAll(arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
var msg_cb = std.ArrayList(u8).init(self.allocator);
|
var msg_cb: std.Io.Writer.Allocating = .init(self.allocator);
|
||||||
defer msg_cb.deinit();
|
defer msg_cb.deinit();
|
||||||
{
|
{
|
||||||
const writer = msg_cb.writer();
|
const writer = &msg_cb.writer;
|
||||||
try cbor.writeArrayHeader(writer, 3);
|
try cbor.writeArrayHeader(writer, 3);
|
||||||
try cbor.writeValue(writer, "cmd");
|
try cbor.writeValue(writer, "cmd");
|
||||||
try cbor.writeValue(writer, cmd);
|
try cbor.writeValue(writer, cmd);
|
||||||
try writer.writeAll(args_cb.items);
|
try writer.writeAll(args_cb.written());
|
||||||
}
|
}
|
||||||
try tp.self_pid().send_raw(.{ .buf = msg_cb.items });
|
try tp.self_pid().send_raw(.{ .buf = msg_cb.written() });
|
||||||
}
|
}
|
||||||
pub const run_async_meta: Meta = .{};
|
pub const run_async_meta: Meta = .{};
|
||||||
|
|
||||||
|
|
@ -1612,12 +1612,13 @@ fn get_or_create_theme_file(self: *Self, allocator: std.mem.Allocator) ![]const
|
||||||
if (root.read_theme(allocator, theme_name)) |content| {
|
if (root.read_theme(allocator, theme_name)) |content| {
|
||||||
allocator.free(content);
|
allocator.free(content);
|
||||||
} else {
|
} else {
|
||||||
var buf = std.ArrayList(u8).init(self.allocator);
|
var buf: std.Io.Writer.Allocating = .init(self.allocator);
|
||||||
defer buf.deinit();
|
defer buf.deinit();
|
||||||
try std.json.stringify(self.theme_, .{ .whitespace = .indent_2 }, buf.writer());
|
var s: std.json.Stringify = .{ .writer = &buf.writer, .options = .{ .whitespace = .indent_2 } };
|
||||||
|
try s.write(self.theme_);
|
||||||
try root.write_theme(
|
try root.write_theme(
|
||||||
theme_name,
|
theme_name,
|
||||||
buf.items,
|
buf.written(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return try root.get_theme_file_name(theme_name);
|
return try root.get_theme_file_name(theme_name);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue