Back of 'config' sourcing implemented, look at TODO in src/main.zig

This commit is contained in:
KikooDX 2021-02-04 00:55:57 +01:00
parent 935623ce77
commit b5972abd1c
2 changed files with 31 additions and 0 deletions

View File

@ -4,8 +4,32 @@
// MIT licensed. The MIT license requires this copyright notice to be
// included in all copies and substantial portions of the software.
//! Values and types used by different files and that don't fit in any.
//! Read /etc/kble.conf and execute content.
/// Number passed to commands.
const std = @import("std");
pub const arg_type: type = u16;
pub const mouse_enabled: bool = true;
pub const mouse_left_btn: c_int = 0;
pub const mouse_right_btn: c_int = 1;
/// Read /etc/kble.conf and execute all bytes as keypresses.
pub fn source_config() void {
// Open file in read mode.
const file: std.fs.File = std.fs.openFileAbsolute("/etc/kble.conf", std.fs.File.OpenFlags{
.read = true,
.write = false,
}) catch {
std.log.err("Can't open /etc/kble.conf", .{});
return;
};
// Get reader.
const reader: std.fs.File.Reader = file.reader();
// Read all bytes.
while (true) {
const byte: u8 = reader.readByte() catch {
break;
};
std.log.info("{}", .{byte});
}
}

View File

@ -89,6 +89,9 @@ pub fn main() void {
bindings['v'] = &ActionsDef.mode_rectangle;
bindings['c'] = &ActionsDef.mode_camera;
// Load config.
conf.source_config();
// Create input buffer.
const input_buffer_len = 255;
var input_buffer: [input_buffer_len]u32 = undefined;
@ -135,6 +138,7 @@ pub fn main() void {
else
0;
// TODO: move everything from this to a function (for config and macros support).
const action: actions.Action = bindings[key].*;
const apply_selection: bool = (mode == Mode.select);
@ -161,8 +165,11 @@ pub fn main() void {
}
cursor_before = cursor; // Save position before selection.
mode = action.next_mode;
if (mode == Mode.select) // Select first tile.
level.select_cell(cursor, true);
},
}
// TODO end
}
// Mouse operations.