diff options
author | wrmr | 2024-11-06 02:09:26 -0500 |
---|---|---|
committer | wrmr | 2024-11-06 02:09:26 -0500 |
commit | a3f7fb80590705c1a7d7b42edd8f5f1362f09cfa (patch) | |
tree | 8d12c8f92c13c327571e77b8604b25801520afc7 | |
parent | d2c280d441ddf974c90447d0a9252f5711802304 (diff) |
MORE prompt
-rw-r--r-- | doc.c | 8 | ||||
-rw-r--r-- | doc.h | 2 | ||||
-rw-r--r-- | main.c | 6 | ||||
-rw-r--r-- | nav.c | 5 | ||||
-rw-r--r-- | nav.h | 2 |
5 files changed, 20 insertions, 3 deletions
diff --git a/doc.c b/doc.c index d41db7c..38b4802 100644 --- a/doc.c +++ b/doc.c @@ -71,6 +71,14 @@ struct doc_line *doc_line_at(struct doc *d, size_t ofs) { return (struct doc_line *)&d->txt.buf[ofs]; } +int doc_line_nextp(struct doc *d, size_t ofs) { + return ofs + doc_line_at(d, ofs)->len + sizeof(struct doc_line) < d->txt.sz; +} + +int doc_line_prevp(struct doc *d, size_t ofs) { + return ofs >= doc_line_at(d, ofs)->prev + sizeof(struct doc_line); +} + int doc_line_prev(struct doc *d, size_t *ofs) { size_t n = doc_line_at(d, *ofs)->prev + sizeof(struct doc_line); if (*ofs >= n) { diff --git a/doc.h b/doc.h index ab66272..132999e 100644 --- a/doc.h +++ b/doc.h @@ -32,6 +32,8 @@ void doc_add_text(struct doc *, const char *); void doc_add_textn(struct doc *, const char *, size_t); struct doc_line *doc_line_at(struct doc *d, size_t ofs); +int doc_line_prevp(struct doc *d, size_t ofs); +int doc_line_nextp(struct doc *d, size_t ofs); int doc_line_prev(struct doc *d, size_t *ofs); int doc_line_next(struct doc *d, size_t *ofs); diff --git a/main.c b/main.c index 3026e23..2150d57 100644 --- a/main.c +++ b/main.c @@ -74,8 +74,8 @@ void cmd_trim(char *buf, size_t max) { } } -int cmd_get(char *buf, size_t n) { - fputs("* ", stdout); +int cmd_get(char *buf, size_t n, struct nav_state *ns) { + nav_prompt(ns); return !!fgets(buf, n, stdin); } @@ -88,7 +88,7 @@ int main(int argc, const char **argv) { } else { nav_redraw(&ns); } - while (cmd_get(cmd_buf, sizeof cmd_buf)) { + while (cmd_get(cmd_buf, sizeof cmd_buf, &ns)) { cmd_trim(cmd_buf, sizeof cmd_buf); if (cmd_do(cmd_buf, &ns)) { break; diff --git a/nav.c b/nav.c index 0a3e773..8456a76 100644 --- a/nav.c +++ b/nav.c @@ -129,3 +129,8 @@ int nav_link_nr(struct nav_state *ns, unsigned long link_nr) { } return 0; } + +void nav_prompt(struct nav_state *ns) { + int m = doc_line_nextp(&ns->histv[ns->cur_doc], ns->cur_ofs[ns->cur_doc]); + fputs(m ? "MORE* " : "* ", stdout); +} diff --git a/nav.h b/nav.h index 0afcfaf..769096f 100644 --- a/nav.h +++ b/nav.h @@ -25,4 +25,6 @@ void nav_redraw(struct nav_state *ns); int nav_to(struct nav_state *ns, const char *url); int nav_link_nr(struct nav_state *ns, unsigned long link_nr); +void nav_prompt(struct nav_state *ns); + #endif |