Commit: 6bd4cdf7b61e6779842fd151f2419b8029dc9f4c
Parent: 5cfed867fbcbf3da79163eb1a960e2956bd6e14d
Author: Randy Palamar
Date: Fri, 14 Feb 2025 21:01:55 -0700
terminal: fix top and bottom margin setting
The default bottom when one is not specified is supposed to be the
bottom most row and when the requested margins are equal we should
ignore the request.
This fixes all 4 related tests (2 was actually fine but the test
needed to be fixed).
Diffstat:
2 files changed, 12 insertions(+), 15 deletions(-)
diff --git a/terminal.c b/terminal.c
@@ -829,17 +829,15 @@ set_colours(Term *t, CSI *csi)
}
static void
-set_scrolling_region(Term *t, i32 top, i32 bot)
+set_top_bottom_margins(Term *t, i32 requested_top, i32 requested_bottom)
{
- CLAMP(top, 0, t->size.h - 1);
- CLAMP(bot, 0, t->size.h - 1);
- if (top > bot) {
- i32 tmp = top;
- top = bot;
- bot = tmp;
+ i32 top = MIN(MAX(1, requested_top), t->size.h);
+ i32 bottom = MIN(t->size.h, (requested_bottom ? requested_bottom : t->size.h));
+ if (top < bottom) {
+ t->top = top - 1;
+ t->bot = bottom - 1;
+ cursor_move_abs_to(t, 0, 0);
}
- t->top = top;
- t->bot = bot;
}
static void
@@ -957,8 +955,7 @@ handle_csi(Term *t, CSI *csi)
/* NOTE: XTRESTORE: restore the value of a private mode */
set_mode(t, csi, 1, t->saved_mode, &t->mode);
} else {
- set_scrolling_region(t, ORONE(csi->argv[0]) - 1, ORONE(csi->argv[1]) - 1);
- cursor_move_abs_to(t, 0, 0);
+ set_top_bottom_margins(t, csi->argv[0], csi->argv[1]);
}
break;
case 's':
diff --git a/tests/test.c b/tests/test.c
@@ -896,7 +896,7 @@ static TEST_FN(set_top_bottom_margins_v1)
{
struct test_result result = {.info = __FUNCTION__};
- launder_static_string(term, s8("ABC\nDEF\nGHI\n"));
+ launder_static_string(term, s8("ABC\r\nDEF\r\nGHI\r\n"));
launder_static_string(term, CSI(r));
s8 raw = launder_static_string(term, CSI(T));
handle_input(term, arena, raw);
@@ -924,7 +924,7 @@ static TEST_FN(set_top_bottom_margins_v2)
{
struct test_result result = {.info = __FUNCTION__};
- launder_static_string(term, s8("ABC\nDEF\nGHI\n"));
+ launder_static_string(term, s8("ABC\r\nDEF\r\nGHI\r\n"));
launder_static_string(term, CSI(2r));
s8 raw = launder_static_string(term, CSI(T));
handle_input(term, arena, raw);
@@ -951,7 +951,7 @@ static TEST_FN(set_top_bottom_margins_v3)
{
struct test_result result = {.info = __FUNCTION__};
- launder_static_string(term, s8("ABC\nDEF\nGHI\n"));
+ launder_static_string(term, s8("ABC\r\nDEF\r\nGHI\r\n"));
launder_static_string(term, CSI(1;2r));
s8 raw = launder_static_string(term, CSI(T));
handle_input(term, arena, raw);
@@ -975,7 +975,7 @@ static TEST_FN(set_top_bottom_margins_v4)
{
struct test_result result = {.info = __FUNCTION__};
- launder_static_string(term, s8("ABC\nDEF\nGHI\n"));
+ launder_static_string(term, s8("ABC\r\nDEF\r\nGHI\r\n"));
launder_static_string(term, CSI(2;2r));
s8 raw = launder_static_string(term, CSI(T));
handle_input(term, arena, raw);