mirror of
https://github.com/fairyglade/ly.git
synced 2025-12-22 20:24:53 +00:00
Compare commits
1 Commits
peterc-s/m
...
Atomsoldat
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2f2a460e38 |
@@ -297,7 +297,7 @@ fn install_ly(allocator: std.mem.Allocator, install_config: bool) !void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
const pam_path = try std.fs.path.join(allocator, &[_][]const u8{ dest_directory, config_directory, "/pam.d" });
|
const pam_path = try std.fs.path.join(allocator, &[_][]const u8{ config_directory, "/pam.d" });
|
||||||
if (!std.mem.eql(u8, dest_directory, "")) {
|
if (!std.mem.eql(u8, dest_directory, "")) {
|
||||||
std.fs.cwd().makePath(pam_path) catch {
|
std.fs.cwd().makePath(pam_path) catch {
|
||||||
std.debug.print("warn: {s} already exists as a directory.\n", .{pam_path});
|
std.debug.print("warn: {s} already exists as a directory.\n", .{pam_path});
|
||||||
|
|||||||
@@ -35,14 +35,6 @@
|
|||||||
# matrix -> CMatrix
|
# matrix -> CMatrix
|
||||||
animation = none
|
animation = none
|
||||||
|
|
||||||
# The minimum time between animation frames
|
|
||||||
# 32 -> ~30fps
|
|
||||||
# 16 -> ~60fps
|
|
||||||
# 8 -> ~120fps
|
|
||||||
# 6 -> ~144fps
|
|
||||||
# 4 -> ~240fps
|
|
||||||
animation_refresh_ms = 16
|
|
||||||
|
|
||||||
# Stop the animation after some time
|
# Stop the animation after some time
|
||||||
# 0 -> Run forever
|
# 0 -> Run forever
|
||||||
# 1..2e12 -> Stop the animation after this many seconds
|
# 1..2e12 -> Stop the animation after this many seconds
|
||||||
|
|||||||
@@ -50,57 +50,35 @@ pub fn realloc(self: *Doom) !void {
|
|||||||
self.buffer = buffer;
|
self.buffer = buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn drawWithUpdate(self: Doom) void {
|
pub fn draw(self: Doom) void {
|
||||||
for (0..self.terminal_buffer.width) |x| {
|
for (0..self.terminal_buffer.width) |x| {
|
||||||
for (1..self.terminal_buffer.height) |y| {
|
for (1..self.terminal_buffer.height) |y| {
|
||||||
// get source index
|
|
||||||
const source = y * self.terminal_buffer.width + x;
|
const source = y * self.terminal_buffer.width + x;
|
||||||
|
|
||||||
// random number between 0 and 3 inclusive
|
|
||||||
const random = (self.terminal_buffer.random.int(u16) % 7) & 3;
|
const random = (self.terminal_buffer.random.int(u16) % 7) & 3;
|
||||||
|
|
||||||
// adjust destination index based on random value
|
|
||||||
var dest = (source - @min(source, random)) + 1;
|
var dest = (source - @min(source, random)) + 1;
|
||||||
if (self.terminal_buffer.width > dest) dest = 0 else dest -= self.terminal_buffer.width;
|
if (self.terminal_buffer.width > dest) dest = 0 else dest -= self.terminal_buffer.width;
|
||||||
|
|
||||||
// get source intensity and destination offset
|
|
||||||
const buffer_source = self.buffer[source];
|
const buffer_source = self.buffer[source];
|
||||||
const buffer_dest_offset = random & 1;
|
const buffer_dest_offset = random & 1;
|
||||||
|
|
||||||
if (buffer_source < buffer_dest_offset) continue;
|
if (buffer_source < buffer_dest_offset) continue;
|
||||||
|
|
||||||
// calculate the destination intensity
|
|
||||||
var buffer_dest = buffer_source - buffer_dest_offset;
|
var buffer_dest = buffer_source - buffer_dest_offset;
|
||||||
if (buffer_dest > 12) buffer_dest = 0;
|
if (buffer_dest > 12) buffer_dest = 0;
|
||||||
self.buffer[dest] = @intCast(buffer_dest);
|
self.buffer[dest] = @intCast(buffer_dest);
|
||||||
|
|
||||||
// update terminal
|
|
||||||
self.terminal_buffer.buffer[dest] = toTermboxCell(FIRE[buffer_dest]);
|
self.terminal_buffer.buffer[dest] = toTermboxCell(FIRE[buffer_dest]);
|
||||||
self.terminal_buffer.buffer[source] = toTermboxCell(FIRE[buffer_source]);
|
self.terminal_buffer.buffer[source] = toTermboxCell(FIRE[buffer_source]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw(self: Doom) void {
|
|
||||||
for (0..self.terminal_buffer.width) |x| {
|
|
||||||
for (1..self.terminal_buffer.height) |y| {
|
|
||||||
// get source index
|
|
||||||
const source = y * self.terminal_buffer.width + x;
|
|
||||||
|
|
||||||
// get intensity from buffer
|
|
||||||
const buffer_source = self.buffer[source];
|
|
||||||
|
|
||||||
// set cell to correct fire char
|
|
||||||
self.terminal_buffer.buffer[source] = toTermboxCell(FIRE[buffer_source]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn initBuffer(buffer: []u8, width: usize) void {
|
fn initBuffer(buffer: []u8, width: usize) void {
|
||||||
const slice_start = buffer[0..buffer.len];
|
const length = buffer.len - width;
|
||||||
const slice_end = buffer[buffer.len - width .. buffer.len];
|
const slice_start = buffer[0..length];
|
||||||
|
const slice_end = buffer[length..];
|
||||||
|
|
||||||
// set cell initial values to 0, set bottom row to be fire sources
|
|
||||||
@memset(slice_start, 0);
|
@memset(slice_start, 0);
|
||||||
@memset(slice_end, STEPS - 1);
|
@memset(slice_end, STEPS - 1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,12 +68,14 @@ pub fn realloc(self: *Matrix) !void {
|
|||||||
self.lines = lines;
|
self.lines = lines;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn drawWithUpdate(self: *Matrix) void {
|
pub fn draw(self: *Matrix) void {
|
||||||
const buf_height = self.terminal_buffer.height;
|
const buf_height = self.terminal_buffer.height;
|
||||||
const buf_width = self.terminal_buffer.width;
|
const buf_width = self.terminal_buffer.width;
|
||||||
|
self.count += 1;
|
||||||
|
if (self.count > FRAME_DELAY) {
|
||||||
self.frame += 1;
|
self.frame += 1;
|
||||||
if (self.frame > 4) self.frame = 1;
|
if (self.frame > 4) self.frame = 1;
|
||||||
|
self.count = 0;
|
||||||
|
|
||||||
var x: usize = 0;
|
var x: usize = 0;
|
||||||
while (x < self.terminal_buffer.width) : (x += 2) {
|
while (x < self.terminal_buffer.width) : (x += 2) {
|
||||||
@@ -138,13 +140,8 @@ pub fn drawWithUpdate(self: *Matrix) void {
|
|||||||
first_col = false;
|
first_col = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.draw();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw(self: *Matrix) void {
|
|
||||||
const buf_width = self.terminal_buffer.width;
|
|
||||||
|
|
||||||
var x: usize = 0;
|
var x: usize = 0;
|
||||||
while (x < buf_width) : (x += 2) {
|
while (x < buf_width) : (x += 2) {
|
||||||
var y: usize = 1;
|
var y: usize = 1;
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ const Bigclock = enums.Bigclock;
|
|||||||
|
|
||||||
animation: Animation = .none,
|
animation: Animation = .none,
|
||||||
animation_timeout_sec: u12 = 0,
|
animation_timeout_sec: u12 = 0,
|
||||||
animation_refresh_ms: u16 = 16,
|
|
||||||
asterisk: ?u8 = '*',
|
asterisk: ?u8 = '*',
|
||||||
auth_fails: u64 = 10,
|
auth_fails: u64 = 10,
|
||||||
bg: u16 = 0,
|
bg: u16 = 0,
|
||||||
|
|||||||
30
src/main.zig
30
src/main.zig
@@ -317,11 +317,6 @@ pub fn main() !void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var animation_timer = switch (config.animation) {
|
|
||||||
.none => undefined,
|
|
||||||
else => try std.time.Timer.start(),
|
|
||||||
};
|
|
||||||
|
|
||||||
const animate = config.animation != .none;
|
const animate = config.animation != .none;
|
||||||
const shutdown_key = try std.fmt.parseInt(u8, config.shutdown_key[1..], 10);
|
const shutdown_key = try std.fmt.parseInt(u8, config.shutdown_key[1..], 10);
|
||||||
const shutdown_len = try utils.strWidth(lang.shutdown);
|
const shutdown_len = try utils.strWidth(lang.shutdown);
|
||||||
@@ -385,22 +380,8 @@ pub fn main() !void {
|
|||||||
if (!animation_timed_out) {
|
if (!animation_timed_out) {
|
||||||
switch (config.animation) {
|
switch (config.animation) {
|
||||||
.none => {},
|
.none => {},
|
||||||
.doom => {
|
.doom => doom.draw(),
|
||||||
if (animation_timer.read() / std.time.ns_per_ms > config.animation_refresh_ms) {
|
.matrix => matrix.draw(),
|
||||||
animation_timer.reset();
|
|
||||||
doom.drawWithUpdate();
|
|
||||||
} else {
|
|
||||||
doom.draw();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
.matrix => {
|
|
||||||
if (animation_timer.read() / std.time.ns_per_ms > config.animation_refresh_ms) {
|
|
||||||
animation_timer.reset();
|
|
||||||
matrix.drawWithUpdate();
|
|
||||||
} else {
|
|
||||||
matrix.draw();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -704,7 +685,7 @@ pub fn main() !void {
|
|||||||
const password_text = try allocator.dupeZ(u8, password.text.items);
|
const password_text = try allocator.dupeZ(u8, password.text.items);
|
||||||
defer allocator.free(password_text);
|
defer allocator.free(password_text);
|
||||||
|
|
||||||
// Give up TTY
|
// Give up control on the TTY
|
||||||
_ = termbox.tb_shutdown();
|
_ = termbox.tb_shutdown();
|
||||||
|
|
||||||
session_pid = try std.posix.fork();
|
session_pid = try std.posix.fork();
|
||||||
@@ -721,13 +702,10 @@ pub fn main() !void {
|
|||||||
session_pid = -1;
|
session_pid = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Take back TTY
|
// Take back control of the TTY
|
||||||
_ = termbox.tb_init();
|
_ = termbox.tb_init();
|
||||||
_ = termbox.tb_set_output_mode(termbox.TB_OUTPUT_NORMAL);
|
_ = termbox.tb_set_output_mode(termbox.TB_OUTPUT_NORMAL);
|
||||||
|
|
||||||
// Reinitialise buffer to avoid use after free
|
|
||||||
buffer = TerminalBuffer.init(config, labels_max_length, random);
|
|
||||||
|
|
||||||
const auth_err = shared_err.readError();
|
const auth_err = shared_err.readError();
|
||||||
if (auth_err) |err| {
|
if (auth_err) |err| {
|
||||||
auth_fails += 1;
|
auth_fails += 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user