Compare commits

..

No commits in common. "master" and "v1.0.0" have entirely different histories.

15 changed files with 64 additions and 280 deletions

View File

@ -12,10 +12,10 @@ ALLFLAGS=$(CFLAGS) -I$(IDIR)
LIBS=-lpam LIBS=-lpam
_DEPS = log.h util.h ui.h ui_state.h config.h desktop.h auth.h ofield.h efield.h keys.h users.h sessions.h chvt.h macros.h launch_state.h _DEPS = log.h util.h ui.h ui_state.h config.h desktop.h auth.h ofield.h efield.h keys.h users.h sessions.h chvt.h macros.h
DEPS = $(patsubst %,$(IDIR)/%,$(_DEPS)) DEPS = $(patsubst %,$(IDIR)/%,$(_DEPS))
_OBJ = main.o log.o util.o ui.o ui_state.o config.o desktop.o auth.o ofield.o efield.o users.o sessions.o chvt.o launch_state.o _OBJ = main.o log.o util.o ui.o ui_state.o config.o desktop.o auth.o ofield.o efield.o users.o sessions.o chvt.o
OBJ = $(patsubst %,$(ODIR)/%,$(_OBJ)) OBJ = $(patsubst %,$(ODIR)/%,$(_OBJ))
$(ODIR)/%.o: $(CDIR)/%.c $(DEPS) $(ODIR)/%.o: $(CDIR)/%.c $(DEPS)
@ -33,7 +33,7 @@ clean:
install: lidm install: lidm
mkdir -p ${DESTDIR}${PREFIX}/bin ${DESTDIR}${PREFIX}/share/man/man{1,5} mkdir -p ${DESTDIR}${PREFIX}/bin ${DESTDIR}${PREFIX}/share/man/man{1,5}
install -Dm755 ./lidm ${DESTDIR}${PREFIX}/bin/ install -Dm755 ./lidm ${DESTDIR}${PREFIX}/bin/
[ -f ${DESTDIR}/etc/lidm.ini ] || install -Dm644 ./themes/default.ini ${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.1 ${DESTDIR}${PREFIX}/share/man/man1/
install -Dm644 ./assets/man/lidm-config.5 ${DESTDIR}${PREFIX}/share/man/man5/ install -Dm644 ./assets/man/lidm-config.5 ${DESTDIR}${PREFIX}/share/man/man5/

View File

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

View File

@ -1,7 +1,7 @@
# shellcheck disable=SC2034,SC2148,SC2128,SC2154,SC2164 # shellcheck disable=SC2034,SC2148,SC2128,SC2154,SC2164
# Maintainer: javalsai <javalsai@proton.me> # Maintainer: javalsai <javalsai@proton.me>
pkgname=lidm-bin pkgname=lidm-bin
pkgver=1.1.1 pkgver=0.2.2
pkgrel=1 pkgrel=1
depends=('pam') depends=('pam')
pkgdesc="A fully colorful customizable TUI display manager made in C. (release binary)" pkgdesc="A fully colorful customizable TUI display manager made in C. (release binary)"
@ -16,10 +16,10 @@ source=(
"lidm.1::https://raw.githubusercontent.com/javalsai/lidm/v$pkgver/assets/man/lidm.1" "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" "lidm-config.5::https://raw.githubusercontent.com/javalsai/lidm/v$pkgver/assets/man/lidm-config.5"
) )
sha256sums=('c4e82ae2c08c223ef417edca50f86f516e3f9154339f67110c87d01855673fcf' sha256sums=('be2307be9bef7b3ef294fb0e8178040e2d8ccff6b8efb7546514da8b0f69c179'
'a8d29e220c23b48b5cd3aac0c0e395e90a9d6c9ca9c9c35a45ad6f3df5f55542' '68662430a6d262b35cc54d9f0e164ed935b7f7f4497a87cc94946c558bbe8a91'
'7f2fb91f55088be1a9b1c93ecf5d6c1e437f369b56df2eacc9d10b00c93c39f8' 'a6807a55ff72ec5a5678583156b3efd0d367f0bcb79854094132771f0cb86bce'
'5dbe088ce29c95a400080190560d4308c10519a953e83d2d5020dfdf47dd830f') '3adaae60f79dff1cef2b2aba7dcea04196cd49816759ad36afb9f7331ac9c3e4')
package() { package() {
install -Dm755 lidm "${pkgdir}/usr/bin/lidm" install -Dm755 lidm "${pkgdir}/usr/bin/lidm"

View File

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

View File

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

View File

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

View File

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

View File

@ -1,59 +0,0 @@
# 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,17 +0,0 @@
#ifndef LAUNCHSTATEH_
#define LAUNCHSTATEH_
#include <stdbool.h>
#include <sys/stat.h>
#include "macros.h"
struct LaunchState {
char* NNULLABLE username;
char* NNULLABLE session_opt;
};
int read_launch_state(struct LaunchState* NNULLABLE state);
bool write_launch_state(struct LaunchState state);
#endif

View File

@ -1,7 +1,6 @@
#ifndef UTILH_ #ifndef UTILH_
#define UTILH_ #define UTILH_
#include <bits/types/struct_timeval.h>
#include <stdbool.h> #include <stdbool.h>
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
@ -13,8 +12,6 @@
int find_keyname(enum keys* at, const char* name); int find_keyname(enum keys* at, const char* name);
enum keys find_ansi(const char* seq); enum keys find_ansi(const char* seq);
void read_press(u_char* length, char* out); 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); bool utf8_iscont(char byte);
size_t utf8len(const char* str); size_t utf8len(const char* str);

View File

@ -121,26 +121,19 @@ void moarEnv(char* user, struct session session, struct passwd* pw,
sourceFileTry((char*)vec_get(&config->behavior.source, i)); sourceFileTry((char*)vec_get(&config->behavior.source, i));
} }
/* printf("\n"); */ /* printf("\n"); */
if (pw->pw_dir) { if (pw->pw_dir) {
const char* home = pw->pw_dir; uint home_len = strlen(pw->pw_dir);
size_t home_len = strlen(home);
for (size_t i = 0; i < config->behavior.user_source.length; i++) { for (size_t i = 0; i < config->behavior.user_source.length; i++) {
const char* filename = (char*)vec_get(&config->behavior.user_source, i); char* file2sourcepath = (char*)vec_get(&config->behavior.user_source, i);
size_t filename_len = strlen(filename); 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);
size_t path_len = home_len + 1 + filename_len + 1; // nullbyte and slash sourceFileTry(newbuf);
char* path = malloc(path_len); free(newbuf);
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);
} }
} }

View File

@ -126,7 +126,7 @@ struct parser_error parse_key(enum introspection_type typ, union typ_ptr at,
aux_str = strdup(key); aux_str = strdup(key);
if (!aux_str) FAIL("allocation failure"); if (!aux_str) FAIL("allocation failure");
aux_err = parse_str_inplace(aux_str); aux_err = parse_str_inplace(aux_str);
if (aux_err.msg) { if (!aux_err.msg) {
free(aux_str); free(aux_str);
return aux_err; return aux_err;
} }
@ -157,7 +157,7 @@ struct parser_error parse_key(enum introspection_type typ, union typ_ptr at,
aux_str = strdup(key); aux_str = strdup(key);
if (!aux_str) FAIL("allocation failure"); if (!aux_str) FAIL("allocation failure");
aux_err = parse_str_inplace(aux_str); aux_err = parse_str_inplace(aux_str);
if (aux_err.msg) { if (!aux_err.msg) {
free(aux_str); free(aux_str);
return aux_err; return aux_err;
} }
@ -170,7 +170,7 @@ struct parser_error parse_key(enum introspection_type typ, union typ_ptr at,
#undef FAIL #undef FAIL
#undef NOFAIL #undef NOFAIL
// NOLINTBEGIN(readability-identifier-length,readability-function-cognitive-complexity) // NOLINTBEGIN(readability-identifier-length,readability-function-cognitive-complexity,readability-identifier-length)
struct status config_line_handler(void* _config, char* table, char* k, struct status config_line_handler(void* _config, char* table, char* k,
char* v) { char* v) {
struct config* config = (struct config*)_config; struct config* config = (struct config*)_config;
@ -213,14 +213,11 @@ struct status config_line_handler(void* _config, char* table, char* k,
return ret; return ret;
} }
if (this_intros_key->typ == STRING) log_printf("[I] cfg parsed [%s.%s]\n", table, k);
log_printf("[I] cfg parsed [%s.%s] (%s)\n", table, k, *k_addr.string);
else
log_printf("[I] cfg parsed [%s.%s]\n", table, k);
return ret; return ret;
} }
// NOLINTEND(readability-identifier-length,readability-function-cognitive-complexity) // NOLINTEND(readability-identifier-length,readability-function-cognitive-complexity,readability-identifier-length)
int parse_config(struct config* NNULLABLE config, char* NNULLABLE path) { int parse_config(struct config* NNULLABLE config, char* NNULLABLE path) {
FILE* fd = fopen(path, "r"); FILE* fd = fopen(path, "r");
@ -235,7 +232,9 @@ int parse_config(struct config* NNULLABLE config, char* NNULLABLE path) {
bool ret = read_desktop(fd, config, config_line_handler); bool ret = read_desktop(fd, config, config_line_handler);
(void)fclose(fd); (void)fclose(fd);
if (!ret) {
return -1;
}
if (!ret) return -1;
return 0; return 0;
} }

View File

@ -1,52 +0,0 @@
// Small file for saving last selection
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "launch_state.h"
#define STATE_DIR "/var/lib/lidm"
#define STATE_FILE "/var/lib/lidm/state"
#define RWXR_X___ 0750
int read_launch_state(struct LaunchState* NNULLABLE state) {
FILE* state_fd = fopen(STATE_FILE, "r");
if (state_fd == NULL) return -1;
*state = (struct LaunchState){
.username = NULL,
.session_opt = NULL,
};
size_t num = 0;
if (getline(&state->username, &num, state_fd) < 0) goto fail;
state->username[strcspn(state->username, "\n")] = 0;
num = 0;
if (getline(&state->session_opt, &num, state_fd) < 0) {
free(state->session_opt);
goto fail;
}
state->session_opt[strcspn(state->session_opt, "\n")] = 0;
(void)fclose(state_fd);
return 0;
fail:
(void)fclose(state_fd);
return -1;
}
bool write_launch_state(struct LaunchState state) {
FILE* state_fd = fopen(STATE_FILE, "w");
if (state_fd == NULL) {
if (mkdir(STATE_DIR, RWXR_X___) == -1) return false;
state_fd = fopen(STATE_FILE, "w");
if (state_fd == NULL) return false;
}
(void)fprintf(state_fd, "%s\n%s\n", state.username, state.session_opt);
(void)fclose(state_fd);
return true;
}

107
src/ui.c
View File

@ -20,8 +20,6 @@
#include "auth.h" #include "auth.h"
#include "efield.h" #include "efield.h"
#include "keys.h" #include "keys.h"
#include "launch_state.h"
#include "log.h"
#include "ofield.h" #include "ofield.h"
#include "sessions.h" #include "sessions.h"
#include "ui.h" #include "ui.h"
@ -46,7 +44,6 @@ static void print_session(struct uint_point origin, struct session session,
static void print_user(struct uint_point origin, struct user user, static void print_user(struct uint_point origin, struct user user,
bool multiple); bool multiple);
static void print_passwd(struct uint_point origin, uint length, bool err); 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 // ansi resource: https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797
static struct termios orig_term; static struct termios orig_term;
@ -55,15 +52,18 @@ static struct winsize window;
#define INNER_BOX_OUT_MARGIN 2 #define INNER_BOX_OUT_MARGIN 2
struct config* g_config = NULL; 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) { void setup(struct config* config) {
g_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); tcgetattr(STDOUT_FILENO, &orig_term);
term = orig_term; // save term term = orig_term; // save term
@ -76,9 +76,9 @@ void setup(struct config* config) {
printf("\x1b[s\x1b[?47h\x1b[%s;%sm\x1b[2J", g_config->colors.bg, printf("\x1b[s\x1b[?47h\x1b[%s;%sm\x1b[2J", g_config->colors.bg,
g_config->colors.fg); g_config->colors.fg);
print_footer();
(void)atexit(restore_all); (void)atexit(restore_all);
(void)signal(SIGINT, signal_handler); (void)signal(SIGINT, signal_handler);
(void)signal(SIGWINCH, process_sigwinch);
} }
static struct uint_point box_start() { static struct uint_point box_start() {
@ -171,18 +171,11 @@ void ui_update_ofield(struct opts_field* NNULLABLE self) {
} }
static char* unknown_str = "unknown"; static char* unknown_str = "unknown";
void scratch_print_ui() { // NOLINTNEXTLINE(readability-function-cognitive-complexity)
ioctl(STDOUT_FILENO, TIOCGWINSZ, &window); int load(struct Vector* users, struct Vector* sessions) {
/// SETUP
if (window.ws_row < BOX_HEIGHT + INNER_BOX_OUT_MARGIN * 2 || gusers = users;
window.ws_col < BOX_WIDTH + INNER_BOX_OUT_MARGIN * 2) { gsessions = sessions;
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 // hostnames larger won't render properly
const u_char HOSTNAME_SIZE = VALUES_COL - VALUES_SEPR - BOX_HMARGIN; const u_char HOSTNAME_SIZE = VALUES_COL - VALUES_SEPR - BOX_HMARGIN;
@ -199,6 +192,12 @@ void scratch_print_ui() {
// 1]); // 1]);
// *hidx = '\0'; // *hidx = '\0';
} }
of_session =
ofield_new(sessions->length + g_config->behavior.include_defshell);
of_user = ofield_new(users->length);
of_passwd = ofield_new(0);
/// PRINTING /// PRINTING
const struct uint_point BOXSTART = box_start(); const struct uint_point BOXSTART = box_start();
@ -217,71 +216,17 @@ void scratch_print_ui() {
g_config->colors.e_date, fmtd_time, g_config->colors.fg); g_config->colors.e_date, fmtd_time, g_config->colors.fg);
free(fmtd_time); free(fmtd_time);
print_footer();
ui_update_field(SESSION); ui_update_field(SESSION);
ui_update_field(USER); ui_update_field(USER);
ui_update_field(PASSWD); ui_update_field(PASSWD);
ui_update_cursor_focus(); 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);
of_user = ofield_new(users->length);
of_passwd = ofield_new(0);
of_user.current_opt = users->length > 0;
of_session.current_opt = sessions->length > 0;
struct LaunchState initial_state;
if (read_launch_state(&initial_state) == 0) {
for (size_t i = 0; i < users->length; i++) {
struct user* user_i = (struct user*)vec_get(users, i);
if (strcmp(user_i->username, initial_state.username) == 0) {
of_user.current_opt = i + 1;
break;
}
}
for (size_t i = 0; i < sessions->length; i++) {
struct session* session_i = (struct session*)vec_get(sessions, i);
if (strcmp(session_i->name, initial_state.session_opt) == 0) {
of_session.current_opt = i + 1;
break;
}
}
if (g_config->behavior.include_defshell) {
if (strcmp(st_user().shell, initial_state.session_opt) == 0)
of_session.current_opt = sessions->length + 1;
}
free(initial_state.username);
free(initial_state.session_opt);
}
scratch_print_ui();
/// INTERACTIVE /// INTERACTIVE
u_char len; u_char len;
char seq[0xff]; char seq[0xff];
uint esc = 0; uint esc = 0;
while (true) { while (true) {
if (need_resize) { read_press(&len, seq);
need_resize = 0;
scratch_print_ui();
}
if (!read_press_nb(&len, seq, &tv)) continue;
if (*seq == '\x1b') { if (*seq == '\x1b') {
enum keys ansi_code = find_ansi(seq); enum keys ansi_code = find_ansi(seq);
if (ansi_code != -1) { if (ansi_code != -1) {
@ -309,12 +254,6 @@ int load(struct Vector* users, struct Vector* sessions) {
} }
} else { } else {
if (len == 1 && *seq == '\n') { if (len == 1 && *seq == '\n') {
bool successful_write = write_launch_state((struct LaunchState){
.username = st_user().username,
.session_opt = st_session(g_config->behavior.include_defshell).name,
});
if (!successful_write) log_puts("[E] failed to write launch state");
if (!launch(st_user().username, of_passwd.efield.content, if (!launch(st_user().username, of_passwd.efield.content,
st_session(g_config->behavior.include_defshell), st_session(g_config->behavior.include_defshell),
&restore_all, g_config)) { &restore_all, g_config)) {

View File

@ -1,5 +1,3 @@
#include <asm-generic/errno-base.h>
#include <errno.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -55,17 +53,6 @@ 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 // https://stackoverflow.com/a/48040042
static int selret_magic() { static int selret_magic() {
fd_set set; fd_set set;