mirror of
https://mzte.de/git/LordMZTE/dotfiles.git
synced 2024-12-15 01:43:51 +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 std = @import("std");
|
||||||
const at = @import("ansi-term");
|
const at = @import("ansi-term");
|
||||||
const run = @import("run.zig");
|
const run = @import("run.zig");
|
||||||
|
const util = @import("util.zig");
|
||||||
|
|
||||||
pub fn main() !void {
|
pub fn main() !void {
|
||||||
var stdout = std.io.bufferedWriter(std.io.getStdOut().writer());
|
var stdout = std.io.bufferedWriter(std.io.getStdOut().writer());
|
||||||
|
var exit = false;
|
||||||
|
|
||||||
try stdout.writer().writeAll("\x1b[2J\x1b[1;1H"); // clear
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
try util.writeAnsiClear(stdout.writer());
|
||||||
|
|
||||||
const cmd = ui(&stdout) catch |e| {
|
const cmd = ui(&stdout) catch |e| {
|
||||||
std.debug.print("Error rendering the UI: {}\n", .{e});
|
std.debug.print("Error rendering the UI: {}\n", .{e});
|
||||||
break;
|
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});
|
try stdout.writer().print("Error running command: {}\n\n", .{e});
|
||||||
continue;
|
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,
|
startx,
|
||||||
shell,
|
shell,
|
||||||
zellij,
|
zellij,
|
||||||
|
logout,
|
||||||
shutdown,
|
shutdown,
|
||||||
reboot,
|
reboot,
|
||||||
|
|
||||||
|
@ -12,6 +13,7 @@ pub const Command = enum {
|
||||||
'x', 'X' => .startx,
|
'x', 'X' => .startx,
|
||||||
's', 'S' => .shell,
|
's', 'S' => .shell,
|
||||||
'z', 'Z' => .zellij,
|
'z', 'Z' => .zellij,
|
||||||
|
'l', 'L' => .logout,
|
||||||
'p', 'P' => .shutdown,
|
'p', 'P' => .shutdown,
|
||||||
'r', 'R' => .reboot,
|
'r', 'R' => .reboot,
|
||||||
else => null,
|
else => null,
|
||||||
|
@ -23,12 +25,18 @@ pub const Command = enum {
|
||||||
.startx => 'X',
|
.startx => 'X',
|
||||||
.shell => 'S',
|
.shell => 'S',
|
||||||
.zellij => 'Z',
|
.zellij => 'Z',
|
||||||
|
.logout => 'L',
|
||||||
.shutdown => 'P',
|
.shutdown => 'P',
|
||||||
.reboot => 'R',
|
.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 mem: [512]u8 = undefined;
|
||||||
var fba = std.heap.FixedBufferAllocator.init(&mem);
|
var fba = std.heap.FixedBufferAllocator.init(&mem);
|
||||||
const arg = self.argv();
|
const arg = self.argv();
|
||||||
|
@ -41,6 +49,7 @@ pub const Command = enum {
|
||||||
.startx => &.{"startx"},
|
.startx => &.{"startx"},
|
||||||
.shell => &.{"fish"},
|
.shell => &.{"fish"},
|
||||||
.zellij => &.{"zellij"},
|
.zellij => &.{"zellij"},
|
||||||
|
.logout => unreachable,
|
||||||
.shutdown => &.{ "systemctl", "poweroff" },
|
.shutdown => &.{ "systemctl", "poweroff" },
|
||||||
.reboot => &.{ "systemctl", "reboot" },
|
.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