summaryrefslogtreecommitdiff
path: root/src/bin/termiointernals.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin/termiointernals.c')
-rw-r--r--src/bin/termiointernals.c141
1 files changed, 104 insertions, 37 deletions
diff --git a/src/bin/termiointernals.c b/src/bin/termiointernals.c
index 555c27a..cd17b29 100644
--- a/src/bin/termiointernals.c
+++ b/src/bin/termiointernals.c
@@ -5,6 +5,7 @@
5#include "termio.h" 5#include "termio.h"
6#include "miniview.h" 6#include "miniview.h"
7#include "termpty.h" 7#include "termpty.h"
8#include "backlog.h"
8#include "termptydbl.h" 9#include "termptydbl.h"
9#include "termptyops.h" 10#include "termptyops.h"
10#include "termiointernals.h" 11#include "termiointernals.h"
@@ -21,6 +22,16 @@ termio_selection_get(Termio *sd,
21{ 22{
22 int x, y; 23 int x, y;
23 24
25#define SB_ADD(STR, LEN) do { \
26 if (ty_sb_add(sb, STR, LEN) < 0) \
27 goto err; \
28} while (0)
29
30#define RTRIM() do { \
31 if (rtrim) \
32 ty_sb_spaces_rtrim(sb); \
33} while (0)
34
24 termpty_backlog_lock(); 35 termpty_backlog_lock();
25 for (y = c1y; y <= c2y; y++) 36 for (y = c1y; y <= c2y; y++)
26 { 37 {
@@ -33,51 +44,91 @@ termio_selection_get(Termio *sd,
33 cells = termpty_cellrow_get(sd->pty, y, &w); 44 cells = termpty_cellrow_get(sd->pty, y, &w);
34 if (!cells || !w) 45 if (!cells || !w)
35 { 46 {
36 if (ty_sb_add(sb, "\n", 1) < 0) goto err; 47 SB_ADD("\n", 1);
37 continue; 48 continue;
38 } 49 }
39 if (w > sd->grid.w) w = sd->grid.w; 50
51 /* Define how much needs to be read on that line */
52 if (w > sd->grid.w)
53 w = sd->grid.w;
40 if (y == c1y && c1x >= w) 54 if (y == c1y && c1x >= w)
41 { 55 {
42 if (rtrim) 56 RTRIM();
43 ty_sb_spaces_rtrim(sb); 57 SB_ADD("\n", 1);
44 if (ty_sb_add(sb, "\n", 1) < 0) goto err;
45 continue; 58 continue;
46 } 59 }
47 start_x = c1x; 60 start_x = c1x;
48 end_x = (c2x >= w) ? w - 1 : c2x; 61 end_x = (c2x >= w) ? w - 1 : c2x;
49 if (c1y != c2y) 62 if (c1y != c2y)
50 { 63 {
51 if (y == c1y) end_x = w - 1; 64 if (y == c1y)
52 else if (y == c2y) start_x = 0; 65 end_x = w - 1;
66 else if (y == c2y)
67 start_x = 0;
53 else 68 else
54 { 69 {
55 start_x = 0; 70 start_x = 0;
56 end_x = w - 1; 71 end_x = w - 1;
57 } 72 }
58 } 73 }
74
59 for (x = start_x; x <= end_x; x++) 75 for (x = start_x; x <= end_x; x++)
60 { 76 {
61 if ((cells[x].codepoint == 0) && (cells[x].att.dblwidth)) 77 if ((cells[x].codepoint == 0) && (cells[x].att.dblwidth))
62 { 78 {
63 if (x < end_x) x++; 79 if (x < end_x)
64 else break; 80 x++;
81 else
82 break;
83 }
84 if (x >= w)
85 break;
86 if (cells[x].att.tab_inserted)
87 {
88 /* There was a tab inserted.
89 * Only output it if there were spaces/empty cells "bellow"
90 */
91 Eina_Bool is_tab = EINA_TRUE;
92 while ((is_tab) && (x < end_x))
93 {
94 if (((cells[x].codepoint == 0) ||
95 (cells[x].att.invisible == 1) ||
96 (cells[x].codepoint == ' ')))
97 {
98 x++;
99 }
100 else
101 {
102 is_tab = EINA_FALSE;
103 }
104 if (cells[x].att.tab_last)
105 {
106 SB_ADD("\t", 1);
107 if (is_tab)
108 {
109 x++;
110 is_tab = EINA_FALSE;
111 }
112 break;
113 }
114 }
65 } 115 }
66 if (x >= w) break;
67 if (cells[x].att.newline) 116 if (cells[x].att.newline)
68 { 117 {
69 last0 = -1; 118 last0 = -1;
70 if ((y != c2y) || (x != end_x)) 119 if ((y != c2y) || (x != end_x))
71 { 120 {
72 if (rtrim) 121 RTRIM();
73 ty_sb_spaces_rtrim(sb); 122 SB_ADD("\n", 1);
74 if (ty_sb_add(sb, "\n", 1) < 0) goto err;
75 } 123 }
76 break; 124 break;
77 } 125 }
78 else if (cells[x].codepoint == 0) 126 else if (cells[x].codepoint == 0)
79 { 127 {
80 if (last0 < 0) last0 = x; 128 /* empty cell, track it to know whether to replace with
129 * spaces */
130 if (last0 < 0)
131 last0 = x;
81 } 132 }
82 else 133 else
83 { 134 {
@@ -90,27 +141,28 @@ termio_selection_get(Termio *sd,
90 last0 = -1; 141 last0 = -1;
91 while (v >= 0) 142 while (v >= 0)
92 { 143 {
93 if (ty_sb_add(sb, " ", 1) < 0) goto err; 144 SB_ADD(" ", 1);
94 v--; 145 v--;
95 } 146 }
96 } 147 }
97 txtlen = codepoint_to_utf8(cells[x].codepoint, txt); 148 txtlen = codepoint_to_utf8(cells[x].codepoint, txt);
98 if (txtlen > 0) 149 if (txtlen > 0)
99 if (ty_sb_add(sb, txt, txtlen) < 0) goto err; 150 SB_ADD(txt, txtlen);
100 if ((x == (w - 1)) && 151 if ((x == (w - 1)) &&
101 ((x != c2x) || (y != c2y))) 152 ((x != c2x) || (y != c2y)))
102 { 153 {
103 if (!cells[x].att.autowrapped) 154 if (!cells[x].att.autowrapped)
104 { 155 {
105 if (rtrim) 156 RTRIM();
106 ty_sb_spaces_rtrim(sb); 157 SB_ADD("\n", 1);
107 if (ty_sb_add(sb, "\n", 1) < 0) goto err;
108 } 158 }
109 } 159 }
110 } 160 }
111 } 161 }
112 if (last0 >= 0) 162 if (last0 >= 0)
113 { 163 {
164 /* line stop by empty cell, need to know whether to insert spaces
165 * or just go to next line */
114 if (y == c2y) 166 if (y == c2y)
115 { 167 {
116 Eina_Bool have_more = EINA_FALSE; 168 Eina_Bool have_more = EINA_FALSE;
@@ -120,8 +172,10 @@ termio_selection_get(Termio *sd,
120 if ((cells[x].codepoint == 0) && 172 if ((cells[x].codepoint == 0) &&
121 (cells[x].att.dblwidth)) 173 (cells[x].att.dblwidth))
122 { 174 {
123 if (x < (w - 1)) x++; 175 if (x < (w - 1))
124 else break; 176 x++;
177 else
178 break;
125 } 179 }
126 if (((cells[x].codepoint != 0) && 180 if (((cells[x].codepoint != 0) &&
127 (cells[x].codepoint != ' ')) || 181 (cells[x].codepoint != ' ')) ||
@@ -133,9 +187,8 @@ termio_selection_get(Termio *sd,
133 } 187 }
134 if (!have_more) 188 if (!have_more)
135 { 189 {
136 if (rtrim) 190 RTRIM();
137 ty_sb_spaces_rtrim(sb); 191 SB_ADD("\n", 1);
138 if (ty_sb_add(sb, "\n", 1) < 0) goto err;
139 } 192 }
140 else 193 else
141 { 194 {
@@ -144,31 +197,34 @@ termio_selection_get(Termio *sd,
144 if ((cells[x].codepoint == 0) && 197 if ((cells[x].codepoint == 0) &&
145 (cells[x].att.dblwidth)) 198 (cells[x].att.dblwidth))
146 { 199 {
147 if (x < (w - 1)) x++; 200 if (x < (w - 1))
148 else break; 201 x++;
202 else
203 break;
149 } 204 }
150 if (x >= w) break; 205 if (x >= w)
151 if (ty_sb_add(sb, " ", 1) < 0) goto err; 206 break;
207 SB_ADD(" ", 1);
152 } 208 }
153 } 209 }
154 } 210 }
155 else 211 else
156 { 212 {
157 if (rtrim) 213 RTRIM();
158 ty_sb_spaces_rtrim(sb); 214 SB_ADD("\n", 1);
159 if (ty_sb_add(sb, "\n", 1) < 0) goto err;
160 } 215 }
161 } 216 }
162 } 217 }
163 termpty_backlog_unlock(); 218 termpty_backlog_unlock();
164 219
165 if (rtrim) 220 RTRIM();
166 ty_sb_spaces_rtrim(sb);
167 221
168 return; 222 return;
169 223
170err: 224err:
171 ty_sb_free(sb); 225 ty_sb_free(sb);
226#undef SB_ADD
227#undef RTRIM
172} 228}
173 229
174 230
@@ -359,9 +415,21 @@ termio_internal_get_selection(Termio *sd, size_t *lenp)
359 415
360 if (isb.len) 416 if (isb.len)
361 { 417 {
418 int res;
362 if (isb.buf[isb.len - 1] != '\n' && i != end_y) 419 if (isb.buf[isb.len - 1] != '\n' && i != end_y)
363 ty_sb_add(&isb, "\n", 1); 420 {
364 ty_sb_add(&sb, isb.buf, isb.len); 421 res = ty_sb_add(&isb, "\n", 1);
422 if (res < 0)
423 {
424 ERR("failure to add newline to selection buffer");
425 }
426 }
427 res = ty_sb_add(&sb, isb.buf, isb.len);
428 if (res < 0)
429 {
430 ERR("failure to add %zd characters to selection buffer",
431 isb.len);
432 }
365 } 433 }
366 ty_sb_free(&isb); 434 ty_sb_free(&isb);
367 } 435 }
@@ -1305,8 +1373,6 @@ _selection_newline_extend_fix(Termio *sd)
1305 termpty_backlog_unlock(); 1373 termpty_backlog_unlock();
1306} 1374}
1307 1375
1308/* }}} */
1309
1310void 1376void
1311termio_selection_dbl_fix(Termio *sd) 1377termio_selection_dbl_fix(Termio *sd)
1312{ 1378{
@@ -1393,6 +1459,7 @@ termio_selection_dbl_fix(Termio *sd)
1393 sd->pty->selection.end.y = end_y; 1459 sd->pty->selection.end.y = end_y;
1394} 1460}
1395 1461
1462/* }}} */
1396 1463
1397static void 1464static void
1398_handle_mouse_down_single_click(Termio *sd, 1465_handle_mouse_down_single_click(Termio *sd,