feat: add support for CRLF EOL mode
This commit is contained in:
parent
9a633aa2a9
commit
593b202b16
8 changed files with 119 additions and 50 deletions
|
@ -1,6 +1,7 @@
|
|||
const std = @import("std");
|
||||
const Allocator = std.mem.Allocator;
|
||||
const tp = @import("thespian");
|
||||
const Buffer = @import("Buffer");
|
||||
|
||||
const Plane = @import("renderer").Plane;
|
||||
|
||||
|
@ -13,6 +14,7 @@ lines: usize = 0,
|
|||
column: usize = 0,
|
||||
buf: [256]u8 = undefined,
|
||||
rendered: [:0]const u8 = "",
|
||||
eol_mode: Buffer.EolMode = .lf,
|
||||
|
||||
const Self = @This();
|
||||
|
||||
|
@ -47,14 +49,21 @@ pub fn render(self: *Self, btn: *Button.State(Self), theme: *const Widget.Theme)
|
|||
fn format(self: *Self) void {
|
||||
var fbs = std.io.fixedBufferStream(&self.buf);
|
||||
const writer = fbs.writer();
|
||||
std.fmt.format(writer, " Ln {d}, Col {d} ", .{ self.line + 1, self.column + 1 }) catch {};
|
||||
const eol_mode = switch (self.eol_mode) {
|
||||
.lf => "",
|
||||
.crlf => " [␍␊]",
|
||||
};
|
||||
std.fmt.format(writer, "{s} Ln {d}, Col {d} ", .{ eol_mode, self.line + 1, self.column + 1 }) catch {};
|
||||
self.rendered = @ptrCast(fbs.getWritten());
|
||||
self.buf[self.rendered.len] = 0;
|
||||
}
|
||||
|
||||
pub fn receive(self: *Self, _: *Button.State(Self), _: tp.pid_ref, m: tp.message) error{Exit}!bool {
|
||||
var eol_mode: Buffer.EolModeTag = @intFromEnum(Buffer.EolMode.lf);
|
||||
if (try m.match(.{ "E", "pos", tp.extract(&self.lines), tp.extract(&self.line), tp.extract(&self.column) })) {
|
||||
self.format();
|
||||
} else if (try m.match(.{ "E", "eol_mode", tp.extract(&eol_mode) })) {
|
||||
self.eol_mode = @enumFromInt(eol_mode);
|
||||
} else if (try m.match(.{ "E", "close" })) {
|
||||
self.lines = 0;
|
||||
self.line = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue