mirror of https://github.com/fairyglade/ly.git
				
				
				
			make long lines shorter and add changelog
This commit is contained in:
		
							parent
							
								
									6a41bcf13a
								
							
						
					
					
						commit
						f904be8fc0
					
				|  | @ -0,0 +1,41 @@ | ||||||
|  | # Zig Rewrite | ||||||
|  | 
 | ||||||
|  | ## Config Options | ||||||
|  | 
 | ||||||
|  | res/config.ini contains all of the available config options and their default values. | ||||||
|  | 
 | ||||||
|  | ### Additions | ||||||
|  | 
 | ||||||
|  | + border\_fg has been introduced to change the color of the borders. | ||||||
|  | + term\_restore\_cursor\_cmd should restore the cursor to it's usual state. | ||||||
|  | + sleep\_key and sleep\_cmd. | ||||||
|  | + log\_path is used to store ly.log and ly.log.old for debugging purposes (pretty much nothing is logged currently). | ||||||
|  | 
 | ||||||
|  | Note: sleep\_cmd is unset by default, meaning it's hidden and has no effect.  | ||||||
|  | 
 | ||||||
|  | ### Changes | ||||||
|  | 
 | ||||||
|  | + xinitrc can be set to null to hide it. | ||||||
|  | + blank\_password has been renamed to clear\_password. | ||||||
|  | 
 | ||||||
|  | ### Removals | ||||||
|  | 
 | ||||||
|  | + wayland\_specifier has been removed. | ||||||
|  | 
 | ||||||
|  | ## Save File | ||||||
|  | 
 | ||||||
|  | The save file is now in .ini format. | ||||||
|  | 
 | ||||||
|  | Example: | ||||||
|  | 
 | ||||||
|  | ```ini | ||||||
|  | user = ash | ||||||
|  | session_index = 0 | ||||||
|  | ``` | ||||||
|  | 
 | ||||||
|  | ## Misc | ||||||
|  | 
 | ||||||
|  | + getty@tty2 has been added as a conflict in res/ly.service, so if it is running, ly should still be able to start. | ||||||
|  | + XDG\_CURRENT\_DESKTOP is now set by ly. | ||||||
|  | + LANG is no longer set by ly. | ||||||
|  | + X Server PID is fetched from /tmp/X{d}.lock to be able to kill the process since it detaches. | ||||||
|  | @ -85,6 +85,7 @@ shutdown_key = F1 | ||||||
| # Specifies the key used for restart (F1-F12) | # Specifies the key used for restart (F1-F12) | ||||||
| restart_key = F2 | restart_key = F2 | ||||||
| 
 | 
 | ||||||
|  | # Specifies the key used for sleep (F1-F12) | ||||||
| sleep_key = F3 | sleep_key = F3 | ||||||
| 
 | 
 | ||||||
| # Command executed when pressing shutdown_key | # Command executed when pressing shutdown_key | ||||||
|  |  | ||||||
							
								
								
									
										16
									
								
								src/auth.zig
								
								
								
								
							
							
						
						
									
										16
									
								
								src/auth.zig
								
								
								
								
							|  | @ -8,7 +8,6 @@ const Config = @import("config/Config.zig"); | ||||||
| const Allocator = std.mem.Allocator; | const Allocator = std.mem.Allocator; | ||||||
| const utmp = interop.utmp; | const utmp = interop.utmp; | ||||||
| const Utmp = utmp.utmp; | const Utmp = utmp.utmp; | ||||||
| //const LogFile = @import("logger/LogFile.zig"); |  | ||||||
| 
 | 
 | ||||||
| pub fn authenticate( | pub fn authenticate( | ||||||
|     allocator: Allocator, |     allocator: Allocator, | ||||||
|  | @ -142,7 +141,7 @@ pub fn authenticate( | ||||||
|             .xinitrc, .x11 => { |             .xinitrc, .x11 => { | ||||||
|                 var vt_buf: [5]u8 = undefined; |                 var vt_buf: [5]u8 = undefined; | ||||||
|                 const vt = try std.fmt.bufPrint(&vt_buf, "vt{d}", .{config.tty}); |                 const vt = try std.fmt.bufPrint(&vt_buf, "vt{d}", .{config.tty}); | ||||||
|                 try executeX11Cmd(pwd.pw_shell, pwd.pw_dir, config.x_cmd, config.x_cmd_setup, current_environment.cmd, config.xauth_cmd, config.mcookie_cmd, vt); |                 try executeX11Cmd(pwd.pw_shell, pwd.pw_dir, config, current_environment.cmd, vt); | ||||||
|             }, |             }, | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  | @ -172,12 +171,10 @@ pub fn authenticate( | ||||||
| 
 | 
 | ||||||
| fn initEnv(allocator: Allocator, pwd: *interop.passwd, path: ?[]const u8) !void { | fn initEnv(allocator: Allocator, pwd: *interop.passwd, path: ?[]const u8) !void { | ||||||
|     const term = interop.getenv("TERM"); |     const term = interop.getenv("TERM"); | ||||||
|     //const lang = interop.getenv("LANG"); |  | ||||||
| 
 | 
 | ||||||
|     _ = interop.clearenv(); |     _ = interop.clearenv(); | ||||||
| 
 | 
 | ||||||
|     if (term[0] != 0) _ = interop.setenv("TERM", term, 1); |     if (term[0] != 0) _ = interop.setenv("TERM", term, 1); | ||||||
|     //if (lang[0] != 0) _ = interop.setenv("LANG", lang, 1); |  | ||||||
|     _ = interop.setenv("HOME", pwd.pw_dir, 1); |     _ = interop.setenv("HOME", pwd.pw_dir, 1); | ||||||
|     _ = interop.setenv("PWD", pwd.pw_dir, 1); |     _ = interop.setenv("PWD", pwd.pw_dir, 1); | ||||||
|     _ = interop.setenv("SHELL", pwd.pw_shell, 1); |     _ = interop.setenv("SHELL", pwd.pw_shell, 1); | ||||||
|  | @ -375,16 +372,16 @@ fn executeWaylandCmd(shell: [*:0]const u8, wayland_cmd: []const u8, desktop_cmd: | ||||||
|     _ = interop.execl(shell, shell, "-c", cmd_str.ptr, @as([*c]const u8, 0)); |     _ = interop.execl(shell, shell, "-c", cmd_str.ptr, @as([*c]const u8, 0)); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| fn executeX11Cmd(shell: [*:0]const u8, pw_dir: [*:0]const u8, x_cmd: []const u8, x_cmd_setup: []const u8, desktop_cmd: []const u8, xauth_cmd: []const u8, mcookie_cmd: []const u8, vt: []const u8) !void { | fn executeX11Cmd(shell: [*:0]const u8, pw_dir: [*:0]const u8, config: Config, desktop_cmd: []const u8, vt: []const u8) !void { | ||||||
|     const display_num = try getFreeDisplay(); |     const display_num = try getFreeDisplay(); | ||||||
|     var buf: [5]u8 = undefined; |     var buf: [5]u8 = undefined; | ||||||
|     var display_name: [:0]u8 = try std.fmt.bufPrintZ(&buf, ":{d}", .{display_num}); |     var display_name: [:0]u8 = try std.fmt.bufPrintZ(&buf, ":{d}", .{display_num}); | ||||||
|     try xauth(display_name, shell, pw_dir, xauth_cmd, mcookie_cmd); |     try xauth(display_name, shell, pw_dir, config.xauth_cmd, config.mcookie_cmd); | ||||||
| 
 | 
 | ||||||
|     const pid = std.c.fork(); |     const pid = std.c.fork(); | ||||||
|     if (pid == 0) { |     if (pid == 0) { | ||||||
|         var cmd_buffer = std.mem.zeroes([1024]u8); |         var cmd_buffer = std.mem.zeroes([1024]u8); | ||||||
|         const cmd_str = try std.fmt.bufPrintZ(&cmd_buffer, "{s} {s} {s}", .{ x_cmd, display_name, vt }); |         const cmd_str = try std.fmt.bufPrintZ(&cmd_buffer, "{s} {s} {s}", .{ config.x_cmd, display_name, vt }); | ||||||
|         _ = interop.execl(shell, shell, "-c", cmd_str.ptr, @as([*c]const u8, 0)); |         _ = interop.execl(shell, shell, "-c", cmd_str.ptr, @as([*c]const u8, 0)); | ||||||
|         std.os.exit(0); |         std.os.exit(0); | ||||||
|     } |     } | ||||||
|  | @ -406,12 +403,10 @@ fn executeX11Cmd(shell: [*:0]const u8, pw_dir: [*:0]const u8, x_cmd: []const u8, | ||||||
|     // Pid can be fetched from /tmp/X{d}.lock |     // Pid can be fetched from /tmp/X{d}.lock | ||||||
|     const x_pid = try getXPid(display_num); |     const x_pid = try getXPid(display_num); | ||||||
| 
 | 
 | ||||||
|     //logger.debug("Found X Server PID: {d}", .{x_pid}); |  | ||||||
| 
 |  | ||||||
|     const xorg_pid = std.c.fork(); |     const xorg_pid = std.c.fork(); | ||||||
|     if (xorg_pid == 0) { |     if (xorg_pid == 0) { | ||||||
|         var cmd_buffer = std.mem.zeroes([1024]u8); |         var cmd_buffer = std.mem.zeroes([1024]u8); | ||||||
|         const cmd_str = try std.fmt.bufPrintZ(&cmd_buffer, "{s} {s}", .{ x_cmd_setup, desktop_cmd }); |         const cmd_str = try std.fmt.bufPrintZ(&cmd_buffer, "{s} {s}", .{ config.x_cmd_setup, desktop_cmd }); | ||||||
|         _ = interop.execl(shell, shell, "-c", cmd_str.ptr, @as([*c]const u8, 0)); |         _ = interop.execl(shell, shell, "-c", cmd_str.ptr, @as([*c]const u8, 0)); | ||||||
|         std.os.exit(0); |         std.os.exit(0); | ||||||
|     } |     } | ||||||
|  | @ -421,7 +416,6 @@ fn executeX11Cmd(shell: [*:0]const u8, pw_dir: [*:0]const u8, x_cmd: []const u8, | ||||||
| 
 | 
 | ||||||
|     _ = std.c.kill(x_pid, 0); |     _ = std.c.kill(x_pid, 0); | ||||||
|     if (std.c._errno().* != interop.ESRCH) { |     if (std.c._errno().* != interop.ESRCH) { | ||||||
|         //logger.debug("X Server is alive. Sending SIGTERM to process. PID: {d}", .{pid}); |  | ||||||
|         _ = std.c.kill(x_pid, interop.SIGTERM); |         _ = std.c.kill(x_pid, interop.SIGTERM); | ||||||
|         _ = std.c.waitpid(x_pid, &status, 0); |         _ = std.c.waitpid(x_pid, &status, 0); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  | @ -44,7 +44,6 @@ term_reset_cmd: []const u8 = "/usr/bin/tput reset", | ||||||
| term_restore_cursor_cmd: []const u8 = "/usr/bin/tput cnorm", | term_restore_cursor_cmd: []const u8 = "/usr/bin/tput cnorm", | ||||||
| tty: u8 = 2, | tty: u8 = 2, | ||||||
| wayland_cmd: []const u8 = build_options.data_directory ++ "/wsetup.sh", | wayland_cmd: []const u8 = build_options.data_directory ++ "/wsetup.sh", | ||||||
| wayland_specifier: bool = false, |  | ||||||
| waylandsessions: []const u8 = "/usr/share/wayland-sessions", | waylandsessions: []const u8 = "/usr/share/wayland-sessions", | ||||||
| x_cmd: []const u8 = "/usr/bin/X", | x_cmd: []const u8 = "/usr/bin/X", | ||||||
| xinitrc: ?[]const u8 = "~/.xinitrc", | xinitrc: ?[]const u8 = "~/.xinitrc", | ||||||
|  |  | ||||||
|  | @ -1,47 +0,0 @@ | ||||||
| const std = @import("std"); |  | ||||||
| const ini = @import("ini"); |  | ||||||
| const Config = @import("Config.zig"); |  | ||||||
| const Lang = @import("Lang.zig"); |  | ||||||
| 
 |  | ||||||
| const Allocator = std.mem.Allocator; |  | ||||||
| 
 |  | ||||||
| pub const CONFIG_MAX_SIZE: u64 = 8 * 1024; |  | ||||||
| 
 |  | ||||||
| const ConfigReader = @This(); |  | ||||||
| 
 |  | ||||||
| allocator: Allocator, |  | ||||||
| config_allocated: bool = false, |  | ||||||
| lang_allocated: bool = false, |  | ||||||
| config: []u8 = undefined, |  | ||||||
| lang: []u8 = undefined, |  | ||||||
| 
 |  | ||||||
| pub fn init(config_allocator: Allocator) ConfigReader { |  | ||||||
|     return .{ |  | ||||||
|         .allocator = config_allocator, |  | ||||||
|     }; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| pub fn deinit(self: ConfigReader) void { |  | ||||||
|     if (self.config_allocated) self.allocator.free(self.config); |  | ||||||
|     if (self.lang_allocated) self.allocator.free(self.lang); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| pub fn readConfig(self: *ConfigReader, path: []const u8) !Config { |  | ||||||
|     var file = std.fs.cwd().openFile(path, .{}) catch return Config.init(); |  | ||||||
|     defer file.close(); |  | ||||||
| 
 |  | ||||||
|     self.config = try file.readToEndAlloc(self.allocator, CONFIG_MAX_SIZE); |  | ||||||
|     self.config_allocated = true; |  | ||||||
| 
 |  | ||||||
|     return try ini.readToStruct(Config, self.config); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| pub fn readLang(self: *ConfigReader, path: []const u8) !Lang { |  | ||||||
|     var file = std.fs.cwd().openFile(path, .{}) catch return Lang.init(); |  | ||||||
|     defer file.close(); |  | ||||||
| 
 |  | ||||||
|     self.lang = try file.readToEndAlloc(self.allocator, CONFIG_MAX_SIZE); |  | ||||||
|     self.lang_allocated = true; |  | ||||||
| 
 |  | ||||||
|     return try ini.readToStruct(Lang, self.lang); |  | ||||||
| } |  | ||||||
|  | @ -13,8 +13,8 @@ const Text = @import("tui/components/Text.zig"); | ||||||
| const Config = @import("config/Config.zig"); | const Config = @import("config/Config.zig"); | ||||||
| const ini = @import("config/ini.zig"); | const ini = @import("config/ini.zig"); | ||||||
| const Lang = @import("config/Lang.zig"); | const Lang = @import("config/Lang.zig"); | ||||||
| const LogFile = @import("logger/LogFile.zig"); |  | ||||||
| const Save = @import("config/Save.zig"); | const Save = @import("config/Save.zig"); | ||||||
|  | const LogFile = @import("logger/LogFile.zig"); | ||||||
| 
 | 
 | ||||||
| const Ini = ini.Ini; | const Ini = ini.Ini; | ||||||
| const termbox = interop.termbox; | const termbox = interop.termbox; | ||||||
|  | @ -125,7 +125,7 @@ pub fn main() !void { | ||||||
|     // Initialize terminal buffer |     // Initialize terminal buffer | ||||||
|     const labels_max_length = @max(lang.login.len, lang.password.len); |     const labels_max_length = @max(lang.login.len, lang.password.len); | ||||||
| 
 | 
 | ||||||
|     var buffer = TerminalBuffer.init(config.margin_box_v, config.margin_box_h, config.input_len, labels_max_length, config.fg, config.bg, config.border_fg); |     var buffer = TerminalBuffer.init(config, labels_max_length); | ||||||
| 
 | 
 | ||||||
|     // Initialize components |     // Initialize components | ||||||
|     var desktop = try Desktop.init(allocator, &buffer, config.max_desktop_len); |     var desktop = try Desktop.init(allocator, &buffer, config.max_desktop_len); | ||||||
|  | @ -371,7 +371,6 @@ pub fn main() !void { | ||||||
| 
 | 
 | ||||||
|                         buffer.drawLabel(lang.sleep, length, 0); |                         buffer.drawLabel(lang.sleep, length, 0); | ||||||
|                     } |                     } | ||||||
|                     // length += lang.sleep.len + 1; |  | ||||||
|                 } |                 } | ||||||
| 
 | 
 | ||||||
|                 draw_lock_state: { |                 draw_lock_state: { | ||||||
|  |  | ||||||
|  | @ -2,6 +2,7 @@ const std = @import("std"); | ||||||
| const builtin = @import("builtin"); | const builtin = @import("builtin"); | ||||||
| const interop = @import("../interop.zig"); | const interop = @import("../interop.zig"); | ||||||
| const utils = @import("utils.zig"); | const utils = @import("utils.zig"); | ||||||
|  | const Config = @import("../config/Config.zig"); | ||||||
| 
 | 
 | ||||||
| const Allocator = std.mem.Allocator; | const Allocator = std.mem.Allocator; | ||||||
| const Random = std.rand.Random; | const Random = std.rand.Random; | ||||||
|  | @ -35,7 +36,7 @@ box_height: u64, | ||||||
| margin_box_v: u8, | margin_box_v: u8, | ||||||
| margin_box_h: u8, | margin_box_h: u8, | ||||||
| 
 | 
 | ||||||
| pub fn init(margin_box_v: u8, margin_box_h: u8, input_length: u8, labels_max_length: u64, fg: u8, bg: u8, border_fg: u8) TerminalBuffer { | pub fn init(config: Config, labels_max_length: u64) TerminalBuffer { | ||||||
|     var prng = std.rand.Isaac64.init(@intCast(std.time.timestamp())); |     var prng = std.rand.Isaac64.init(@intCast(std.time.timestamp())); | ||||||
| 
 | 
 | ||||||
|     return .{ |     return .{ | ||||||
|  | @ -43,9 +44,9 @@ pub fn init(margin_box_v: u8, margin_box_h: u8, input_length: u8, labels_max_len | ||||||
|         .width = @intCast(termbox.tb_width()), |         .width = @intCast(termbox.tb_width()), | ||||||
|         .height = @intCast(termbox.tb_height()), |         .height = @intCast(termbox.tb_height()), | ||||||
|         .buffer = termbox.tb_cell_buffer(), |         .buffer = termbox.tb_cell_buffer(), | ||||||
|         .fg = fg, |         .fg = config.fg, | ||||||
|         .bg = bg, |         .bg = config.bg, | ||||||
|         .border_fg = border_fg, |         .border_fg = config.border_fg, | ||||||
|         .box_chars = if (builtin.os.tag == .linux or builtin.os.tag.isBSD()) .{ |         .box_chars = if (builtin.os.tag == .linux or builtin.os.tag.isBSD()) .{ | ||||||
|             .left_up = 0x250C, |             .left_up = 0x250C, | ||||||
|             .left_down = 0x2514, |             .left_down = 0x2514, | ||||||
|  | @ -68,10 +69,10 @@ pub fn init(margin_box_v: u8, margin_box_h: u8, input_length: u8, labels_max_len | ||||||
|         .labels_max_length = labels_max_length, |         .labels_max_length = labels_max_length, | ||||||
|         .box_x = 0, |         .box_x = 0, | ||||||
|         .box_y = 0, |         .box_y = 0, | ||||||
|         .box_width = (2 * margin_box_h) + input_length + 1 + labels_max_length, |         .box_width = (2 * config.margin_box_h) + config.input_len + 1 + labels_max_length, | ||||||
|         .box_height = 7 + (2 * margin_box_v), |         .box_height = 7 + (2 * config.margin_box_v), | ||||||
|         .margin_box_v = margin_box_v, |         .margin_box_v = config.margin_box_v, | ||||||
|         .margin_box_h = margin_box_h, |         .margin_box_h = config.margin_box_h, | ||||||
|     }; |     }; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue