From 4368ac677e1c24ef20b3c7f52921bd8229c04623 Mon Sep 17 00:00:00 2001 From: Kalle Carlbark Date: Tue, 20 Aug 2024 21:54:33 +0200 Subject: [PATCH] wip: Apparently we need to clear before printing to get text aligned with image --- src/macos.zig | 7 ++++--- src/main.zig | 13 +++++-------- src/root.zig | 2 +- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/macos.zig b/src/macos.zig index e0fcacc..b451716 100644 --- a/src/macos.zig +++ b/src/macos.zig @@ -34,7 +34,7 @@ pub fn macos_version(allocator: std.mem.Allocator) ![]const u8 { const koko = info.msgSend(NSOperatingSystemVersion, "operatingSystemVersion", .{}); - const buf = try std.fmt.allocPrint(allocator, "\n\t\t\tOS: {s} {d}.{d}.{d}", .{ version_to_name(koko), koko.major, koko.minor, koko.patch }); + const buf = try std.fmt.allocPrint(allocator, "\t\t\tOS: {s} {d}.{d}.{d}\n", .{ version_to_name(koko), koko.major, koko.minor, koko.patch }); return buf; } @@ -46,9 +46,10 @@ pub fn macos_kernel_version(allocator: std.mem.Allocator) ![]const u8 { return error.UnameFailed; } - const kaka = std.mem.span(@ptrCast(name.sysname)); + const sysname = std.mem.sliceTo(name.sysname[0..], 0); + const version = std.mem.sliceTo(name.release[0..], 0); - const buf = try std.fmt.allocPrint(allocator, "\n\t\t\tKernel: {s} {s}", .{ kaka, name.version }); + const buf = try std.fmt.allocPrint(allocator, "\t\t\tKernel: {s} {s}\n", .{ sysname, version }); return buf; } diff --git a/src/main.zig b/src/main.zig index 9ca39ca..0dac812 100644 --- a/src/main.zig +++ b/src/main.zig @@ -36,7 +36,7 @@ pub fn main() !void { const kernel = try macos.macos_kernel_version(allocator); defer allocator.free(kernel); - // try tty.anyWriter().writeAll(vaxis.ctlseqs.kitty_graphics_clear); + try tty.anyWriter().writeAll("\x1bc"); try tty.anyWriter().writeAll(vaxis.ctlseqs.unicode_set); defer vx.queryTerminalSend(tty.anyWriter()) catch {}; defer tty.anyWriter().writeAll(vaxis.ctlseqs.unicode_reset) catch {}; @@ -57,6 +57,7 @@ pub fn main() !void { // const koko = try vx.transmitImage(allocator, tty.anyWriter(), &img1, .png); // win.hideCursor(); // win.showCursor(10, 1); + const system_info = [_]vaxis.Cell.Segment{ .{ .text = os }, .{ .text = kernel }, @@ -70,14 +71,11 @@ pub fn main() !void { .{ .text = "\t\t\tKernel: lalal\n" }, }; try root.kitty_image_inline_copy(allocator, tty.anyWriter(), "/Users/kc/Sync/Images/apple-dark.png"); - try tty.anyWriter().print("\x1b[10;1H", .{}); - try tty.anyWriter().print("\r\t\tTEST: testest\n", .{}); - try tty.anyWriter().print("\r\t\tTEST: testest\n", .{}); - try tty.anyWriter().print("\r\t\tTEST: testest\n", .{}); - try tty.anyWriter().print("\r\t\tTEST: testest\n", .{}); - try tty.anyWriter().print("\r\t\tTEST: testest\n", .{}); result = try win.print(&system_info, .{ .wrap = .word }); + // printf '\e[%sA\e[9999999D' "${lines:-0}" + try tty.anyWriter().print("\x1b[{d}A\x1b[9999999D", .{winsize.rows}); + // try tty.anyWriter().writeAll("\x1b[1J"); try vx.prettyPrint(writer); // const dimensions = try koko.cellSize(win); @@ -92,7 +90,6 @@ pub fn main() !void { // try vx.queryTerminalSend(tty.anyWriter()); // Clear from cursor to beginning of the screen - // try stdout.writeAll("\x1b[1J"); // Move cursor to the upper left corner of the screen // try stdout.writeAll("\x1b[1;1H"); // try stdout_file.writeAll("\x1b[9B"); diff --git a/src/root.zig b/src/root.zig index f9bca5d..2c094b9 100644 --- a/src/root.zig +++ b/src/root.zig @@ -18,7 +18,7 @@ pub fn kitty_image_inline_copy(allocator: std.mem.Allocator, tty: std.io.AnyWrit const encoded = base64Encoder.encode(b64_buf, path); try tty.print("\x1b_Ga=T,q=2,f=100,t=f,p=0,s=267,v=314;{s}\x1b\\", .{encoded}); - try tty.print("\x1b\\", .{}); + // try tty.print("\x1b\\", .{}); // if (encoded.len <= 4096) { // try tty.print("\x1b_Ga=T,q=2,f=100,t=f,s=267,v=314,m=1;{s}\x1b\\", .{encoded});