feat: utf8 support & partial ui.c refactor

This commit is contained in:
2025-06-20 21:31:03 +02:00
parent d5688f5c5c
commit 787b412005
17 changed files with 366 additions and 264 deletions

View File

@@ -109,7 +109,9 @@ BUILD(functions, TABLE_FUNCTIONS);
F(char*, e_passwd, STRING, "password", name) \
F(char*, s_wayland, STRING, "wayland", name) \
F(char*, s_xorg, STRING, "xorg", name) \
F(char*, s_shell, STRING, "shell", name)
F(char*, s_shell, STRING, "shell", name) \
F(char*, opts_pre, STRING, "< ", name) \
F(char*, opts_post, STRING, " >", name)
BUILD(strings, TABLE_STRINGS);

View File

@@ -4,15 +4,15 @@
#include <stdbool.h>
#include <sys/types.h>
// holds also the max string buffer in itself, not dynamic
struct editable_field {
u_char length;
u_char pos;
char content[255];
};
struct editable_field field_new(char* content);
void field_trim(struct editable_field* self, u_char pos);
void field_update(struct editable_field* self, char* update);
bool field_seek(struct editable_field* self, char seek);
struct editable_field efield_new(char* content);
void efield_trim(struct editable_field* self, u_char pos);
void efield_update(struct editable_field* self, char* update);
bool efield_seek(struct editable_field* self, char seek);
#endif

23
include/ofield.h Normal file
View File

@@ -0,0 +1,23 @@
#ifndef OFIELD_
#define OFIELD_
#include <stddef.h>
#include "efield.h"
// related vector is external, indexing at 1, 0 means empty and hence points to
// the editable_field
struct opts_field {
size_t opts;
size_t current_opt;
struct editable_field efield;
};
struct opts_field ofield_new(size_t opts);
void ofield_toedit(struct opts_field* self, char* init);
void ofield_kbd_type(struct opts_field* self, char* typed, char* empty_default);
bool ofield_opts_seek(struct opts_field* self, char seek);
bool ofield_seek(struct opts_field* self, char seek);
u_char ofield_display_cursor_col(struct opts_field* self);
#endif

View File

@@ -2,11 +2,24 @@
#define UIH_
#include "config.h"
#include "ofield.h"
#include "util.h"
enum input { SESSION, USER, PASSWD };
extern const u_char inputs_n;
// not customizable (for now)
extern const uint boxw;
extern const uint boxh;
void setup(struct config* config);
int load(struct Vector* users, struct Vector* sessions);
void print_err(const char*);
void print_errno(const char*);
void ui_update_field(enum input focused_input);
void ui_update_ffield();
void ui_update_ofield(struct opts_field* self);
void ui_update_cursor_focus();
#endif

28
include/ui_state.h Normal file
View File

@@ -0,0 +1,28 @@
#ifndef UISTATEH_
#define UISTATEH_
#include <stddef.h>
#include "ui.h"
extern enum input focused_input;
extern struct opts_field of_session;
extern struct opts_field of_user;
extern struct opts_field of_passwd;
extern struct Vector* gusers;
extern struct Vector* gsessions;
struct opts_field* NNULLABLE get_opts_field(enum input from);
struct opts_field* NNULLABLE get_opts_ffield();
struct user st_user();
struct session st_session(bool include_defshell);
void st_ch_focus(char direction);
void st_ch_of_opts(char direction);
void st_ch_ef_col(char direction);
void st_kbd_type(char* text, bool cfg_include_defshell);
#endif

View File

@@ -13,6 +13,12 @@ int find_keyname(enum keys* at, char* name);
enum keys find_ansi(char*);
void read_press(u_char*, char*);
bool utf8_iscont(char byte);
size_t utf8len(char* str);
size_t utf8len_until(char* str, char* until);
char* utf8back(char* str);
char* utf8seek(char* str);
struct Vector {
uint32_t length;
uint32_t capacity;