Skip to content

Commit

Permalink
^G^G RET action cancelling
Browse files Browse the repository at this point in the history
  • Loading branch information
em1lyy committed Jul 18, 2021
1 parent 0fe3d00 commit c9aea1f
Showing 1 changed file with 36 additions and 8 deletions.
44 changes: 36 additions & 8 deletions nezumi.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ void hist_next();
void bookmark_add_prompt();
void load_bookmarks();
void add_bookmark(struct bookmark *bm, int disable_mem_write);
int endswith(const char *str, const char *suffix);

struct simplepage *currentsite = NULL;
struct simplepage **history = NULL;
Expand Down Expand Up @@ -326,7 +327,12 @@ void prompt_url() {
echo();
if (getnstr(gotourl, MAXURLLEN - 2) != ERR) {
attroff(A_REVERSE);
load_page(gotourl);
if (!endswith(gotourl, "\a\a")) {
load_page(gotourl);
} else {
attroff(A_REVERSE);
free(gotourl);
}
} else {
attroff(A_REVERSE);
free(gotourl);
Expand Down Expand Up @@ -361,7 +367,12 @@ void prompt_index(unsigned int linum) {
echo();
if (getnstr(squery, MAXURLLEN - 2) != ERR) {
attroff(A_REVERSE);
currentsite = followprompt(currentsite, linum, squery);
if (!endswith(squery, "\a\a")) {
currentsite = followprompt(currentsite, linum, squery);
} else {
attroff(A_REVERSE);
free(squery);
}
} else {
attroff(A_REVERSE);
free(squery);
Expand Down Expand Up @@ -396,7 +407,11 @@ void prompt_download(unsigned int linum) {
echo();
if (getnstr(fname, MAXURLLEN - 2) != ERR) {
attroff(A_REVERSE);
followbinary(currentsite, linum, fname);
if (!endswith(fname, "\a\a")) {
followbinary(currentsite, linum, fname);
} else {
free(fname);
}
} else {
free(fname);
}
Expand Down Expand Up @@ -512,11 +527,13 @@ void bookmark_add_prompt() {
echo();
if (getnstr(bmname, 254) != ERR) {
attroff(A_REVERSE);
struct bookmark *bm = malloc(sizeof(struct bookmark));
strncpy(bm->name, bmname, 255);
strncpy(bm->url, currentsite->meta->url, 1022);
bm->url[1022] = '\0'; /* ensure null termination */
add_bookmark(bm, 0);
if (!endswith(bmname, "\a\a")) {
struct bookmark *bm = malloc(sizeof(struct bookmark));
strncpy(bm->name, bmname, 255);
strncpy(bm->url, currentsite->meta->url, 1022);
bm->url[1022] = '\0'; /* ensure null termination */
add_bookmark(bm, 0);
}
}
free(bmname);
attroff(A_REVERSE);
Expand Down Expand Up @@ -607,3 +624,14 @@ void add_bookmark(struct bookmark *bm, int disable_mem_write) {
}
}
}

/* string ends-with helper function */
int endswith(const char *str, const char *suffix) {
if (!str || !suffix)
return 0;
int lenstr = strlen(str);
int lensuffix = strlen(suffix);
if (lensuffix > lenstr)
return 0;
return strncmp(str + lenstr - lensuffix, suffix, lensuffix) == 0;
}

0 comments on commit c9aea1f

Please sign in to comment.