fix: render control codes in mini buffer input with unicode control code symbols
closes #236
This commit is contained in:
parent
993add1a43
commit
e39d9ed4b3
7 changed files with 24 additions and 8 deletions
|
@ -202,6 +202,21 @@ pub fn putstr(self: *Plane, text: []const u8) !usize {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn putstr_unicode(self: *Plane, text: []const u8) !usize {
|
||||||
|
var result: usize = 0;
|
||||||
|
var iter = self.window.screen.unicode.graphemeIterator(text);
|
||||||
|
while (iter.next()) |grapheme| {
|
||||||
|
const s_ = grapheme.bytes(text);
|
||||||
|
const s = switch (s_[0]) {
|
||||||
|
0...31 => |code| Buffer.unicode.control_code_to_unicode(code),
|
||||||
|
else => s_,
|
||||||
|
};
|
||||||
|
self.write_cell(@intCast(self.col), @intCast(self.row), s);
|
||||||
|
result += 1;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
pub fn putc(self: *Plane, cell: *const Cell) !usize {
|
pub fn putc(self: *Plane, cell: *const Cell) !usize {
|
||||||
return self.putc_yx(@intCast(self.row), @intCast(self.col), cell);
|
return self.putc_yx(@intCast(self.row), @intCast(self.col), cell);
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,7 +60,7 @@ pub fn Create(options: type) type {
|
||||||
fn update_mini_mode_text(self: *Self) void {
|
fn update_mini_mode_text(self: *Self) void {
|
||||||
if (tui.mini_mode()) |mini_mode| {
|
if (tui.mini_mode()) |mini_mode| {
|
||||||
mini_mode.text = self.input.items;
|
mini_mode.text = self.input.items;
|
||||||
mini_mode.cursor = tui.egc_chunk_width(self.input.items, 0, 8);
|
mini_mode.cursor = tui.egc_chunk_width(self.input.items, 0, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -115,7 +115,7 @@ pub fn Create(options: type) type {
|
||||||
}
|
}
|
||||||
if (tui.mini_mode()) |mini_mode| {
|
if (tui.mini_mode()) |mini_mode| {
|
||||||
mini_mode.text = self.file_path.items;
|
mini_mode.text = self.file_path.items;
|
||||||
mini_mode.cursor = tui.egc_chunk_width(self.file_path.items, 0, 8);
|
mini_mode.cursor = tui.egc_chunk_width(self.file_path.items, 0, 1);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -139,7 +139,7 @@ pub fn Create(options: type) type {
|
||||||
defer {
|
defer {
|
||||||
if (tui.mini_mode()) |mini_mode| {
|
if (tui.mini_mode()) |mini_mode| {
|
||||||
mini_mode.text = self.file_path.items;
|
mini_mode.text = self.file_path.items;
|
||||||
mini_mode.cursor = tui.egc_chunk_width(self.file_path.items, 0, 8);
|
mini_mode.cursor = tui.egc_chunk_width(self.file_path.items, 0, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var count: usize = undefined;
|
var count: usize = undefined;
|
||||||
|
@ -243,7 +243,7 @@ pub fn Create(options: type) type {
|
||||||
fn update_mini_mode_text(self: *Self) void {
|
fn update_mini_mode_text(self: *Self) void {
|
||||||
if (tui.mini_mode()) |mini_mode| {
|
if (tui.mini_mode()) |mini_mode| {
|
||||||
mini_mode.text = self.file_path.items;
|
mini_mode.text = self.file_path.items;
|
||||||
mini_mode.cursor = tui.egc_chunk_width(self.file_path.items, 0, 8);
|
mini_mode.cursor = tui.egc_chunk_width(self.file_path.items, 0, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -142,7 +142,7 @@ fn load_history(self: *Self, pos: usize) void {
|
||||||
fn update_mini_mode_text(self: *Self) void {
|
fn update_mini_mode_text(self: *Self) void {
|
||||||
if (tui.mini_mode()) |mini_mode| {
|
if (tui.mini_mode()) |mini_mode| {
|
||||||
mini_mode.text = self.input_.items;
|
mini_mode.text = self.input_.items;
|
||||||
mini_mode.cursor = tui.egc_chunk_width(self.input_.items, 0, 8);
|
mini_mode.cursor = tui.egc_chunk_width(self.input_.items, 0, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -83,7 +83,7 @@ fn start_query(self: *Self) !void {
|
||||||
fn update_mini_mode_text(self: *Self) void {
|
fn update_mini_mode_text(self: *Self) void {
|
||||||
if (tui.mini_mode()) |mini_mode| {
|
if (tui.mini_mode()) |mini_mode| {
|
||||||
mini_mode.text = self.input_;
|
mini_mode.text = self.input_;
|
||||||
mini_mode.cursor = tui.egc_chunk_width(self.input_, 0, 8);
|
mini_mode.cursor = tui.egc_chunk_width(self.input_, 0, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ fn update_mini_mode_text(self: *Self) void {
|
||||||
(fmt.bufPrint(&self.buf, "{d}", .{linenum}) catch "")
|
(fmt.bufPrint(&self.buf, "{d}", .{linenum}) catch "")
|
||||||
else
|
else
|
||||||
"";
|
"";
|
||||||
mini_mode.cursor = tui.egc_chunk_width(mini_mode.text, 0, 8);
|
mini_mode.cursor = tui.egc_chunk_width(mini_mode.text, 0, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -104,7 +104,8 @@ pub fn render(self: *Self, btn: *Button.State(Self), theme: *const Widget.Theme)
|
||||||
fn render_mini_mode(plane: *Plane, theme: *const Widget.Theme) void {
|
fn render_mini_mode(plane: *Plane, theme: *const Widget.Theme) void {
|
||||||
plane.off_styles(styles.italic);
|
plane.off_styles(styles.italic);
|
||||||
const mini_mode = tui.mini_mode() orelse return;
|
const mini_mode = tui.mini_mode() orelse return;
|
||||||
_ = plane.print(" {s}", .{mini_mode.text}) catch {};
|
_ = plane.putstr_unicode(" ") catch {};
|
||||||
|
_ = plane.putstr_unicode(mini_mode.text) catch {};
|
||||||
if (mini_mode.cursor) |cursor| {
|
if (mini_mode.cursor) |cursor| {
|
||||||
const pos: c_int = @intCast(cursor);
|
const pos: c_int = @intCast(cursor);
|
||||||
if (tui.config().enable_terminal_cursor) {
|
if (tui.config().enable_terminal_cursor) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue