mirror of
https://mzte.de/git/LordMZTE/dotfiles.git
synced 2024-12-13 13:02:58 +01:00
update mzteinit
This commit is contained in:
parent
37d063ae24
commit
33acf673ae
3 changed files with 29 additions and 4 deletions
|
@ -1,21 +1,34 @@
|
|||
const std = @import("std");
|
||||
const at = @import("ansi-term");
|
||||
const run = @import("run.zig");
|
||||
const util = @import("util.zig");
|
||||
|
||||
pub fn main() !void {
|
||||
var stdout = std.io.bufferedWriter(std.io.getStdOut().writer());
|
||||
var exit = false;
|
||||
|
||||
try stdout.writer().writeAll("\x1b[2J\x1b[1;1H"); // clear
|
||||
while (true) {
|
||||
try util.writeAnsiClear(stdout.writer());
|
||||
|
||||
const cmd = ui(&stdout) catch |e| {
|
||||
std.debug.print("Error rendering the UI: {}\n", .{e});
|
||||
break;
|
||||
};
|
||||
cmd.run() catch |e| {
|
||||
|
||||
try util.writeAnsiClear(stdout.writer());
|
||||
try stdout.flush();
|
||||
|
||||
cmd.run(&exit) catch |e| {
|
||||
try stdout.writer().print("Error running command: {}\n\n", .{e});
|
||||
continue;
|
||||
};
|
||||
try stdout.writer().writeAll("\x1b[2J\x1b[1;1H"); // clear
|
||||
|
||||
if (exit) {
|
||||
try stdout.writer().writeAll("Goodbye!");
|
||||
try stdout.flush();
|
||||
std.time.sleep(2 * std.time.ns_per_s);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ pub const Command = enum {
|
|||
startx,
|
||||
shell,
|
||||
zellij,
|
||||
logout,
|
||||
shutdown,
|
||||
reboot,
|
||||
|
||||
|
@ -12,6 +13,7 @@ pub const Command = enum {
|
|||
'x', 'X' => .startx,
|
||||
's', 'S' => .shell,
|
||||
'z', 'Z' => .zellij,
|
||||
'l', 'L' => .logout,
|
||||
'p', 'P' => .shutdown,
|
||||
'r', 'R' => .reboot,
|
||||
else => null,
|
||||
|
@ -23,12 +25,18 @@ pub const Command = enum {
|
|||
.startx => 'X',
|
||||
.shell => 'S',
|
||||
.zellij => 'Z',
|
||||
.logout => 'L',
|
||||
.shutdown => 'P',
|
||||
.reboot => 'R',
|
||||
};
|
||||
}
|
||||
|
||||
pub fn run(self: Command) !void {
|
||||
pub fn run(self: Command, exit: *bool) !void {
|
||||
if (self == .logout) {
|
||||
exit.* = true;
|
||||
return;
|
||||
}
|
||||
|
||||
var mem: [512]u8 = undefined;
|
||||
var fba = std.heap.FixedBufferAllocator.init(&mem);
|
||||
const arg = self.argv();
|
||||
|
@ -41,6 +49,7 @@ pub const Command = enum {
|
|||
.startx => &.{"startx"},
|
||||
.shell => &.{"fish"},
|
||||
.zellij => &.{"zellij"},
|
||||
.logout => unreachable,
|
||||
.shutdown => &.{ "systemctl", "poweroff" },
|
||||
.reboot => &.{ "systemctl", "reboot" },
|
||||
};
|
||||
|
|
3
scripts/mzteinit/src/util.zig
Normal file
3
scripts/mzteinit/src/util.zig
Normal file
|
@ -0,0 +1,3 @@
|
|||
pub fn writeAnsiClear(writer: anytype) !void {
|
||||
try writer.writeAll("\x1b[2J\x1b[1;1H");
|
||||
}
|
Loading…
Reference in a new issue