summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwrmr2025-06-24 17:26:51 -0400
committerwrmr2025-06-24 17:26:51 -0400
commit8a3da522978123e9c37c26111694e79901d5f8c2 (patch)
tree3d0000e2861d1b9e0dbd7c4c1b2e1d43c9390d79
parentd67eab5fb62ec69980057275af38ae8527534312 (diff)
make pages no larger than a screenful
-rw-r--r--main.c35
1 files changed, 29 insertions, 6 deletions
diff --git a/main.c b/main.c
index c458139..40d861e 100644
--- a/main.c
+++ b/main.c
@@ -5,6 +5,11 @@
/* TODO:
*
+ * - add a little temporary message line, maybe at the top of the screen
+ * + log_warn() goes here
+ * + "message not yours to edit"
+ * + "got 78 users and 722 posts in [nanoseconds?]"
+ *
* - make it so that page up/page down act based on number of lines
* traversed, not abstract number of posts skipped
*
@@ -38,7 +43,8 @@
#include "arena.h"
#define POST_LIMIT 200 /* see bink.py */
-#define PAGE_LEN 10
+#define PAGE_LEN getmaxy(stdscr)
+#define HALF_PAGE_LEN ((getmaxy(stdscr) * 75) / 100)
#define GFX_MARGIN_X 2
#define GFX_MARGIN_Y 1
#define GFX_TEXT_MARGIN_X 1
@@ -420,8 +426,23 @@ void new_post(Arena *temp) {
fclose(f);
}
-/* this will probably crash if there are zero posts */
+/* will skip at least one post, so not suitable for just scrolling one line at
+ * a time like bink.py does */
+int line_skip(int cur, Gfx *gfx, int amt) {
+ int sign = amt < 0 ? -1 : 1;
+ amt = abs(amt);
+ while (amt > 0 && (sign < 0 ? cur > 0 : cur + 1 < gfx->len)) {
+ amt -= gfx_post_height(&gfx->posts[cur]) + 1;
+ cur += sign;
+ }
+ if (amt < 0) {
+ if (sign < 0 && cur + 1 < gfx->len) cur++;
+ else if (sign > 0 && cur > 0) cur--;
+ }
+ return cur;
+}
+/* might crash on zero posts? */
int main(void) {
/* init */
@@ -476,16 +497,18 @@ int main(void) {
case ' ':
case 'd':
case KEY_NPAGE:
+ cur = line_skip(cur, &gfx, PAGE_LEN);
+ break;
case 0x04 /* ^D */:
- cur += PAGE_LEN;
- if (cur > posts.len - 1) cur = posts.len - 1;
+ cur = line_skip(cur, &gfx, HALF_PAGE_LEN);
break;
case 'b':
case 'u':
case KEY_PPAGE:
+ cur = line_skip(cur, &gfx, -PAGE_LEN);
+ break;
case 0x15 /* ^U */:
- cur -= PAGE_LEN;
- if (cur < 0) cur = 0;
+ cur = line_skip(cur, &gfx, -HALF_PAGE_LEN);
break;
case 'e':
if (my_post(&posts.data[cur])) {