Custom info text

pull/606/head
Kinzie 4 weeks ago
parent 4415545f7b
commit 1d3148201c
No known key found for this signature in database
GPG Key ID: EF86FC12BB84F79E

@ -10,6 +10,7 @@ bg: u8 = 0,
bigclock: bool = false,
blank_box: bool = true,
border_fg: u8 = 8,
box_title: ?[]const u8 = null,
clear_password: bool = false,
clock: ?[:0]const u8 = null,
console_dev: [:0]const u8 = "/dev/console",
@ -17,6 +18,7 @@ default_input: Input = .login,
fg: u8 = 8,
hide_borders: bool = false,
hide_key_hints: bool = false,
initial_info_text: ?[]const u8 = null,
input_len: u8 = 34,
lang: []const u8 = "en",
load: bool = true,

@ -129,8 +129,10 @@ pub fn main() !void {
interop.setNumlock(config.numlock) catch {};
// Initialize information line with host name
get_host_name: {
if (config.initial_info_text) |text| {
try info_line.setText(text);
} else get_host_name: {
// Initialize information line with host name
var name_buf: [std.posix.HOST_NAME_MAX]u8 = undefined;
const hostname = std.posix.gethostname(&name_buf) catch {
try info_line.setText(lang.err_hostname);
@ -395,9 +397,13 @@ pub fn main() !void {
}
}
if (config.box_title) |title| {
buffer.drawConfinedLabel(title, buffer.box_x, buffer.box_y - 1, buffer.box_width);
}
if (config.vi_mode) {
const label_txt = if (insert_mode) lang.insert else lang.normal;
buffer.drawLabel(label_txt, buffer.box_x, buffer.box_y - 1);
buffer.drawLabel(label_txt, buffer.box_x, buffer.box_y + buffer.box_height);
}
draw_lock_state: {

@ -170,6 +170,20 @@ pub fn drawLabel(self: TerminalBuffer, text: []const u8, x: u64, y: u64) void {
}
}
pub fn drawConfinedLabel(self: TerminalBuffer, text: []const u8, x: u64, y: u64, max_length: u64) void {
var confined_text = text;
if (text.len > max_length) confined_text = text[0..max_length];
const yc: c_int = @intCast(y);
const utf8view = std.unicode.Utf8View.init(confined_text) catch return;
var utf8 = utf8view.iterator();
var i = x;
while (utf8.nextCodepoint()) |codepoint| : (i += 1) {
termbox.tb_change_cell(@intCast(i), yc, codepoint, self.fg, self.bg);
}
}
pub fn drawCharMultiple(self: TerminalBuffer, char: u8, x: u64, y: u64, length: u64) void {
const yc: c_int = @intCast(y);
const cell = utils.initCell(char, self.fg, self.bg);

Loading…
Cancel
Save