remove things from nenu.c

This commit is contained in:
randomuser 2020-12-20 17:52:05 -06:00
parent 273614deb8
commit 99c3c87beb
2 changed files with 4 additions and 137 deletions

View File

@ -4,7 +4,7 @@ MANDIR?=${PREFIX}/share/man
all: nenu
nenu: nenu.c config.h
nenu: nenu.c
gcc -o nenu nenu.c \
-lX11 \
-lXft \
@ -20,24 +20,9 @@ clean:
rm nenu
rm nenu.1.gz
nenu.1.gz: nenu.1
gzip -k nenu.1
.PHONY:
install-man: nenu.1.gz
install -D nenu.1.gz ${DESTDIR}${MANDIR}/man1/nenu.1.gz
.PHONY:
install-nenu: nenu
install -Dm 755 nenu ${DESTDIR}${PREFIX}/bin/nenu
.PHONY:
install: install-man install-nenu
.PHONY:
uninstall-man:
rm ${DESTDIR}${PREFIX}/man/man1/nenu.1.gz
.PHONY:
uninstall: uninstall-man
install: install-nenu

122
nenu.c
View File

@ -82,15 +82,6 @@ static FcChar8 prompt[MAX_LEN] = {'\0'};
static option *options = NULL;
static option *valid = NULL;
void usage() {
printf(
"usage: nenu [options] [prompt]\n"
"\n"
" nenu takes options from stdin and displays them in a list,\n"
" allowing the user to choose their deisred option.\n"
);
}
void clean_resources() {
XUngrabKeyboard(display, CurrentTime);
XUngrabPointer(display, CurrentTime);
@ -122,7 +113,7 @@ int text_width(FcChar8 *s) {
/* XftTextExtentsUtf8 doesn't seem to know what a space is. */
char str[MAX_LEN];
strcpy(str, s);
for (i = 0; i < len; i++)
for (i = 0; i < len; i++)
if (str[i] == ' ') str[i] = '-';
XftTextExtentsUtf8(display, font, str, len, &g);
@ -214,35 +205,6 @@ size_t nextrune(int inc) {
return n;
}
void handle_button(XButtonEvent be) {
option *o;
switch(be.button) {
case Button4:
if (valid->prev)
valid = valid->prev;
else
for (; valid && valid->next;
valid = valid->next);
break;
case Button5:
if (valid->next)
valid = valid->next;
else
for (; valid && valid->prev;
valid = valid->prev);
break;
case Button1:
finish();
break;
case Button3:
finish();
break;
case Button2:
finish();
break;
}
}
void handle_key(XKeyEvent ke) {
FcChar8 buf[32];
int len, n;
@ -255,44 +217,6 @@ void handle_key(XKeyEvent ke) {
if (status == XBufferOverflow)
return;
if (ke.state & ControlMask) {
switch(keysym) {
case XK_a:
keysym = XK_Home;
break;
case XK_e:
keysym = XK_End;
break;
case XK_p:
keysym = XK_Up;
break;
case XK_n:
keysym = XK_Down;
break;
case XK_f:
keysym = XK_Right;
break;
case XK_b:
keysym = XK_Left;
break;
case XK_d:
keysym = XK_Delete;
break;
case XK_bracketleft:
keysym = XK_Escape;
break;
case XK_k:
text[cursor] = '\0';
break;
case XK_u:
for (n = cursor; cursor < MAX_LEN; cursor++)
text[cursor - n] = text[cursor];
cursor = 0;
update_valid_options();
return;
}
}
if (text_input) {
switch(keysym) {
default:
@ -318,44 +242,10 @@ void handle_key(XKeyEvent ke) {
case XK_Tab:
copy_first();
break;
case XK_Left:
if (cursor != 0)
cursor = nextrune(-1);
break;
case XK_Right:
if (text[cursor] != '\0')
cursor = nextrune(+1);
break;
case XK_Home:
cursor = 0;
break;
case XK_End:
while (text[cursor] != '\0')
cursor = nextrune(+1);
}
}
}
switch(keysym) {
case XK_Up:
if (valid->prev)
valid = valid->prev;
else
for (;
valid && valid->next;
valid = valid->next);
break;
case XK_Down:
if (valid->next)
valid = valid->next;
else
for (;
valid && valid->prev;
valid = valid->prev);
break;
case XK_Return:
finish();
break;
@ -625,9 +515,6 @@ int main(int argc, char *argv[]) {
} else if (argv[i][0] == '-') {
switch (argv[i][1])
{
case 'h':
usage();
exit(EXIT_SUCCESS);
case 'o': exit_on_one = 1; break;
case 'f': first_on_exit = 1; break;
case 't': text_input = 0; break;
@ -637,7 +524,6 @@ int main(int argc, char *argv[]) {
default:
fprintf(stderr, "Unknown option: %s\n",
argv[i]);
usage();
exit(EXIT_FAILURE);
}
} else {
@ -660,10 +546,6 @@ int main(int argc, char *argv[]) {
handle_key(ev.xkey);
render();
break;
case ButtonRelease:
handle_button(ev.xbutton);
render();
break;
case Expose:
XRaiseWindow(display, win);
render();