mirror of
https://mzte.de/git/LordMZTE/dotfiles.git
synced 2024-11-13 05:22:08 +01:00
minor mzteinit improvements
This commit is contained in:
parent
8e72b3ab93
commit
96f62f2283
3 changed files with 23 additions and 10 deletions
|
@ -49,7 +49,6 @@ pub fn main() void {
|
|||
|
||||
fn tryMain() !void {
|
||||
var stdout = std.io.bufferedWriter(std.io.getStdOut().writer());
|
||||
var exit = false;
|
||||
|
||||
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
||||
defer _ = gpa.deinit();
|
||||
|
@ -101,16 +100,21 @@ fn tryMain() !void {
|
|||
try util.writeAnsiClear(stdout.writer());
|
||||
try stdout.flush();
|
||||
|
||||
var exit = util.ExitMode.run;
|
||||
cmd.run(alloc, &exit, &env_map) catch |e| {
|
||||
try stdout.writer().print("Error running command: {}\n\n", .{e});
|
||||
continue;
|
||||
};
|
||||
|
||||
if (exit) {
|
||||
try stdout.writer().writeAll("Goodbye!");
|
||||
try stdout.flush();
|
||||
std.time.sleep(2 * std.time.ns_per_s);
|
||||
return;
|
||||
switch (exit) {
|
||||
.run => {},
|
||||
.immediate => return,
|
||||
.delayed => {
|
||||
try stdout.writer().writeAll("Goodbye!");
|
||||
try stdout.flush();
|
||||
std.time.sleep(2 * std.time.ns_per_s);
|
||||
return;
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
const std = @import("std");
|
||||
const log = std.log.scoped(.run);
|
||||
|
||||
pub const Command = enum {
|
||||
startx,
|
||||
|
@ -34,15 +35,21 @@ pub const Command = enum {
|
|||
pub fn run(
|
||||
self: Command,
|
||||
alloc: std.mem.Allocator,
|
||||
exit: *bool,
|
||||
exit: *@import("util.zig").ExitMode,
|
||||
env: *const std.process.EnvMap,
|
||||
) !void {
|
||||
if (self == .logout) {
|
||||
exit.* = true;
|
||||
return;
|
||||
switch (self) {
|
||||
.logout => {
|
||||
exit.* = .delayed;
|
||||
log.info("user logged out", .{});
|
||||
return;
|
||||
},
|
||||
.shutdown, .reboot => exit.* = .immediate,
|
||||
else => {},
|
||||
}
|
||||
|
||||
const arg = self.argv();
|
||||
log.info("run cmd: {s}", .{arg});
|
||||
var child = std.ChildProcess.init(arg, alloc);
|
||||
child.env_map = env;
|
||||
_ = try child.spawnAndWait();
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
pub fn writeAnsiClear(writer: anytype) !void {
|
||||
try writer.writeAll("\x1b[2J\x1b[1;1H");
|
||||
}
|
||||
|
||||
pub const ExitMode = enum { run, immediate, delayed };
|
||||
|
|
Loading…
Reference in a new issue