all: at this point just read readme 😭

spaghetti code
equivalent spaghetti readme
spaghetti commit (wait no, this is actually descriptive)
This commit is contained in:
2024-07-13 01:30:47 +02:00
parent 08debefeb7
commit 6b2d76c9b8
16 changed files with 954 additions and 39 deletions

18
include/efield.h Normal file
View File

@@ -0,0 +1,18 @@
#ifndef _EFIELDH_
#define _EFIELDH_
#include <stdbool.h>
#include <sys/types.h>
struct editable_field {
u_char length;
u_char pos;
char content[255];
};
struct editable_field field_new(char*);
void field_trim(struct editable_field*, u_char);
void field_update(struct editable_field*, char*);
bool field_seek(struct editable_field*, char);
#endif

104
include/keys.h Normal file
View File

@@ -0,0 +1,104 @@
#ifndef _KEYSH_
#define _KEYSH_
#include <stdlib.h>
enum keys {
ESC,
F1,
F2,
F3,
F4,
F5,
F6,
F7,
F8,
F9,
F10,
F11,
F12,
A_UP,
A_DOWN,
A_RIGHT,
A_LEFT,
N_CENTER,
N_UP,
N_DOWN,
N_RIGHT,
N_LEFT,
INS,
SUPR,
HOME,
END,
PAGE_UP,
PAGE_DOWN,
};
static const char * const key_names[] = {
[ESC] = "ESC",
[F1] = "F1",
[F2] = "F2",
[F3] = "F3",
[F4] = "F4",
[F5] = "F5",
[F6] = "F6",
[F7] = "F7",
[F8] = "F8",
[F9] = "F9",
[F10] = "F10",
[F11] = "F11",
[F12] = "F12",
[A_UP] = "A_UP",
[A_DOWN] = "A_DOWN",
[A_RIGHT] = "A_RIGHT",
[N_CENTER] = "N_CENTER",
[A_LEFT] = "A_LEFT",
[N_UP] = "N_UP",
[N_DOWN] = "N_DOWN",
[N_RIGHT] = "N_RIGHT",
[N_LEFT] = "N_LEFT",
[INS] = "INS",
[SUPR] = "SUPR",
[HOME] = "HOME",
[END] = "END",
[PAGE_UP] = "PAGE_UP",
[PAGE_DOWN] = "PAGE_DOWN",
};
struct key_mapping {
enum keys key;
const char *sequences[3];
};
static const struct key_mapping key_mappings[] = {
{ ESC, { "\x1b", NULL }},
{ F1, { "\x1bOP", "\x1b[[A", NULL }},
{ F2, { "\x1bOQ", "\x1b[[B", NULL }},
{ F3, { "\x1bOR", "\x1b[[C", NULL }},
{ F4, { "\x1bOS", "\x1b[[D", NULL }},
{ F5, { "\x1b[15~", "\x1b[[E", NULL }},
{ F6, { "\x1b[17~", NULL }},
{ F7, { "\x1b[18~", NULL }},
{ F8, { "\x1b[19~", NULL }},
{ F9, { "\x1b[20~", NULL }},
{ F10, { "\x1b[21~", NULL }},
{ F11, { "\x1b[23~", NULL }},
{ F12, { "\x1b[24~", NULL }},
{ A_UP, { "\x1b[A", NULL }},
{ A_DOWN, { "\x1b[B", NULL }},
{ A_RIGHT, { "\x1b[C", NULL }},
{ A_LEFT, { "\x1b[D", NULL }},
{ N_CENTER, { "\x1b[E", NULL }},
{ N_UP, { "\x1bOA", NULL }},
{ N_DOWN, { "\x1bOB", NULL }},
{ N_RIGHT, { "\x1bOC", NULL }},
{ N_LEFT, { "\x1bOD", NULL }},
{ INS, { "\x1b[2~", NULL }},
{ SUPR, { "\x1b[3~", NULL }},
{ HOME, { "\x1b[H", NULL }},
{ END, { "\x1b[F", NULL }},
{ PAGE_UP, { "\x1b[5~", NULL }},
{ PAGE_DOWN, { "\x1b[6~", NULL }},
};
#endif

View File

@@ -1,9 +1,18 @@
#ifndef _SESSIONSH_
#define _SESSIONSH_
#include <sys/types.h>
enum session_type {
XORG,
WAYLAND,
SHELL,
};
struct session {
const char *type;
char *name;
char *path;
enum session_type type;
};
struct sessions_list {
@@ -12,3 +21,5 @@ struct sessions_list {
};
struct sessions_list *get_avaliable_sessions();
#endif

80
include/ui.h Normal file
View File

@@ -0,0 +1,80 @@
#ifndef _UIH_
#define _UIH_
#include <stdbool.h>
#include <keys.h>
#include <sessions.h>
#include <users.h>
// should be ansi escape codes under \x1b[...m
// if not prepared accordingly, it might break
struct theme_colors {
char *bg;
char *fg;
char *err;
char *s_wl;
char *s_xorg;
char *s_shell;
char *f_other;
char *e_hostname;
char *e_date;
char *e_box;
char *e_header;
char *e_user;
char *e_passwd;
char *e_badpasswd;
char *e_key;
};
// even if they're multiple bytes long
// they should only take up 1 char size on display
struct theme_chars {
char *hb;
char *vb;
char *ctl;
char *ctr;
char *cbl;
char *cbr;
};
struct theme {
struct theme_colors colors;
struct theme_chars chars;
};
struct functions {
enum keys poweroff;
enum keys reboot;
enum keys refresh;
};
struct strings {
char* f_poweroff;
char* f_reboot;
char* f_refresh;
char* e_user;
char* e_passwd;
char* s_xorg;
char* s_wayland;
char* s_shell;
};
struct behavior {
bool include_defshell;
};
struct config {
struct theme theme;
struct functions functions;
struct strings strings;
struct behavior behavior;
};
void setup(struct config);
int load(struct users_list*, struct sessions_list*);
void print_err(const char*);
void print_errno(const char*);
#endif

View File

@@ -1,6 +1,10 @@
#ifndef _USERSH_
#define _USERSH_
#include <sys/types.h>
struct user {
char *shell;
char *username;
char *display_name;
};
@@ -11,3 +15,5 @@ struct users_list {
};
struct users_list *get_human_users();
#endif

View File

@@ -1 +1,12 @@
#ifndef _UTILH_
#define _UTILH_
#include <keys.h>
#include <stdbool.h>
#include <sys/types.h>
enum keys find_ansi(char*);
void read_press(u_char*, char*);
void strcln(char **dest, const char *source);
#endif