1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
From de7a1acf3168a35c19a569cc7f6f572c39e96c82 Mon Sep 17 00:00:00 2001
From: Michael Forney <mforney@mforney.org>
Date: Thu, 3 Jun 2021 00:32:57 -0700
Subject: [PATCH] Don't wrap when adding past last line in non-scrolling window
X/Open curses says
> If scrolling is disabled, any characters that would extend beyond
> the last column of the last line are truncated.
However, currently libcurses wraps the cursor back to the beginning
of the last line.
To fix this, when we try to add a character that would go past the
end of the last line, leave the cursor where it is. If the character
goes exactly to the end of the last line, add the character but set
the cursor to the last column (to match ncurses behavior).
[0] https://pubs.opengroup.org/onlinepubs/7908799/xcurses/intov.html#tag_001_004_002_002
---
lib/libcurses/addbytes.c | 20 +++++++++++---------
1 file changed, 11 insertions(+), 9 deletions(-)
diff --git a/lib/libcurses/addbytes.c b/lib/libcurses/addbytes.c
index 9fd917ca..e52dc310 100644
--- a/lib/libcurses/addbytes.c
+++ b/lib/libcurses/addbytes.c
@@ -232,8 +232,6 @@ _cursesi_addbyte(WINDOW *win, __LINE **lp, int *y, int *x, int c,
#endif
if (char_interp && ((*lp)->flags & __ISPASTEOL)) {
- *x = 0;
- (*lp)->flags &= ~__ISPASTEOL;
if (*y == win->scr_b) {
#ifdef DEBUG
__CTRACE(__CTRACE_INPUT,
@@ -246,6 +244,8 @@ _cursesi_addbyte(WINDOW *win, __LINE **lp, int *y, int *x, int c,
} else {
(*y)++;
}
+ *x = 0;
+ (*lp)->flags &= ~__ISPASTEOL;
*lp = win->alines[*y];
if (c == '\n')
return OK;
@@ -341,8 +341,6 @@ _cursesi_addwchar(WINDOW *win, __LINE **lnp, int *y, int *x,
return OK;
case L'\n':
wclrtoeol(win);
- *x = 0;
- (*lnp)->flags &= ~__ISPASTEOL;
if (*y == win->scr_b) {
if (!(win->flags & __SCROLLOK))
return ERR;
@@ -350,6 +348,8 @@ _cursesi_addwchar(WINDOW *win, __LINE **lnp, int *y, int *x,
} else {
(*y)++;
}
+ *x = 0;
+ (*lnp)->flags &= ~__ISPASTEOL;
return OK;
case L'\t':
cc.vals[0] = L' ';
@@ -395,8 +395,6 @@ _cursesi_addwchar(WINDOW *win, __LINE **lnp, int *y, int *x,
}
/* check for new line first */
if (char_interp && ((*lnp)->flags & __ISPASTEOL)) {
- *x = 0;
- (*lnp)->flags &= ~__ISPASTEOL;
if (*y == win->scr_b) {
if (!(win->flags & __SCROLLOK))
return ERR;
@@ -404,6 +402,8 @@ _cursesi_addwchar(WINDOW *win, __LINE **lnp, int *y, int *x,
} else {
(*y)++;
}
+ *x = 0;
+ (*lnp)->flags &= ~__ISPASTEOL;
(*lnp) = win->alines[*y];
lp = &win->alines[*y]->line[*x];
}
@@ -459,7 +459,6 @@ _cursesi_addwchar(WINDOW *win, __LINE **lnp, int *y, int *x,
if (newx > *(*lnp)->lastchp)
*(*lnp)->lastchp = newx;
__touchline(win, *y, sx, (int) win->maxx - 1);
- sx = *x = 0;
if (*y == win->scr_b) {
if (!(win->flags & __SCROLLOK))
return ERR;
@@ -467,6 +466,7 @@ _cursesi_addwchar(WINDOW *win, __LINE **lnp, int *y, int *x,
} else {
(*y)++;
}
+ sx = *x = 0;
lp = &win->alines[*y]->line[0];
(*lnp) = win->alines[*y];
}
@@ -547,14 +547,16 @@ _cursesi_addwchar(WINDOW *win, __LINE **lnp, int *y, int *x,
if (newx > *(*lnp)->lastchp)
*(*lnp)->lastchp = newx;
__touchline(win, *y, sx, (int) win->maxx - 1);
- *x = sx = 0;
if (*y == win->scr_b) {
- if (!(win->flags & __SCROLLOK))
+ if (!(win->flags & __SCROLLOK)) {
+ *x = win->maxx - 1;
return ERR;
+ }
scroll(win);
} else {
(*y)++;
}
+ *x = sx = 0;
lp = &win->alines[*y]->line[0];
(*lnp) = win->alines[*y];
} else {
--
2.31.1
|