mirror of
https://github.com/javalsai/lidm.git
synced 2026-02-27 12:00:44 +01:00
* chore(organization): allow nested header and c files * feat: add shell login "middleware" & etc: * lidm now calls `bash` (or other shells, depends on PACKAGE cfg) in login mode as a session wrapper to source most env (can be disabled) * this fixes a lot of env problems with all `/etc/profile` and more Extra: * implemented a musl compatible version of `execvpe` and now lidm should search for PATH everywhere it needs to * `search_path` now also checks if the found binary is properly executable * lidm now uses `confstr` for a decent PATH default if none is found * logs are unbuffered for cases where debug logs appear empty (exit without handlers moment) * chore: one-time evaluate certain makefile vars --------- Co-authored-by: grialion <48643945+grialion@users.noreply.github.com>
121 lines
2.4 KiB
C
121 lines
2.4 KiB
C
#ifndef KEYSH_
|
|
#define KEYSH_
|
|
|
|
#include <stdbool.h>
|
|
#include <stdint.h>
|
|
#include <stdlib.h>
|
|
#include <sys/time.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,
|
|
NONE,
|
|
};
|
|
|
|
static const char* const KEY_NAMES[] = {
|
|
[NONE] = "NONE",
|
|
[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}},
|
|
};
|
|
|
|
struct option_keys {
|
|
bool is_some;
|
|
enum Keys key;
|
|
};
|
|
|
|
int find_keyname(enum Keys* at, const char* name);
|
|
struct option_keys find_ansi(const char* seq);
|
|
void read_press(uint8_t* length, char* out);
|
|
// non blocking, waits up to tv or interrupt, returns true if actually read
|
|
bool read_press_nb(uint8_t* length, char* out, struct timeval* tv);
|
|
|
|
#endif
|