Compare commits
3 commits
a10254b77a
...
19569fc18c
| Author | SHA1 | Date | |
|---|---|---|---|
| 19569fc18c | |||
| b6b1f02565 | |||
| 4aecc983c0 |
5 changed files with 34 additions and 15 deletions
|
|
@ -30,8 +30,8 @@
|
|||
.hash = "fuzzig-0.1.1-Ji0xivxIAQBD0g8O_NV_0foqoPf3elsg9Sc3pNfdVH4D",
|
||||
},
|
||||
.vaxis = .{
|
||||
.url = "git+https://github.com/neurocyte/libvaxis?ref=main#035457cdb54f4c12caae6638b837c447447ae70d",
|
||||
.hash = "vaxis-0.5.1-BWNV_NAyCQBgEcQ3hBKEqyWOJh4uDSm4mPvffsI10J5i",
|
||||
.url = "git+https://github.com/neurocyte/libvaxis?ref=main#164dfadbad9a5df529ade8e3f0e5c52939d27e81",
|
||||
.hash = "vaxis-0.5.1-BWNV_M4yCQBLJYI9ooJL-8dstYnId58coiBeHhF4m9wz",
|
||||
},
|
||||
.zeit = .{
|
||||
.url = "git+https://github.com/rockorager/zeit?ref=zig-0.15#ed2ca60db118414bda2b12df2039e33bad3b0b88",
|
||||
|
|
|
|||
23
src/renderer/vaxis/GraphemeCache.zig
Normal file
23
src/renderer/vaxis/GraphemeCache.zig
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
storage: *Storage,
|
||||
|
||||
pub const GraphemeCache = @This();
|
||||
|
||||
pub inline fn put(self: *@This(), bytes: []const u8) []u8 {
|
||||
return self.storage.put(bytes);
|
||||
}
|
||||
|
||||
pub const Storage = struct {
|
||||
buf: [1024 * 512]u8 = undefined,
|
||||
idx: usize = 0,
|
||||
|
||||
pub fn put(self: *@This(), bytes: []const u8) []u8 {
|
||||
if (self.idx + bytes.len > self.buf.len) self.idx = 0;
|
||||
defer self.idx += bytes.len;
|
||||
@memcpy(self.buf[self.idx .. self.idx + bytes.len], bytes);
|
||||
return self.buf[self.idx .. self.idx + bytes.len];
|
||||
}
|
||||
|
||||
pub fn cache(self: *@This()) GraphemeCache {
|
||||
return .{ .storage = self };
|
||||
}
|
||||
};
|
||||
|
|
@ -2,6 +2,7 @@ const std = @import("std");
|
|||
const vaxis = @import("vaxis");
|
||||
|
||||
pub const Plane = @import("Plane.zig");
|
||||
const GraphemeCache = @import("GraphemeCache.zig");
|
||||
|
||||
const Layer = @This();
|
||||
|
||||
|
|
@ -13,6 +14,7 @@ plane_: Plane,
|
|||
const View = struct {
|
||||
allocator: std.mem.Allocator,
|
||||
screen: vaxis.Screen,
|
||||
cache_storage: GraphemeCache.Storage = .{},
|
||||
|
||||
pub const Config = struct {
|
||||
h: u16,
|
||||
|
|
@ -57,6 +59,7 @@ pub fn init(allocator: std.mem.Allocator, opts: Options) std.mem.Allocator.Error
|
|||
const name = "layer";
|
||||
self.plane_ = .{
|
||||
.window = self.window(),
|
||||
.cache = self.view.cache_storage.cache(),
|
||||
.name_buf = undefined,
|
||||
.name_len = name.len,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ const vaxis = @import("vaxis");
|
|||
const Buffer = @import("Buffer");
|
||||
const color = @import("color");
|
||||
const RGB = @import("color").RGB;
|
||||
const GraphemeCache = @import("GraphemeCache.zig");
|
||||
|
||||
const Plane = @This();
|
||||
|
||||
|
|
@ -18,7 +19,7 @@ row: i32 = 0,
|
|||
col: i32 = 0,
|
||||
name_buf: [name_buf_len]u8,
|
||||
name_len: usize,
|
||||
cache: GraphemeCache = .{},
|
||||
cache: GraphemeCache,
|
||||
style: vaxis.Cell.Style = .{},
|
||||
style_base: vaxis.Cell.Style = .{},
|
||||
scrolling: bool = false,
|
||||
|
|
@ -49,6 +50,7 @@ pub fn init(nopts: *const Options, parent_: Plane) !Plane {
|
|||
const len = @min(nopts.name.len, name_buf_len);
|
||||
var plane: Plane = .{
|
||||
.window = parent_.window.child(opts),
|
||||
.cache = parent_.cache,
|
||||
.name_buf = undefined,
|
||||
.name_len = len,
|
||||
.scrolling = nopts.flags == .VSCROLL,
|
||||
|
|
@ -500,18 +502,6 @@ pub fn metrics(self: *const Plane, tab_width: usize) Buffer.Metrics {
|
|||
};
|
||||
}
|
||||
|
||||
const GraphemeCache = struct {
|
||||
buf: [1024 * 16]u8 = undefined,
|
||||
idx: usize = 0,
|
||||
|
||||
pub fn put(self: *GraphemeCache, bytes: []const u8) []u8 {
|
||||
if (self.idx + bytes.len > self.buf.len) self.idx = 0;
|
||||
defer self.idx += bytes.len;
|
||||
@memcpy(self.buf[self.idx .. self.idx + bytes.len], bytes);
|
||||
return self.buf[self.idx .. self.idx + bytes.len];
|
||||
}
|
||||
};
|
||||
|
||||
fn to_cell_color(col: ThemeColor) vaxis.Cell.Color {
|
||||
return .{ .rgb = RGB.to_u8s(RGB.from_u24(col.color)) };
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ pub const CursorShape = vaxis.Cell.CursorShape;
|
|||
|
||||
pub const style = @import("style.zig").StyleBits;
|
||||
pub const styles = @import("style.zig");
|
||||
const GraphemeCache = @import("GraphemeCache.zig");
|
||||
|
||||
const Self = @This();
|
||||
pub const log_name = "vaxis";
|
||||
|
|
@ -25,6 +26,7 @@ allocator: std.mem.Allocator,
|
|||
tty: vaxis.Tty,
|
||||
vx: vaxis.Vaxis,
|
||||
tty_buffer: []u8,
|
||||
cache_storage: GraphemeCache.Storage = .{},
|
||||
|
||||
no_alternate: bool,
|
||||
event_buffer: std.Io.Writer.Allocating,
|
||||
|
|
@ -240,6 +242,7 @@ pub fn stdplane(self: *Self) Plane {
|
|||
const name = "root";
|
||||
var plane: Plane = .{
|
||||
.window = self.vx.window(),
|
||||
.cache = self.cache_storage.cache(),
|
||||
.name_buf = undefined,
|
||||
.name_len = name.len,
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue