19 Commits

Author SHA1 Message Date
981aa4efc7 Merge pull request #48 from rmntgx/ui-improvements
Interface resize
2025-07-04 01:45:16 +02:00
9f905622a2 chore: dry and modularize a bit 2025-07-04 01:43:32 +02:00
92d3351292 Merge pull request #50 from rmntgx/master
fix: do not overwrite theme
2025-07-03 20:36:51 +02:00
rmntgx
f5445248d3 Merge branch 'master' into ui-improvements 2025-07-02 14:02:40 +05:00
rmntgx
68ed11fb2d feat: cool resize implementation 2025-07-02 13:50:17 +05:00
bae810eb99 Merge pull request #47 from javalsai/actions/update-aur-1.1.1
[AUR update]: Bump to 1.1.1
2025-07-01 01:56:05 +02:00
GitHub Actions
4c955053e8 Update AUR pkgs to v1.1.1 2025-06-30 23:55:37 +00:00
3bfc2f52f3 Merge pull request #46 from javalsai/fix-45
fix #45
2025-07-01 01:53:22 +02:00
59acddf652 dev: add debug utils folder 2025-07-01 01:26:35 +02:00
6c6769b2b3 chore: clean some auth logic 2025-07-01 01:16:08 +02:00
99e27dd0c0 fix(likely): #45 2025-07-01 01:09:49 +02:00
rmntgx
b653fdcc57 feat: buggy resize implementation 2025-06-29 23:32:04 +05:00
rmntgx
d7b5f4f090 Merge branch 'javalsai:master' into master 2025-06-29 23:10:52 +05:00
4b6d113bdb Merge pull request #44 from javalsai/actions/update-aur-1.1.0
[AUR update]: Bump to 1.1.0
2025-06-29 19:05:26 +02:00
GitHub Actions
4fa400eb06 Update AUR pkgs to v1.1.0 2025-06-29 17:01:11 +00:00
rmntgx
d5a708ec4a Merge pull request #6 from rmntgx/save-last-selection
Save last selection
2025-06-29 15:21:41 +05:00
rmntgx
8b8784a210 Merge pull request #5 from rmntgx/save-last-selection
Save last selection
2025-06-29 10:26:33 +05:00
rmntgx
d9a1bb1e68 fix: made it simplier 2025-06-25 18:05:50 +05:00
rmntgx
8d24924e59 fix: do not overwrite theme 2025-07-02 14:18:46 +05:00
12 changed files with 176 additions and 66 deletions

View File

@@ -33,7 +33,7 @@ clean:
install: lidm
mkdir -p ${DESTDIR}${PREFIX}/bin ${DESTDIR}${PREFIX}/share/man/man{1,5}
install -Dm755 ./lidm ${DESTDIR}${PREFIX}/bin/
install -Dm644 ./themes/default.ini ${DESTDIR}/etc/lidm.ini
[ -f ${DESTDIR}/etc/lidm.ini ] || install -Dm644 ./themes/default.ini ${DESTDIR}/etc/lidm.ini
install -Dm644 ./assets/man/lidm.1 ${DESTDIR}${PREFIX}/share/man/man1/
install -Dm644 ./assets/man/lidm-config.5 ${DESTDIR}${PREFIX}/share/man/man5/

View File

@@ -1,6 +1,6 @@
pkgbase = lidm-bin
pkgdesc = A fully colorful customizable TUI display manager made in C. (release binary)
pkgver = 1.0.0
pkgver = 1.1.1
pkgrel = 1
url = https://github.com/javalsai/lidm
arch = x86_64
@@ -8,11 +8,11 @@ pkgbase = lidm-bin
depends = pam
provides = lidm
conflicts = lidm
source = lidm::https://github.com/javalsai/lidm/releases/download/v1.0.0/lidm-amd64
source = default-theme.ini::https://raw.githubusercontent.com/javalsai/lidm/v1.0.0/themes/default.ini
source = lidm.1::https://raw.githubusercontent.com/javalsai/lidm/v1.0.0/assets/man/lidm.1
source = lidm-config.5::https://raw.githubusercontent.com/javalsai/lidm/v1.0.0/assets/man/lidm-config.5
sha256sums = 77e8aeeb8dd751620a63220fa6e419d9066b1b35d79e12ce5449a5a1acb24252
source = lidm::https://github.com/javalsai/lidm/releases/download/v1.1.1/lidm-amd64
source = default-theme.ini::https://raw.githubusercontent.com/javalsai/lidm/v1.1.1/themes/default.ini
source = lidm.1::https://raw.githubusercontent.com/javalsai/lidm/v1.1.1/assets/man/lidm.1
source = lidm-config.5::https://raw.githubusercontent.com/javalsai/lidm/v1.1.1/assets/man/lidm-config.5
sha256sums = c4e82ae2c08c223ef417edca50f86f516e3f9154339f67110c87d01855673fcf
sha256sums = a8d29e220c23b48b5cd3aac0c0e395e90a9d6c9ca9c9c35a45ad6f3df5f55542
sha256sums = 7f2fb91f55088be1a9b1c93ecf5d6c1e437f369b56df2eacc9d10b00c93c39f8
sha256sums = 5dbe088ce29c95a400080190560d4308c10519a953e83d2d5020dfdf47dd830f

View File

@@ -1,7 +1,7 @@
# shellcheck disable=SC2034,SC2148,SC2128,SC2154,SC2164
# Maintainer: javalsai <javalsai@proton.me>
pkgname=lidm-bin
pkgver=1.0.0
pkgver=1.1.1
pkgrel=1
depends=('pam')
pkgdesc="A fully colorful customizable TUI display manager made in C. (release binary)"
@@ -16,7 +16,7 @@ source=(
"lidm.1::https://raw.githubusercontent.com/javalsai/lidm/v$pkgver/assets/man/lidm.1"
"lidm-config.5::https://raw.githubusercontent.com/javalsai/lidm/v$pkgver/assets/man/lidm-config.5"
)
sha256sums=('77e8aeeb8dd751620a63220fa6e419d9066b1b35d79e12ce5449a5a1acb24252'
sha256sums=('c4e82ae2c08c223ef417edca50f86f516e3f9154339f67110c87d01855673fcf'
'a8d29e220c23b48b5cd3aac0c0e395e90a9d6c9ca9c9c35a45ad6f3df5f55542'
'7f2fb91f55088be1a9b1c93ecf5d6c1e437f369b56df2eacc9d10b00c93c39f8'
'5dbe088ce29c95a400080190560d4308c10519a953e83d2d5020dfdf47dd830f')

View File

@@ -1,7 +1,7 @@
# shellcheck disable=SC2034,SC2148,SC2128,SC2154,SC2164
# Maintainer: javalsai <javalsai@proton.me>
pkgname=lidm-git
pkgver=1.0.0.r0.g2b1e469
pkgver=1.1.1.r0.g3bfc2f5
pkgrel=1
depends=('pam')
makedepends=('git' 'make' 'gcc')

View File

@@ -1,6 +1,6 @@
pkgbase = lidm
pkgdesc = A fully colorful customizable TUI display manager made in C. (build latest tag)
pkgver = 1.0.0
pkgver = 1.1.1
pkgrel = 1
url = https://github.com/javalsai/lidm
arch = any
@@ -8,7 +8,7 @@ pkgbase = lidm
makedepends = git
makedepends = gcc
depends = pam
source = tarball.tar.gz::https://github.com/javalsai/lidm/archive/refs/tags/v1.0.0.tar.gz
sha256sums = 5a336c7aecc709d1514e6f16f63b316263894a08291a49aaae8ee1b6a06bad74
source = tarball.tar.gz::https://github.com/javalsai/lidm/archive/refs/tags/v1.1.1.tar.gz
sha256sums = 915dc5acce413d5d32bb52c6f9980661a389a0939a49ac31bc250b2d162a5479
pkgname = lidm

View File

@@ -1,7 +1,7 @@
# shellcheck disable=SC2034,SC2148,SC2128,SC2154,SC2164
# Maintainer: javalsai <javalsai@proton.me>
pkgname=lidm
pkgver=1.0.0
pkgver=1.1.1
pkgrel=1
depends=('pam')
makedepends=('git' 'gcc')
@@ -10,7 +10,7 @@ arch=('any')
url="https://github.com/javalsai/lidm"
license=('GPL')
source=("tarball.tar.gz::https://github.com/javalsai/lidm/archive/refs/tags/v$pkgver.tar.gz")
sha256sums=('5a336c7aecc709d1514e6f16f63b316263894a08291a49aaae8ee1b6a06bad74')
sha256sums=('915dc5acce413d5d32bb52c6f9980661a389a0939a49ac31bc250b2d162a5479')
build() {
tar -xzf "tarball.tar.gz"

3
debug/README.md Normal file
View File

@@ -0,0 +1,3 @@
# Debug
This folder contains debug utils like gdb scripts. They are not guaranteed to work but can ease some tasks when debugging.

59
debug/debug.gdb Normal file
View File

@@ -0,0 +1,59 @@
# this just meant to run in another term, is probably better to attach to another already running window
set inferior-tty /dev/pts/7
set pagination off
break *(read_press + 62)
define fake_read
set *((char*) $rsi) = $al
set $rax = 1
jump *(read_press + 67)
end
break *(read_press + 108)
define fake_magic_cont
set $eax = 1
jump *(read_press + 113)
end
define fake_magic_end
set $eax = 0
jump *(read_press + 113)
end
run
set $al = 0x1b
fake_read
fake_magic_cont
set $al = '['
fake_read
fake_magic_cont
set $al = 'D'
fake_read
fake_magic_end
set $al = 'p'
fake_read
fake_magic_end
set $al = 'a'
fake_read
fake_magic_end
set $al = 's'
fake_read
fake_magic_end
set $al = 's'
fake_read
fake_magic_end
set $al = 'w'
fake_read
fake_magic_end
set $al = 'd'
fake_read
fake_magic_end
set $al = '\n'
fake_read
fake_magic_end

View File

@@ -1,6 +1,7 @@
#ifndef UTILH_
#define UTILH_
#include <bits/types/struct_timeval.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
@@ -12,6 +13,8 @@
int find_keyname(enum keys* at, const char* name);
enum keys find_ansi(const char* seq);
void read_press(u_char* length, char* out);
// non blocking, waits up to tv, returns true if actually read
bool read_press_nb(u_char* length, char* out, struct timeval* tv);
bool utf8_iscont(char byte);
size_t utf8len(const char* str);

View File

@@ -121,19 +121,26 @@ void moarEnv(char* user, struct session session, struct passwd* pw,
sourceFileTry((char*)vec_get(&config->behavior.source, i));
}
/* printf("\n"); */
if (pw->pw_dir) {
uint home_len = strlen(pw->pw_dir);
for (size_t i = 0; i < config->behavior.user_source.length; i++) {
char* file2sourcepath = (char*)vec_get(&config->behavior.user_source, i);
size_t newbuf_len = home_len + strlen(file2sourcepath) + 2;
char* newbuf = malloc(newbuf_len); // nullbyte and slash
if (newbuf == NULL) continue; // can't bother
memcpy(newbuf, pw->pw_dir, newbuf_len);
newbuf[home_len] = '/'; // assume pw_dir doesn't start with '/' :P
memcpy(&newbuf[home_len + 1], file2sourcepath, newbuf_len - home_len);
sourceFileTry(newbuf);
free(newbuf);
if (pw->pw_dir) {
const char* home = pw->pw_dir;
size_t home_len = strlen(home);
for (size_t i = 0; i < config->behavior.user_source.length; i++) {
const char* filename = (char*)vec_get(&config->behavior.user_source, i);
size_t filename_len = strlen(filename);
size_t path_len = home_len + 1 + filename_len + 1; // nullbyte and slash
char* path = malloc(path_len);
if (!path) continue; // can't bother
memcpy(path, home, home_len);
path[home_len] = '/'; // assume pw_dir doesn't start with '/' :P
memcpy(&path[home_len + 1], filename, filename_len);
path[path_len - 1] = '\0';
sourceFileTry(path);
free(path);
}
}

103
src/ui.c
View File

@@ -46,6 +46,7 @@ static void print_session(struct uint_point origin, struct session session,
static void print_user(struct uint_point origin, struct user user,
bool multiple);
static void print_passwd(struct uint_point origin, uint length, bool err);
static void scratch_print_ui();
// ansi resource: https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797
static struct termios orig_term;
@@ -54,18 +55,15 @@ static struct winsize window;
#define INNER_BOX_OUT_MARGIN 2
struct config* g_config = NULL;
static volatile sig_atomic_t need_resize = 0;
static void process_sigwinch(int signal) {
need_resize = 1;
}
void setup(struct config* config) {
g_config = config;
ioctl(STDOUT_FILENO, TIOCGWINSZ, &window);
// at least
// 2 padding top and bottom for footer and vertical compensation
// 2 padding left & right to not overflow footer width
if (window.ws_row < BOX_HEIGHT + INNER_BOX_OUT_MARGIN * 2 ||
window.ws_col < BOX_WIDTH + INNER_BOX_OUT_MARGIN * 2) {
(void)fprintf(stderr, "\x1b[1;31mScreen too small\x1b[0m\n");
exit(1);
}
tcgetattr(STDOUT_FILENO, &orig_term);
term = orig_term; // save term
@@ -78,9 +76,9 @@ void setup(struct config* config) {
printf("\x1b[s\x1b[?47h\x1b[%s;%sm\x1b[2J", g_config->colors.bg,
g_config->colors.fg);
print_footer();
(void)atexit(restore_all);
(void)signal(SIGINT, signal_handler);
(void)signal(SIGWINCH, process_sigwinch);
}
static struct uint_point box_start() {
@@ -173,11 +171,18 @@ void ui_update_ofield(struct opts_field* NNULLABLE self) {
}
static char* unknown_str = "unknown";
// NOLINTNEXTLINE(readability-function-cognitive-complexity)
int load(struct Vector* users, struct Vector* sessions) {
/// SETUP
gusers = users;
gsessions = sessions;
void scratch_print_ui() {
ioctl(STDOUT_FILENO, TIOCGWINSZ, &window);
if (window.ws_row < BOX_HEIGHT + INNER_BOX_OUT_MARGIN * 2 ||
window.ws_col < BOX_WIDTH + INNER_BOX_OUT_MARGIN * 2) {
printf("\033[2J\033[H"); // Clear screen
printf("\x1b[1;31mScreen too small\x1b[0m\n");
printf("\x1b[%s;%sm\x1b[2J", g_config->colors.bg, g_config->colors.fg);
return;
}
printf("\033[2J\033[H"); // Clear screen
// hostnames larger won't render properly
const u_char HOSTNAME_SIZE = VALUES_COL - VALUES_SEPR - BOX_HMARGIN;
@@ -194,6 +199,42 @@ int load(struct Vector* users, struct Vector* sessions) {
// 1]);
// *hidx = '\0';
}
/// PRINTING
const struct uint_point BOXSTART = box_start();
// printf box
print_box();
// put hostname
printf("\x1b[%d;%dH\x1b[%sm%s\x1b[%sm", BOXSTART.y + HEAD_ROW,
BOXSTART.x + VALUES_COL - VALUES_SEPR - (uint)utf8len(hostname),
g_config->colors.e_hostname, hostname, g_config->colors.fg);
// put date
char* fmtd_time = fmt_time(g_config->behavior.timefmt);
printf("\x1b[%d;%dH\x1b[%sm%s\x1b[%sm", BOXSTART.y + HEAD_ROW,
BOXSTART.x + BOX_WIDTH - 1 - BOX_HMARGIN - (uint)utf8len(fmtd_time),
g_config->colors.e_date, fmtd_time, g_config->colors.fg);
free(fmtd_time);
print_footer();
ui_update_field(SESSION);
ui_update_field(USER);
ui_update_field(PASSWD);
ui_update_cursor_focus();
}
#define READ_NONBLOCK_DELAY 100000
// NOLINTNEXTLINE(readability-function-cognitive-complexity)
int load(struct Vector* users, struct Vector* sessions) {
struct timeval tv;
tv.tv_sec = 0;
tv.tv_usec = READ_NONBLOCK_DELAY; // timeout = 100ms
/// SETUP
gusers = users;
gsessions = sessions;
of_session =
ofield_new(sessions->length + g_config->behavior.include_defshell);
@@ -228,35 +269,19 @@ int load(struct Vector* users, struct Vector* sessions) {
free(initial_state.session_opt);
}
/// PRINTING
const struct uint_point BOXSTART = box_start();
// printf box
print_box();
// put hostname
printf("\x1b[%d;%dH\x1b[%sm%s\x1b[%sm", BOXSTART.y + HEAD_ROW,
BOXSTART.x + VALUES_COL - VALUES_SEPR - (uint)utf8len(hostname),
g_config->colors.e_hostname, hostname, g_config->colors.fg);
// put date
char* fmtd_time = fmt_time(g_config->behavior.timefmt);
printf("\x1b[%d;%dH\x1b[%sm%s\x1b[%sm", BOXSTART.y + HEAD_ROW,
BOXSTART.x + BOX_WIDTH - 1 - BOX_HMARGIN - (uint)utf8len(fmtd_time),
g_config->colors.e_date, fmtd_time, g_config->colors.fg);
free(fmtd_time);
ui_update_field(SESSION);
ui_update_field(USER);
ui_update_field(PASSWD);
ui_update_cursor_focus();
scratch_print_ui();
/// INTERACTIVE
u_char len;
char seq[0xff];
uint esc = 0;
while (true) {
read_press(&len, seq);
if (need_resize) {
need_resize = 0;
scratch_print_ui();
}
if (!read_press_nb(&len, seq, &tv)) continue;
if (*seq == '\x1b') {
enum keys ansi_code = find_ansi(seq);
if (ansi_code != -1) {

View File

@@ -1,3 +1,5 @@
#include <asm-generic/errno-base.h>
#include <errno.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
@@ -53,6 +55,17 @@ void read_press(u_char* length, char* out) {
}
}
bool read_press_nb(u_char* length, char* out, struct timeval* tv) {
fd_set fds;
FD_ZERO(&fds);
FD_SET(STDIN_FILENO, &fds);
int ret = select(STDIN_FILENO + 1, &fds, NULL, NULL, tv);
if ((ret < 0 && errno == EINTR) || ret == 0) return false;
read_press(length, out);
return true;
}
// https://stackoverflow.com/a/48040042
static int selret_magic() {
fd_set set;