mirror of https://github.com/ericonr/ef.git
Add print_prompt funtion.
This commit is contained in:
parent
55ae15eb6f
commit
69efce1d95
17
ef.c
17
ef.c
|
@ -165,10 +165,6 @@ int main(int argc, char **argv)
|
|||
}
|
||||
keypad(prompt, TRUE);
|
||||
|
||||
/* initial prompt */
|
||||
mvwaddstr(prompt, 0, 0, "> ");
|
||||
wrefresh(prompt);
|
||||
|
||||
/* index in entries, index in matched;
|
||||
* this function could include a wclrtoeol call, but that only hides indexing issues */
|
||||
#define WRITELIST(idx, idxm) \
|
||||
|
@ -188,6 +184,8 @@ int main(int argc, char **argv)
|
|||
char *name = NULL;
|
||||
/* search tokens */
|
||||
struct str_array toks = { 0 };
|
||||
print_prompt(prompt, &toks, true);
|
||||
|
||||
/* index inside set of matches */
|
||||
size_t index_in_matched = 0;
|
||||
for (;;) {
|
||||
|
@ -317,16 +315,9 @@ int main(int argc, char **argv)
|
|||
continue;
|
||||
}
|
||||
|
||||
werase(prompt);
|
||||
mvwaddstr(prompt, 0, 0, ">");
|
||||
for (size_t i = 0; i < toks.n; i++) {
|
||||
const char *e = get_entry(&toks, i);
|
||||
waddch(prompt, ' ');
|
||||
waddstr(prompt, e);
|
||||
}
|
||||
/* show space if name is NULL */
|
||||
if (!name) waddch(prompt, ' ');
|
||||
wrefresh(prompt);
|
||||
print_prompt(prompt, &toks, !name);
|
||||
|
||||
/* name==NULL means the search results won't change,
|
||||
* so we don't need to search again */
|
||||
if (!name) continue;
|
||||
|
|
13
util.c
13
util.c
|
@ -23,6 +23,19 @@ void read_entries_from_stream(struct str_array *a, int delim, FILE *input)
|
|||
}
|
||||
}
|
||||
|
||||
void print_prompt(WINDOW *w, struct str_array *a, bool show_space)
|
||||
{
|
||||
werase(w);
|
||||
mvwaddstr(w, 0, 0, ">");
|
||||
for (size_t i = 0; i < a->n; i++) {
|
||||
const char *e = get_entry(a, i);
|
||||
waddch(w, ' ');
|
||||
waddstr(w, e);
|
||||
}
|
||||
if (show_space) waddch(w, ' ');
|
||||
wrefresh(w);
|
||||
}
|
||||
|
||||
void *xmalloc(size_t s) {
|
||||
void *r = malloc(s);
|
||||
if (r) return r;
|
||||
|
|
4
util.h
4
util.h
|
@ -1,11 +1,15 @@
|
|||
#ifndef UTIL_H
|
||||
#define UTIL_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <curses.h>
|
||||
|
||||
#include "string-array.h"
|
||||
|
||||
void read_entries_from_stream(struct str_array *, int, FILE *);
|
||||
void print_prompt(WINDOW *, struct str_array *, bool);
|
||||
void *xmalloc(size_t);
|
||||
void *xrealloc(void *, size_t);
|
||||
|
||||
|
|
Loading…
Reference in New Issue