aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJack Jamison <jackqjamison@gmail.com>2025-11-08 01:10:21 -0500
committerJack Jamison <jackqjamison@gmail.com>2025-11-08 01:10:21 -0500
commit6e038b0c45c1c2e351ce6ead8b80bc7b1031988f (patch)
treef8504b39e3785591d991d04e84e0448b62207df1
parentd4769b0f2e4012af5949651aca4f60ade5b97b54 (diff)
some quality of life
-rw-r--r--README.md4
-rw-r--r--args.c64
-rw-r--r--font.c3
-rw-r--r--main.c8
4 files changed, 42 insertions, 37 deletions
diff --git a/README.md b/README.md
index 5725de9..27d6fa1 100644
--- a/README.md
+++ b/README.md
@@ -45,6 +45,10 @@ cursor_color = (0.9, 0.9, 0.9, 0.5)
- [x] "prompt"
- [x] fuzzy filter
- [x] config file
+- [x] starting text
+- [x] if lines provided are less than specified, set lines to smallest possible amount
+- [ ] add ability to select the input field
+- [ ] fix prompt clipping issue
- [ ] border, top padding and set exact height
- [ ] unicode + text shaping + display unrenderable characters as something
diff --git a/args.c b/args.c
index 8c56da3..b992d7d 100644
--- a/args.c
+++ b/args.c
@@ -4,6 +4,7 @@
#include <getopt.h>
#include "args.h"
+#include "array.h"
void parse_args(client_state* state, int argc, char* argv[]) {
static struct option long_opts[] = {
@@ -15,41 +16,46 @@ void parse_args(client_state* state, int argc, char* argv[]) {
{"prompt", no_argument, 0, 'p'},
{"orderless", no_argument, 0, 'o'},
{"insensitive", no_argument, 0, 'i'},
+ {"starting-text", required_argument, 0, 's'},
{0, 0, 0, 0}
};
int opt;
int long_index = 0;
- while ((opt = getopt_long(argc, argv, "l:p:coievP", long_opts, &long_index)) != -1) {
+ while ((opt = getopt_long(argc, argv, "l:p:s:coievP", long_opts, &long_index)) != -1) {
switch (opt) {
- case 'l':
- state->lines = atoi(optarg);
- break;
- case 'p':
- state->prompt = optarg;
- break;
- case 'c':
- state->center = true;
- break;
- case 'e':
- state->exact_match = true;
- break;
- case 'v':
- state->verbose = true;
- break;
- case 'P':
- state->password = true;
- break;
- case 'o':
- state->orderless = true;
- break;
- case 'i':
- state->strstr = strcasestr;
- break;
- default:
- fprintf(stderr, "Usage: NOT WHAT YOU TYPED\n");
- fprintf(stderr, "%c\n", opt);
- break;
+ case 'l':
+ state->lines = MIN(atoi(optarg), array_size(state->items));
+ break;
+ case 'p':
+ state->prompt = optarg;
+ break;
+ case 'c':
+ state->center = true;
+ break;
+ case 'e':
+ state->exact_match = true;
+ break;
+ case 'v':
+ state->verbose = true;
+ break;
+ case 'P':
+ state->password = true;
+ break;
+ case 'o':
+ state->orderless = true;
+ break;
+ case 'i':
+ state->strstr = strcasestr;
+ break;
+ case 's':
+ array_insert_many(state->input_buffer, 0, optarg, strlen(optarg));
+ state->cursor_index = strlen(optarg);
+ break;
+ default:
+ fprintf(stderr, "Usage: NOT WHAT YOU TYPED\n");
+ fprintf(stderr, "%c\n", opt);
+ break;
}
}
}
diff --git a/font.c b/font.c
index b0efe94..29ee783 100644
--- a/font.c
+++ b/font.c
@@ -93,9 +93,6 @@ void atlas_init(client_state* state) {
metric->bearing_y = state->ft_face->glyph->bitmap_top;
state->atlas.vert_shift = MIN(state->atlas.vert_shift, (int32_t)metric->bearing_y - (int32_t)metric->bitmap_height);
-
- // fprintf(stderr, "%c: advance: (%f, %f), bitmap: (%u, %u), bearing: (%d, %d), vert_shift: %d\n",
- // (char)i, metric->advance_x, metric->advance_y, metric->bitmap_width, metric->bitmap_height, metric->bearing_x, metric->bearing_y, state->atlas.vert_shift);
}
}
diff --git a/main.c b/main.c
index b9d6ff0..4d7c89b 100644
--- a/main.c
+++ b/main.c
@@ -44,12 +44,9 @@ int main(int argc, char* argv[]) {
state.items = array_new(item_t, 0);
state.input_buffer = array_new(char, 0);
state.filtered_items = array_new(item_display_t, 0);
- state.selected_filtered_item = -1;
state.page_indices = array_new(size_t, 0);
state.strstr = strstr;
- init_conf();
-
// check locale
setlocale(LC_ALL, "");
const char *encoding = nl_langinfo(CODESET);
@@ -59,8 +56,9 @@ int main(int argc, char* argv[]) {
}
// read input
- parse_args(&state, argc, argv);
+ init_conf();
read_stdin(&state);
+ parse_args(&state, argc, argv);
// find font
char* font = get_font("Monospace");
@@ -102,7 +100,7 @@ int main(int argc, char* argv[]) {
if (state.prompt && *state.prompt) {
init_text_buffer(&state, &state.prompt_text_buffer, state.prompt, strlen(state.prompt));
}
- init_text_buffer(&state, &state.input_buffer_grafix, "", 0);
+ init_text_buffer(&state, &state.input_buffer_grafix, state.input_buffer, array_size(state.input_buffer));
array_for_all(item_t, item, state.items) {
init_text_buffer(&state, &item->text_buffer, item->text, strlen(item->text));
}