mirror of
https://github.com/fairyglade/ly.git
synced 2026-09-22 12:00:19 +00:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
75001c4a33 | ||
|
|
c56a607fe7 | ||
|
|
a9cbfbddbf | ||
|
|
f52baa7f79 | ||
|
|
3dcd883c10 | ||
|
|
e01fc945a2 | ||
|
|
79bb0cacf1 | ||
|
|
bcc2cdfcdc | ||
|
|
f89e79c7f8 | ||
|
|
13544be6a8 | ||
|
|
8799dcbdf9 |
@@ -123,7 +123,7 @@ pub fn build(b: *std.Build) !void {
|
|||||||
|
|
||||||
const run_cmd = b.addRunArtifact(exe);
|
const run_cmd = b.addRunArtifact(exe);
|
||||||
run_cmd.step.dependOn(b.getInstallStep());
|
run_cmd.step.dependOn(b.getInstallStep());
|
||||||
if (b.args) |args| run_cmd.addArgs(args);
|
run_cmd.addPassthruArgs();
|
||||||
|
|
||||||
const run_step = b.step("run", "Run the app");
|
const run_step = b.step("run", "Run the app");
|
||||||
run_step.dependOn(&run_cmd.step);
|
run_step.dependOn(&run_cmd.step);
|
||||||
@@ -188,7 +188,7 @@ fn getVersionStr(b: *std.Build, name: []const u8, version: std.SemanticVersion)
|
|||||||
const git_describe_raw = b.runAllowFail(&[_][]const u8{
|
const git_describe_raw = b.runAllowFail(&[_][]const u8{
|
||||||
"git",
|
"git",
|
||||||
"-C",
|
"-C",
|
||||||
b.build_root.path orelse ".",
|
try b.root.toString(b.allocator),
|
||||||
"describe",
|
"describe",
|
||||||
"--match",
|
"--match",
|
||||||
"*.*.*",
|
"*.*.*",
|
||||||
|
|||||||
@@ -2,14 +2,14 @@
|
|||||||
.name = .ly,
|
.name = .ly,
|
||||||
.version = "1.6.0",
|
.version = "1.6.0",
|
||||||
.fingerprint = 0xa148ffcc5dc2cb59,
|
.fingerprint = 0xa148ffcc5dc2cb59,
|
||||||
.minimum_zig_version = "0.16.0",
|
.minimum_zig_version = "0.17.0",
|
||||||
.dependencies = .{
|
.dependencies = .{
|
||||||
.ly_ui = .{
|
.ly_ui = .{
|
||||||
.path = "ly-ui",
|
.path = "ly-ui",
|
||||||
},
|
},
|
||||||
.clap = .{
|
.clap = .{
|
||||||
.url = "git+https://github.com/Hejsil/zig-clap#fc1e5cc3f6d9d3001112385ee6256d694e959d2f",
|
.url = "git+https://github.com/Hejsil/zig-clap?ref=master#e91d66b1abba2024cd2e816426f14d233d3dad9a",
|
||||||
.hash = "clap-0.11.0-oBajB7foAQC3Iyn4IVCkUdYaOVVng5IZkSncySTjNig1",
|
.hash = "clap-0.12.0-oBajB2LpAQD1BQpAukHcuwhIUoHWYNy2DzU6lDW2v2N8",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
.paths = .{
|
.paths = .{
|
||||||
|
|||||||
@@ -381,7 +381,7 @@ fn installText(
|
|||||||
destination_directory: std.Io.Dir,
|
destination_directory: std.Io.Dir,
|
||||||
destination_directory_path: []const u8,
|
destination_directory_path: []const u8,
|
||||||
destination_file: []const u8,
|
destination_file: []const u8,
|
||||||
options: std.Io.File.CreateFlags,
|
options: std.Io.Dir.CreateFileOptions,
|
||||||
) !void {
|
) !void {
|
||||||
var file = try destination_directory.createFile(io, destination_file, options);
|
var file = try destination_directory.createFile(io, destination_file, options);
|
||||||
defer file.close(io);
|
defer file.close(io);
|
||||||
|
|||||||
@@ -28,9 +28,7 @@ pub fn build(b: *std.Build) void {
|
|||||||
});
|
});
|
||||||
mod.addImport("zlua", zlua.module("zlua"));
|
mod.addImport("zlua", zlua.module("zlua"));
|
||||||
|
|
||||||
const translate_c = b.dependency("translate_c", .{
|
const translate_c = b.dependency("translate_c", .{});
|
||||||
.target = target,
|
|
||||||
});
|
|
||||||
|
|
||||||
addCImport(b, mod, translate_c, target, optimize, "pam", "#include <security/pam_appl.h>");
|
addCImport(b, mod, translate_c, target, optimize, "pam", "#include <security/pam_appl.h>");
|
||||||
addCImport(b, mod, translate_c, target, optimize, "utmp", "#include <utmpx.h>");
|
addCImport(b, mod, translate_c, target, optimize, "utmp", "#include <utmpx.h>");
|
||||||
|
|||||||
@@ -2,19 +2,19 @@
|
|||||||
.name = .ly_core,
|
.name = .ly_core,
|
||||||
.version = "1.2.0",
|
.version = "1.2.0",
|
||||||
.fingerprint = 0xddda7afda795472,
|
.fingerprint = 0xddda7afda795472,
|
||||||
.minimum_zig_version = "0.16.0",
|
.minimum_zig_version = "0.17.0",
|
||||||
.dependencies = .{
|
.dependencies = .{
|
||||||
.zigini = .{
|
.zigini = .{
|
||||||
.url = "git+https://github.com/AshAmetrine/zigini?ref=master#a665d081dda42664a96da2840ea09c5ccf9d0692",
|
.url = "git+https://github.com/AshAmetrine/zigini?ref=main#085badbf90e25016f4609b5bde334689cdb41c5c",
|
||||||
.hash = "zigini-0.5.0-BSkB7e9WAACfyCBABNZiWL3gFMw18GKn3qBcPs8L1Ec1",
|
.hash = "zigini-0.6.0-BSkB7UtYAAB6b6HEm3Pjj5WIy-uiuBYsNTNCUENVwL1t",
|
||||||
},
|
},
|
||||||
.translate_c = .{
|
.translate_c = .{
|
||||||
.url = "git+https://codeberg.org/ziglang/translate-c?ref=zig-0.16.x#6fe0ffc4549f15c5f2d9432c2b4460ba90ff85ac",
|
.url = "git+https://codeberg.org/ziglang/translate-c?ref=master#3da873cacdd7e9190fe1cf40372ddf5387c970ea",
|
||||||
.hash = "translate_c-1.0.0-Q_BUWo_5BgD4flHdUhA31zOz0XvZk9k7lQv1ouzyNXj2",
|
.hash = "translate_c-0.0.0-Q_BUWktLBwBO7VLbmrOKUcAMRtE5fmOxI35189X5XbJs",
|
||||||
},
|
},
|
||||||
.zlua = .{
|
.zlua = .{
|
||||||
.url = "git+https://github.com/natecraddock/ziglua?ref=zig-0.16#8f271c82baa5fc43aa02a72f6da020c2025d9436",
|
.url = "git+https://github.com/AnErrupTion/ziglua?ref=zig-0.17#4159a5592a8de728022e0c491a3bdde7decbdc16",
|
||||||
.hash = "zlua-0.1.0-hGRpC2aABQD4D9PBVH3wAW8k32-I4969MRQ0CpOwoley",
|
.hash = "zlua-0.1.0-hGRpCw6VBQDaOiIiYsLOcQTlcJCpqDqIrhyDVqkanTSB",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
.paths = .{
|
.paths = .{
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ pub fn info(self: *LogFile, io: std.Io, category: []const u8, comptime message:
|
|||||||
} else {
|
} else {
|
||||||
var buffer: [1024]u8 = undefined;
|
var buffer: [1024]u8 = undefined;
|
||||||
const slice = try std.fmt.bufPrint(&buffer, message, args);
|
const slice = try std.fmt.bufPrint(&buffer, message, args);
|
||||||
const msg = try std.fmt.bufPrintZ(buffer[slice.len..], "[info/{s}] {s}", .{ category, slice });
|
const msg = try std.fmt.bufPrintSentinel(buffer[slice.len..], "[info/{s}] {s}", .{ category, slice }, 0);
|
||||||
|
|
||||||
std.posix.system.syslog(std.posix.LOG.INFO, msg.ptr);
|
std.posix.system.syslog(std.posix.LOG.INFO, msg.ptr);
|
||||||
}
|
}
|
||||||
@@ -72,7 +72,7 @@ pub fn err(self: *LogFile, io: std.Io, category: []const u8, comptime message: [
|
|||||||
} else {
|
} else {
|
||||||
var buffer: [1024]u8 = undefined;
|
var buffer: [1024]u8 = undefined;
|
||||||
const slice = try std.fmt.bufPrint(&buffer, message, args);
|
const slice = try std.fmt.bufPrint(&buffer, message, args);
|
||||||
const msg = try std.fmt.bufPrintZ(buffer[slice.len..], "[info/{s}] {s}", .{ category, slice });
|
const msg = try std.fmt.bufPrintSentinel(buffer[slice.len..], "[info/{s}] {s}", .{ category, slice }, 0);
|
||||||
|
|
||||||
std.posix.system.syslog(std.posix.LOG.ERR, msg.ptr);
|
std.posix.system.syslog(std.posix.LOG.ERR, msg.ptr);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
const ErrInt = std.meta.Int(.unsigned, @bitSizeOf(anyerror));
|
const ErrInt = @Int(.unsigned, @bitSizeOf(anyerror));
|
||||||
const PaddingInt = std.meta.Int(.unsigned, 8 - (@bitSizeOf(ErrInt) + @bitSizeOf(bool)) % 8);
|
const PaddingInt = @Int(.unsigned, 8 - (@bitSizeOf(ErrInt) + @bitSizeOf(bool)) % 8);
|
||||||
|
|
||||||
const ErrorHandler = packed struct {
|
const ErrorHandler = packed struct {
|
||||||
has_error: bool = false,
|
has_error: bool = false,
|
||||||
|
|||||||
@@ -376,7 +376,7 @@ pub fn setNumlock(val: bool) !void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn setUserContext(allocator: std.mem.Allocator, entry: UsernameEntry) !void {
|
pub fn setUserContext(allocator: std.mem.Allocator, entry: UsernameEntry) !void {
|
||||||
const username_z = try allocator.dupeZ(u8, entry.username.?);
|
const username_z = try allocator.dupeSentinel(u8, entry.username.?, 0);
|
||||||
defer allocator.free(username_z);
|
defer allocator.free(username_z);
|
||||||
|
|
||||||
return platform_struct.setUserContextImpl(username_z.ptr, entry);
|
return platform_struct.setUserContextImpl(username_z.ptr, entry);
|
||||||
@@ -392,10 +392,10 @@ pub fn setUserShell(entry: *UsernameEntry) void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn setEnvironmentVariable(allocator: std.mem.Allocator, name: []const u8, value: []const u8, replace: bool) !void {
|
pub fn setEnvironmentVariable(allocator: std.mem.Allocator, name: []const u8, value: []const u8, replace: bool) !void {
|
||||||
const name_z = try allocator.dupeZ(u8, name);
|
const name_z = try allocator.dupeSentinel(u8, name, 0);
|
||||||
defer allocator.free(name_z);
|
defer allocator.free(name_z);
|
||||||
|
|
||||||
const value_z = try allocator.dupeZ(u8, value);
|
const value_z = try allocator.dupeSentinel(u8, value, 0);
|
||||||
defer allocator.free(value_z);
|
defer allocator.free(value_z);
|
||||||
|
|
||||||
const status = stdlib.setenv(name_z.ptr, value_z.ptr, @intFromBool(replace));
|
const status = stdlib.setenv(name_z.ptr, value_z.ptr, @intFromBool(replace));
|
||||||
@@ -422,7 +422,7 @@ pub fn getNextUsernameEntry() ?UsernameEntry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn getUsernameEntry(allocator: std.mem.Allocator, username: []const u8) ?UsernameEntry {
|
pub fn getUsernameEntry(allocator: std.mem.Allocator, username: []const u8) ?UsernameEntry {
|
||||||
const username_z = allocator.dupeZ(u8, username) catch return null;
|
const username_z = allocator.dupeSentinel(u8, username, 0) catch return null;
|
||||||
defer allocator.free(username_z);
|
defer allocator.free(username_z);
|
||||||
|
|
||||||
const entry = pwd.getpwnam(username_z);
|
const entry = pwd.getpwnam(username_z);
|
||||||
|
|||||||
@@ -131,13 +131,11 @@ pub fn LuaParser(comptime Struct: type) type {
|
|||||||
var arena = std.heap.ArenaAllocator.init(allocator);
|
var arena = std.heap.ArenaAllocator.init(allocator);
|
||||||
const arena_alloc = arena.allocator();
|
const arena_alloc = arena.allocator();
|
||||||
|
|
||||||
var maybe_load_error: ?anyerror = null;
|
|
||||||
errdefer |err| maybe_load_error = err;
|
|
||||||
|
|
||||||
const data = parseLua(arena_alloc, path) catch load_error: {
|
const data = parseLua(arena_alloc, path) catch load_error: {
|
||||||
break :load_error Struct{};
|
break :load_error Struct{};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var maybe_load_error: ?anyerror = null;
|
||||||
if (global_errors.items.len != 0) {
|
if (global_errors.items.len != 0) {
|
||||||
maybe_load_error = error.InvalidConfig;
|
maybe_load_error = error.InvalidConfig;
|
||||||
}
|
}
|
||||||
@@ -176,8 +174,8 @@ pub fn LuaParser(comptime Struct: type) type {
|
|||||||
defer lua.pop(1); // pop ly table
|
defer lua.pop(1); // pop ly table
|
||||||
if (ly_type == .nil) return error.MissingLyTable;
|
if (ly_type == .nil) return error.MissingLyTable;
|
||||||
|
|
||||||
inline for (struc.fields) |field| {
|
inline for (struc.field_names, struc.field_types) |name, ftype| {
|
||||||
try setField(allocator, lua, field, &data);
|
try setField(allocator, lua, name, ftype, &data);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
else => @compileError("Expected a struct."),
|
else => @compileError("Expected a struct."),
|
||||||
@@ -188,21 +186,47 @@ pub fn LuaParser(comptime Struct: type) type {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn setField(allocator: std.mem.Allocator, lua: *Lua, comptime field: std.builtin.Type.StructField, data: *Struct) !void {
|
pub fn setField(
|
||||||
const type_info = @typeInfo(field.type);
|
allocator: std.mem.Allocator,
|
||||||
|
lua: *Lua,
|
||||||
|
comptime field_name: [:0]const u8,
|
||||||
|
field_type: type,
|
||||||
|
data: *Struct,
|
||||||
|
) !void {
|
||||||
|
return setFieldInner(
|
||||||
|
allocator,
|
||||||
|
lua,
|
||||||
|
field_name,
|
||||||
|
field_type,
|
||||||
|
data,
|
||||||
|
) catch |err| {
|
||||||
|
const value = lua.toString(-1) catch "";
|
||||||
|
const duped = allocator.dupe(u8, value) catch "";
|
||||||
|
errorHandler(@typeName(field_type), field_name, duped, err);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
fn setFieldInner(
|
||||||
|
allocator: std.mem.Allocator,
|
||||||
|
lua: *Lua,
|
||||||
|
comptime field_name: [:0]const u8,
|
||||||
|
field_type: type,
|
||||||
|
data: *Struct,
|
||||||
|
) !void {
|
||||||
|
const type_info = @typeInfo(field_type);
|
||||||
const actual_type, const is_optional = blk: {
|
const actual_type, const is_optional = blk: {
|
||||||
if (type_info == .optional) {
|
if (type_info == .optional) {
|
||||||
break :blk .{ type_info.optional.child, true };
|
break :blk .{ type_info.optional.child, true };
|
||||||
}
|
}
|
||||||
break :blk .{ field.type, false };
|
break :blk .{ field_type, false };
|
||||||
};
|
};
|
||||||
// push value to top of stack
|
// push value to top of stack
|
||||||
_ = lua.getField(-1, field.name);
|
_ = lua.getField(-1, field_name);
|
||||||
defer lua.pop(1);
|
defer lua.pop(1);
|
||||||
|
|
||||||
// handle null, i.e. undefined fields
|
// handle null, i.e. undefined fields
|
||||||
if (is_optional and lua.isNil(-1)) {
|
if (is_optional and lua.isNil(-1)) {
|
||||||
@field(data, field.name) = null;
|
@field(data, field_name) = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,17 +236,11 @@ pub fn LuaParser(comptime Struct: type) type {
|
|||||||
}
|
}
|
||||||
const actual_type_info = @typeInfo(actual_type);
|
const actual_type_info = @typeInfo(actual_type);
|
||||||
|
|
||||||
errdefer |err| {
|
|
||||||
const value = lua.toString(-1) catch "";
|
|
||||||
const duped = allocator.dupe(u8, value) catch "";
|
|
||||||
errorHandler(@typeName(field.type), field.name, duped, err);
|
|
||||||
}
|
|
||||||
|
|
||||||
// dispatch depending on type
|
// dispatch depending on type
|
||||||
if (actual_type_info == .int and is_optional) {
|
if (actual_type_info == .int and is_optional) {
|
||||||
if (lua.isNumber(-1)) {
|
if (lua.isNumber(-1)) {
|
||||||
const value = try lua.toNumber(-1);
|
const value = try lua.toNumber(-1);
|
||||||
@field(data, field.name) = @trunc(value);
|
@field(data, field_name) = @trunc(value);
|
||||||
} else {
|
} else {
|
||||||
const str = try lua.toString(-1);
|
const str = try lua.toString(-1);
|
||||||
|
|
||||||
@@ -233,13 +251,13 @@ pub fn LuaParser(comptime Struct: type) type {
|
|||||||
|
|
||||||
if (iter.nextCodepoint() != null) return error.ExpectedSingleCharacter;
|
if (iter.nextCodepoint() != null) return error.ExpectedSingleCharacter;
|
||||||
|
|
||||||
@field(data, field.name) = if (codepoint) |cp| @intCast(cp) else null;
|
@field(data, field_name) = if (codepoint) |cp| @intCast(cp) else null;
|
||||||
}
|
}
|
||||||
// non null integer
|
// non null integer
|
||||||
} else if (actual_type_info == .int) {
|
} else if (actual_type_info == .int) {
|
||||||
if (lua.isNumber(-1)) {
|
if (lua.isNumber(-1)) {
|
||||||
const value = try lua.toNumber(-1);
|
const value = try lua.toNumber(-1);
|
||||||
@field(data, field.name) = @trunc(value);
|
@field(data, field_name) = @trunc(value);
|
||||||
} else {
|
} else {
|
||||||
const str = try lua.toString(-1);
|
const str = try lua.toString(-1);
|
||||||
|
|
||||||
@@ -250,27 +268,27 @@ pub fn LuaParser(comptime Struct: type) type {
|
|||||||
|
|
||||||
if (iter.nextCodepoint() != null) return error.ExpectedSingleCharacter;
|
if (iter.nextCodepoint() != null) return error.ExpectedSingleCharacter;
|
||||||
|
|
||||||
@field(data, field.name) = @intCast(codepoint);
|
@field(data, field_name) = @intCast(codepoint);
|
||||||
}
|
}
|
||||||
} else if (actual_type_info == .float) { // all floats
|
} else if (actual_type_info == .float) { // all floats
|
||||||
const value = try lua.toNumber(-1);
|
const value = try lua.toNumber(-1);
|
||||||
@field(data, field.name) = @floatCast(value);
|
@field(data, field_name) = @floatCast(value);
|
||||||
} else if (actual_type_info == .bool) {
|
} else if (actual_type_info == .bool) {
|
||||||
if (!lua.isBoolean(-1)) return error.ExpectedBoolean;
|
if (!lua.isBoolean(-1)) return error.ExpectedBoolean;
|
||||||
const value = lua.toBoolean(-1);
|
const value = lua.toBoolean(-1);
|
||||||
@field(data, field.name) = value;
|
@field(data, field_name) = value;
|
||||||
} else if (actual_type == []const u8) {
|
} else if (actual_type == []const u8) {
|
||||||
const value = try lua.toString(-1);
|
const value = try lua.toString(-1);
|
||||||
const duped = try allocator.dupe(u8, value);
|
const duped = try allocator.dupe(u8, value);
|
||||||
@field(data, field.name) = duped;
|
@field(data, field_name) = duped;
|
||||||
} else if (actual_type == [:0]const u8) {
|
} else if (actual_type == [:0]const u8) {
|
||||||
const value = try lua.toString(-1);
|
const value = try lua.toString(-1);
|
||||||
const duped = try allocator.dupeSentinel(u8, value, 0);
|
const duped = try allocator.dupeSentinel(u8, value, 0);
|
||||||
@field(data, field.name) = duped;
|
@field(data, field_name) = duped;
|
||||||
} else if (actual_type_info == .@"enum") {
|
} else if (actual_type_info == .@"enum") {
|
||||||
const value = try lua.toString(-1);
|
const value = try lua.toString(-1);
|
||||||
const variant = std.meta.stringToEnum(actual_type, value) orelse return error.InvalidVariant;
|
const variant = std.meta.stringToEnum(actual_type, value) orelse return error.InvalidVariant;
|
||||||
@field(data, field.name) = variant;
|
@field(data, field_name) = variant;
|
||||||
} else unreachable;
|
} else unreachable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,9 +28,7 @@ pub fn build(b: *std.Build) void {
|
|||||||
.optimize = optimize,
|
.optimize = optimize,
|
||||||
});
|
});
|
||||||
|
|
||||||
const translate_c_dep = b.dependency("translate_c", .{
|
const translate_c_dep = b.dependency("translate_c", .{});
|
||||||
.target = target,
|
|
||||||
});
|
|
||||||
|
|
||||||
const termbox2: Translator = .init(translate_c_dep, .{
|
const termbox2: Translator = .init(translate_c_dep, .{
|
||||||
.c_source_file = termbox_dep.path("termbox2.h"),
|
.c_source_file = termbox_dep.path("termbox2.h"),
|
||||||
@@ -38,18 +36,7 @@ pub fn build(b: *std.Build) void {
|
|||||||
.optimize = optimize,
|
.optimize = optimize,
|
||||||
});
|
});
|
||||||
termbox2.defineCMacro("TB_IMPL", null);
|
termbox2.defineCMacro("TB_IMPL", null);
|
||||||
// TODO 0.16.0: Workaround until Aro gets better...
|
|
||||||
// https://codeberg.org/ziglang/translate-c/issues/319
|
|
||||||
termbox2.defineCMacro("_XOPEN_SOURCE", "700");
|
|
||||||
termbox2.defineCMacro("TB_OPT_ATTR_W", "32"); // Enable 24-bit color support + styling (32-bit)
|
termbox2.defineCMacro("TB_OPT_ATTR_W", "32"); // Enable 24-bit color support + styling (32-bit)
|
||||||
// TODO 0.16.0: Including <fcntl.h> with -OReleaseSafe causes
|
|
||||||
// __attribute__(__error__()) to be called. Below
|
|
||||||
// is the workaround.
|
|
||||||
termbox2.defineCMacro("_FORTIFY_SOURCE", "0");
|
|
||||||
// TODO 0.16.0: Needed for now
|
|
||||||
if (target.result.os.tag == .freebsd) {
|
|
||||||
termbox2.defineCMacro("__BSD_VISIBLE", "1");
|
|
||||||
}
|
|
||||||
mod.addImport("termbox2", termbox2.mod);
|
mod.addImport("termbox2", termbox2.mod);
|
||||||
|
|
||||||
const mod_tests = b.addTest(.{
|
const mod_tests = b.addTest(.{
|
||||||
|
|||||||
@@ -2,18 +2,18 @@
|
|||||||
.name = .ly_ui,
|
.name = .ly_ui,
|
||||||
.version = "1.2.0",
|
.version = "1.2.0",
|
||||||
.fingerprint = 0x8d11bf85a74ec803,
|
.fingerprint = 0x8d11bf85a74ec803,
|
||||||
.minimum_zig_version = "0.16.0",
|
.minimum_zig_version = "0.17.0",
|
||||||
.dependencies = .{
|
.dependencies = .{
|
||||||
.ly_core = .{
|
.ly_core = .{
|
||||||
.path = "../ly-core",
|
.path = "../ly-core",
|
||||||
},
|
},
|
||||||
.termbox2 = .{
|
.termbox2 = .{
|
||||||
.url = "git+https://github.com/AnErrupTion/termbox2?ref=master#c7f241e8888ce243e1748b05c26a42fcfaaad936",
|
.url = "git+https://github.com/AnErrupTion/termbox2?ref=master#496730697c662893eec43192f48ff616c2539da6",
|
||||||
.hash = "N-V-__8AAAUXBQD6Fwpi9m0MBqWXFFaqW5l1lVrJC2Ynj7a-",
|
.hash = "N-V-__8AAOEWBQDt5tNdIzIFY6n8DdZsCP-6MyLoNS20wgpA",
|
||||||
},
|
},
|
||||||
.translate_c = .{
|
.translate_c = .{
|
||||||
.url = "git+https://codeberg.org/ziglang/translate-c?ref=zig-0.16.x#6fe0ffc4549f15c5f2d9432c2b4460ba90ff85ac",
|
.url = "git+https://codeberg.org/ziglang/translate-c?ref=master#3da873cacdd7e9190fe1cf40372ddf5387c970ea",
|
||||||
.hash = "translate_c-1.0.0-Q_BUWo_5BgD4flHdUhA31zOz0XvZk9k7lQv1ouzyNXj2",
|
.hash = "translate_c-0.0.0-Q_BUWktLBwBO7VLbmrOKUcAMRtE5fmOxI35189X5XbJs",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
.paths = .{
|
.paths = .{
|
||||||
|
|||||||
26
src/auth.zig
26
src/auth.zig
@@ -57,7 +57,7 @@ pub fn authenticate(
|
|||||||
const tty_str = try std.fmt.bufPrint(&tty_buffer, "{d}", .{options.tty});
|
const tty_str = try std.fmt.bufPrint(&tty_buffer, "{d}", .{options.tty});
|
||||||
|
|
||||||
var pam_tty_buffer: [6]u8 = undefined;
|
var pam_tty_buffer: [6]u8 = undefined;
|
||||||
const pam_tty_str = try std.fmt.bufPrintZ(&pam_tty_buffer, "tty{d}", .{options.tty});
|
const pam_tty_str = try std.fmt.bufPrintSentinel(&pam_tty_buffer, "tty{d}", .{options.tty}, 0);
|
||||||
|
|
||||||
// Set the XDG environment variables
|
// Set the XDG environment variables
|
||||||
try log_file.info(io, "auth/env", "setting xdg environment variables", .{});
|
try log_file.info(io, "auth/env", "setting xdg environment variables", .{});
|
||||||
@@ -221,7 +221,7 @@ fn startSession(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const home_z = try allocator.dupeZ(u8, user_entry.home.?);
|
const home_z = try allocator.dupeSentinel(u8, user_entry.home.?, 0);
|
||||||
defer allocator.free(home_z);
|
defer allocator.free(home_z);
|
||||||
|
|
||||||
// Change to the user's home directory
|
// Change to the user's home directory
|
||||||
@@ -326,7 +326,7 @@ fn loginConv(
|
|||||||
for (0..message_count) |i| set_credentials: {
|
for (0..message_count) |i| set_credentials: {
|
||||||
switch (messages[i].?.msg_style) {
|
switch (messages[i].?.msg_style) {
|
||||||
interop.pam.PAM_PROMPT_ECHO_ON => {
|
interop.pam.PAM_PROMPT_ECHO_ON => {
|
||||||
username = allocator.dupeZ(u8, data.username) catch {
|
username = allocator.dupeSentinel(u8, data.username, 0) catch {
|
||||||
status = interop.pam.PAM_BUF_ERR;
|
status = interop.pam.PAM_BUF_ERR;
|
||||||
break :set_credentials;
|
break :set_credentials;
|
||||||
};
|
};
|
||||||
@@ -341,7 +341,7 @@ fn loginConv(
|
|||||||
data.authreq_responded = true;
|
data.authreq_responded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
password = allocator.dupeZ(u8, pass) catch {
|
password = allocator.dupeSentinel(u8, pass, 0) catch {
|
||||||
status = interop.pam.PAM_BUF_ERR;
|
status = interop.pam.PAM_BUF_ERR;
|
||||||
break :set_credentials;
|
break :set_credentials;
|
||||||
};
|
};
|
||||||
@@ -362,7 +362,7 @@ fn getFreeDisplay() !u8 {
|
|||||||
var buf: [15]u8 = undefined;
|
var buf: [15]u8 = undefined;
|
||||||
var i: u8 = 0;
|
var i: u8 = 0;
|
||||||
while (i < 200) : (i += 1) {
|
while (i < 200) : (i += 1) {
|
||||||
const xlock = try std.fmt.bufPrintZ(&buf, "/tmp/.X{d}-lock", .{i});
|
const xlock = try std.fmt.bufPrintSentinel(&buf, "/tmp/.X{d}-lock", .{i}, 0);
|
||||||
if (interop.isError(std.posix.system.access(xlock.ptr, std.posix.F_OK))) break;
|
if (interop.isError(std.posix.system.access(xlock.ptr, std.posix.F_OK))) break;
|
||||||
}
|
}
|
||||||
return i;
|
return i;
|
||||||
@@ -463,7 +463,7 @@ fn xauth(log_file: *LogFile, allocator: std.mem.Allocator, io: std.Io, display_n
|
|||||||
try log_file.reinit(io);
|
try log_file.reinit(io);
|
||||||
|
|
||||||
var cmd_buffer: [1024]u8 = undefined;
|
var cmd_buffer: [1024]u8 = undefined;
|
||||||
const cmd_str = std.fmt.bufPrintZ(&cmd_buffer, "{s} add {s} . {s}", .{ options.xauth_cmd, display_name, magic_cookie }) catch std.process.exit(1);
|
const cmd_str = std.fmt.bufPrintSentinel(&cmd_buffer, "{s} add {s} . {s}", .{ options.xauth_cmd, display_name, magic_cookie }, 0) catch std.process.exit(1);
|
||||||
|
|
||||||
try log_file.info(io, "auth/x11", "executing: {s} -c {s}", .{ shell, cmd_str });
|
try log_file.info(io, "auth/x11", "executing: {s} -c {s}", .{ shell, cmd_str });
|
||||||
const args = [_:null]?[*:0]const u8{ shell, "-c", cmd_str };
|
const args = [_:null]?[*:0]const u8{ shell, "-c", cmd_str };
|
||||||
@@ -499,7 +499,7 @@ fn executeX11Cmd(log_file: *LogFile, allocator: std.mem.Allocator, io: std.Io, s
|
|||||||
const display_name = try std.fmt.bufPrint(&buf, ":{d}", .{display_num});
|
const display_name = try std.fmt.bufPrint(&buf, ":{d}", .{display_num});
|
||||||
try log_file.info(io, "auth/x11", "got free display: {d}", .{display_num});
|
try log_file.info(io, "auth/x11", "got free display: {d}", .{display_num});
|
||||||
|
|
||||||
const shell_z = try allocator.dupeZ(u8, shell);
|
const shell_z = try allocator.dupeSentinel(u8, shell, 0);
|
||||||
defer allocator.free(shell_z);
|
defer allocator.free(shell_z);
|
||||||
|
|
||||||
try log_file.info(io, "auth/x11", "creating xauth file", .{});
|
try log_file.info(io, "auth/x11", "creating xauth file", .{});
|
||||||
@@ -509,7 +509,7 @@ fn executeX11Cmd(log_file: *LogFile, allocator: std.mem.Allocator, io: std.Io, s
|
|||||||
const pid = std.posix.system.fork();
|
const pid = std.posix.system.fork();
|
||||||
if (pid == 0) {
|
if (pid == 0) {
|
||||||
var cmd_buffer: [1024]u8 = undefined;
|
var cmd_buffer: [1024]u8 = undefined;
|
||||||
const cmd_str = std.fmt.bufPrintZ(&cmd_buffer, "{s} {s} {s} -auth {s}", .{ options.x_cmd, display_name, vt, xauthority }) catch std.process.exit(1);
|
const cmd_str = std.fmt.bufPrintSentinel(&cmd_buffer, "{s} {s} {s} -auth {s}", .{ options.x_cmd, display_name, vt, xauthority }, 0) catch std.process.exit(1);
|
||||||
try log_file.info(io, "auth/x11", "executing: {s} -c {s} -auth {s}", .{ shell, cmd_str, xauthority });
|
try log_file.info(io, "auth/x11", "executing: {s} -c {s} -auth {s}", .{ shell, cmd_str, xauthority });
|
||||||
|
|
||||||
const args = [_:null]?[*:0]const u8{ shell_z, "-c", cmd_str };
|
const args = [_:null]?[*:0]const u8{ shell_z, "-c", cmd_str };
|
||||||
@@ -538,7 +538,7 @@ fn executeX11Cmd(log_file: *LogFile, allocator: std.mem.Allocator, io: std.Io, s
|
|||||||
xorg_pid = std.posix.system.fork();
|
xorg_pid = std.posix.system.fork();
|
||||||
if (xorg_pid == 0) {
|
if (xorg_pid == 0) {
|
||||||
var cmd_buffer: [1024]u8 = undefined;
|
var cmd_buffer: [1024]u8 = undefined;
|
||||||
const cmd_str = std.fmt.bufPrintZ(&cmd_buffer, "{s} {s} {s} {s}", .{ if (options.use_kmscon_vt) "kmscon-launch-gui" else "", options.setup_cmd, options.login_cmd orelse "", desktop_cmd }) catch std.process.exit(1);
|
const cmd_str = std.fmt.bufPrintSentinel(&cmd_buffer, "{s} {s} {s} {s}", .{ if (options.use_kmscon_vt) "kmscon-launch-gui" else "", options.setup_cmd, options.login_cmd orelse "", desktop_cmd }, 0) catch std.process.exit(1);
|
||||||
try log_file.info(io, "auth/x11", "executing: {s} -c {s}", .{ shell, cmd_str });
|
try log_file.info(io, "auth/x11", "executing: {s} -c {s}", .{ shell, cmd_str });
|
||||||
|
|
||||||
const args = [_:null]?[*:0]const u8{ shell_z, "-c", cmd_str };
|
const args = [_:null]?[*:0]const u8{ shell_z, "-c", cmd_str };
|
||||||
@@ -589,11 +589,11 @@ fn executeCmd(global_log_file: *LogFile, allocator: std.mem.Allocator, io: std.I
|
|||||||
}
|
}
|
||||||
defer if (maybe_log_file) |log_file| log_file.close(io);
|
defer if (maybe_log_file) |log_file| log_file.close(io);
|
||||||
|
|
||||||
const shell_z = try allocator.dupeZ(u8, shell);
|
const shell_z = try allocator.dupeSentinel(u8, shell, 0);
|
||||||
defer allocator.free(shell_z);
|
defer allocator.free(shell_z);
|
||||||
|
|
||||||
var cmd_buffer: [1024]u8 = undefined;
|
var cmd_buffer: [1024]u8 = undefined;
|
||||||
const cmd_str = try std.fmt.bufPrintZ(&cmd_buffer, "{s} {s} {s} {s}", .{ if (!is_terminal and options.use_kmscon_vt) "kmscon-launch-gui" else "", options.setup_cmd, options.login_cmd orelse "", exec_cmd orelse shell });
|
const cmd_str = try std.fmt.bufPrintSentinel(&cmd_buffer, "{s} {s} {s} {s}", .{ if (!is_terminal and options.use_kmscon_vt) "kmscon-launch-gui" else "", options.setup_cmd, options.login_cmd orelse "", exec_cmd orelse shell }, 0);
|
||||||
|
|
||||||
try global_log_file.info(io, "auth/sys", "executing: {s} -c {s}", .{ shell, cmd_str });
|
try global_log_file.info(io, "auth/sys", "executing: {s} -c {s}", .{ shell, cmd_str });
|
||||||
const args = [_:null]?[*:0]const u8{ shell_z, "-c", cmd_str };
|
const args = [_:null]?[*:0]const u8{ shell_z, "-c", cmd_str };
|
||||||
@@ -642,7 +642,7 @@ fn addUtmpEntry(io: std.Io, entry: *Utmp, username: []const u8, pid: c_int) !voi
|
|||||||
|
|
||||||
// Get the TTY name (i.e. without the /dev/ prefix)
|
// Get the TTY name (i.e. without the /dev/ prefix)
|
||||||
var ttyname_buf: [@sizeOf(@TypeOf(entry.ut_line))]u8 = undefined;
|
var ttyname_buf: [@sizeOf(@TypeOf(entry.ut_line))]u8 = undefined;
|
||||||
_ = try std.fmt.bufPrintZ(&ttyname_buf, "{s}", .{tty_path["/dev/".len..]});
|
_ = try std.fmt.bufPrintSentinel(&ttyname_buf, "{s}", .{tty_path["/dev/".len..]}, 0);
|
||||||
|
|
||||||
entry.ut_line = ttyname_buf;
|
entry.ut_line = ttyname_buf;
|
||||||
// Get the TTY ID (i.e. without the tty prefix) and truncate it to the size
|
// Get the TTY ID (i.e. without the tty prefix) and truncate it to the size
|
||||||
@@ -650,7 +650,7 @@ fn addUtmpEntry(io: std.Io, entry: *Utmp, username: []const u8, pid: c_int) !voi
|
|||||||
entry.ut_id = ttyname_buf["tty".len..(@sizeOf(@TypeOf(entry.ut_id)) + "tty".len)].*;
|
entry.ut_id = ttyname_buf["tty".len..(@sizeOf(@TypeOf(entry.ut_id)) + "tty".len)].*;
|
||||||
|
|
||||||
var username_buf: [@sizeOf(@TypeOf(entry.ut_user))]u8 = undefined;
|
var username_buf: [@sizeOf(@TypeOf(entry.ut_user))]u8 = undefined;
|
||||||
_ = try std.fmt.bufPrintZ(&username_buf, "{s}", .{username});
|
_ = try std.fmt.bufPrintSentinel(&username_buf, "{s}", .{username}, 0);
|
||||||
|
|
||||||
entry.ut_user = username_buf;
|
entry.ut_user = username_buf;
|
||||||
|
|
||||||
|
|||||||
13
src/main.zig
13
src/main.zig
@@ -154,8 +154,8 @@ pub fn main(init: std.process.Init) !void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var gpa: std.heap.DebugAllocator(.{
|
var gpa: std.heap.DebugAllocator(.{
|
||||||
.never_unmap = builtin.mode == .Debug,
|
.never_unmap = builtin.mode == .debug,
|
||||||
.retain_metadata = builtin.mode == .Debug,
|
.retain_metadata = builtin.mode == .debug,
|
||||||
}) = .init;
|
}) = .init;
|
||||||
defer if (gpa.deinit() == .leak) std.log.err("attention please, memory has been leaked!", .{});
|
defer if (gpa.deinit() == .leak) std.log.err("attention please, memory has been leaked!", .{});
|
||||||
|
|
||||||
@@ -333,7 +333,7 @@ pub fn main(init: std.process.Init) !void {
|
|||||||
|
|
||||||
const username_line = reader.takeDelimiterInclusive('\n') catch break :read_save_file;
|
const username_line = reader.takeDelimiterInclusive('\n') catch break :read_save_file;
|
||||||
|
|
||||||
if (std.mem.containsAtLeastScalar2(u8, username_line, '-', 1)) read_username: {
|
if (std.mem.containsAtLeastScalar(u8, username_line, '-', 1)) read_username: {
|
||||||
var iterator = std.mem.splitScalar(u8, username_line[0..(username_line.len - 1)], '-');
|
var iterator = std.mem.splitScalar(u8, username_line[0..(username_line.len - 1)], '-');
|
||||||
if (iterator.next() == null) break :read_username; // Would be index
|
if (iterator.next() == null) break :read_username; // Would be index
|
||||||
|
|
||||||
@@ -1237,8 +1237,8 @@ pub fn main(init: std.process.Init) !void {
|
|||||||
var iter = custom.binds.iterator();
|
var iter = custom.binds.iterator();
|
||||||
while (iter.next()) |i| {
|
while (iter.next()) |i| {
|
||||||
var concat = try std.mem.concat(state.allocator, u8, &[_][]const u8{ i.key_ptr.*, " ", i.value_ptr.name });
|
var concat = try std.mem.concat(state.allocator, u8, &[_][]const u8{ i.key_ptr.*, " ", i.value_ptr.name });
|
||||||
inline for (@typeInfo(Lang).@"struct".fields) |lang_key| {
|
inline for (@typeInfo(Lang).@"struct".field_names) |lang_key| {
|
||||||
const new = try std.mem.replaceOwned(u8, state.allocator, concat, "$" ++ lang_key.name, @field(state.lang, lang_key.name));
|
const new = try std.mem.replaceOwned(u8, state.allocator, concat, "$" ++ lang_key, @field(state.lang, lang_key));
|
||||||
state.allocator.free(concat);
|
state.allocator.free(concat);
|
||||||
concat = new;
|
concat = new;
|
||||||
}
|
}
|
||||||
@@ -1926,7 +1926,7 @@ fn updateBigClock(self: *BigLabel, ptr: *anyopaque) !void {
|
|||||||
const time = try interop.getTimeOfDay();
|
const time = try interop.getTimeOfDay();
|
||||||
const animate_time = @divTrunc(time.microseconds, 500_000);
|
const animate_time = @divTrunc(time.microseconds, 500_000);
|
||||||
const separator = if (state.animate and animate_time != 0) " " else ":";
|
const separator = if (state.animate and animate_time != 0) " " else ":";
|
||||||
const format = try std.fmt.bufPrintZ(
|
const format = try std.fmt.bufPrintSentinel(
|
||||||
&state.bigclock_format_buf,
|
&state.bigclock_format_buf,
|
||||||
"{s}{s}{s}{s}{s}{s}",
|
"{s}{s}{s}{s}{s}{s}",
|
||||||
.{
|
.{
|
||||||
@@ -1937,6 +1937,7 @@ fn updateBigClock(self: *BigLabel, ptr: *anyopaque) !void {
|
|||||||
if (state.config.bigclock_seconds) "%S" else "",
|
if (state.config.bigclock_seconds) "%S" else "",
|
||||||
if (state.config.bigclock_12hr) "%P" else "",
|
if (state.config.bigclock_12hr) "%P" else "",
|
||||||
},
|
},
|
||||||
|
0,
|
||||||
);
|
);
|
||||||
|
|
||||||
const clock_str = interop.timeAsString(state.io, &state.bigclock_buf, format);
|
const clock_str = interop.timeAsString(state.io, &state.bigclock_buf, format);
|
||||||
|
|||||||
Reference in New Issue
Block a user