Remove tput dependency & use termbox2 instead

Signed-off-by: AnErrupTion <anerruption@disroot.org>
This commit is contained in:
AnErrupTion 2024-08-03 21:48:38 +02:00
parent 0bbe9c78dd
commit b73c78d2fb
No known key found for this signature in database
GPG Key ID: 3E85EB44F610AD7F
6 changed files with 12 additions and 30 deletions

View File

@ -13,8 +13,6 @@ Ly is a lightweight TUI (ncurses-like) display manager for Linux and BSD.
- Runtime (with default config):
- xorg
- xorg-xauth
- mcookie
- tput
- shutdown
### Debian

View File

@ -155,12 +155,6 @@ numlock = false
# Service name (set to ly to use the provided pam config file)
service_name = ly
# Terminal reset command (tput is faster)
term_reset_cmd = $PREFIX_DIRECTORY/bin/tput reset
# Terminal restore cursor command
term_restore_cursor_cmd = $PREFIX_DIRECTORY/bin/tput cnorm
# Wayland setup command
wayland_cmd = $CONFIG_DIRECTORY/ly/wsetup.sh

View File

@ -117,7 +117,9 @@ pub fn authenticate(config: Config, current_environment: Session.Environment, lo
removeUtmpEntry(&entry);
try resetTerminal(pwd.pw_shell.?, config.term_reset_cmd);
// Take back control of the TTY
_ = interop.termbox.tb_init();
_ = interop.termbox.tb_set_output_mode(interop.termbox.TB_OUTPUT_NORMAL);
if (shared_err.readError()) |err| return err;
}
@ -157,7 +159,8 @@ fn startSession(
// Execute what the user requested
std.posix.chdirZ(pwd.pw_dir.?) catch return error.ChangeDirectoryFailed;
try resetTerminal(pwd.pw_shell.?, config.term_reset_cmd);
// Give up control on the TTY
_ = interop.termbox.tb_shutdown();
switch (current_environment.display_server) {
.wayland => try executeWaylandCmd(pwd.pw_shell.?, config.wayland_cmd, current_environment.cmd),
@ -270,17 +273,6 @@ fn loginConv(
return status;
}
fn resetTerminal(shell: [*:0]const u8, term_reset_cmd: [:0]const u8) !void {
const pid = try std.posix.fork();
if (pid == 0) {
const args = [_:null]?[*:0]const u8{ shell, "-c", term_reset_cmd };
std.posix.execveZ(shell, &args, std.c.environ) catch {};
std.process.exit(1);
}
_ = std.posix.waitpid(pid, 0);
}
fn getFreeDisplay() !u8 {
var buf: [15]u8 = undefined;
var i: u8 = 0;

View File

@ -41,8 +41,6 @@ shutdown_cmd: []const u8 = "/sbin/shutdown -a now",
shutdown_key: []const u8 = "F1",
sleep_cmd: ?[]const u8 = null,
sleep_key: []const u8 = "F3",
term_reset_cmd: [:0]const u8 = build_options.prefix_directory ++ "/bin/tput reset",
term_restore_cursor_cmd: []const u8 = build_options.prefix_directory ++ "/bin/tput cnorm",
tty: u8 = build_options.tty,
vi_mode: bool = false,
vi_default_mode: ViMode = .normal,

View File

@ -63,7 +63,9 @@ pub fn configFieldHandler(_: std.mem.Allocator, field: ini.IniField) ?ini.IniFie
std.mem.eql(u8, field.key, "max_desktop_len") or
std.mem.eql(u8, field.key, "max_login_len") or
std.mem.eql(u8, field.key, "max_password_len") or
std.mem.eql(u8, field.key, "mcookie_cmd"))
std.mem.eql(u8, field.key, "mcookie_cmd") or
std.mem.eql(u8, field.key, "term_reset_cmd") or
std.mem.eql(u8, field.key, "term_restore_cursor_cmd"))
{
// The options don't exist anymore
mapped_config_fields = true;

View File

@ -712,15 +712,13 @@ pub fn main() !void {
}
try std.posix.tcsetattr(std.posix.STDIN_FILENO, .FLUSH, tb_termios);
if (auth_fails < config.auth_fails) {
_ = termbox.tb_clear();
_ = termbox.tb_present();
}
if (auth_fails < config.auth_fails) _ = termbox.tb_clear();
update = true;
var restore_cursor = std.process.Child.init(&[_][]const u8{ "/bin/sh", "-c", config.term_restore_cursor_cmd }, allocator);
_ = restore_cursor.spawnAndWait() catch .{};
// Restore the cursor
_ = termbox.tb_set_cursor(0, 0);
_ = termbox.tb_present();
},
else => {
if (!insert_mode) {