summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Faure <billiob@gmail.com>2017-06-05 17:43:23 +0200
committerBoris Faure <billiob@gmail.com>2017-06-05 17:43:23 +0200
commit7ea4b65c8dd3ab2eb5e27f363d29d3fd96d26a7d (patch)
treebc8e5380148920b3471bc3a72401494da65b4e77
parente117ff9153e491222754e9b835963ad660831e92 (diff)
termptyops: handle right/left margins. Ref T5533
-rw-r--r--src/bin/termptyops.c79
1 files changed, 46 insertions, 33 deletions
diff --git a/src/bin/termptyops.c b/src/bin/termptyops.c
index c6a93dd..a3646d5 100644
--- a/src/bin/termptyops.c
+++ b/src/bin/termptyops.c
@@ -38,40 +38,47 @@ termpty_text_scroll(Termpty *ty, Eina_Bool clear)
38 Termcell *cells = NULL, *cells2; 38 Termcell *cells = NULL, *cells2;
39 int y, start_y = 0, end_y = ty->h - 1; 39 int y, start_y = 0, end_y = ty->h - 1;
40 40
41 start_y = ty->termstate.top_margin;
41 if (ty->termstate.bottom_margin != 0) 42 if (ty->termstate.bottom_margin != 0)
42 { 43 end_y = ty->termstate.bottom_margin - 1;
43 start_y = ty->termstate.top_margin; 44 if (!(ty->termstate.top_margin || ty->termstate.bottom_margin ||
44 end_y = ty->termstate.bottom_margin - 1; 45 ty->termstate.left_margin || ty->termstate.right_margin) &&
45 } 46 (!ty->altbuf))
46 else 47 termpty_text_save_top(ty, &(TERMPTY_SCREEN(ty, 0, 0)), ty->w);
47 if (!ty->altbuf)
48 termpty_text_save_top(ty, &(TERMPTY_SCREEN(ty, 0, 0)), ty->w);
49 48
50 termio_scroll(ty->obj, -1, start_y, end_y); 49 termio_scroll(ty->obj, -1, start_y, end_y);
51 DBG("... scroll!!!!! [%i->%i]", start_y, end_y); 50 DBG("... scroll!!!!! [%i->%i]", start_y, end_y);
52 51
53 if (start_y == 0 && end_y == ty->h - 1) 52 if ((start_y == 0 && end_y == ty->h - 1) &&
53 (ty->termstate.left_margin == 0) &&
54 (ty->termstate.right_margin == 0))
54 { 55 {
55 // screen is a circular buffer now 56 // screen is a circular buffer now
56 cells = &(ty->screen[ty->circular_offset * ty->w]); 57 cells = &(ty->screen[ty->circular_offset * ty->w]);
57 if (clear) 58 if (clear)
58 termpty_cells_clear(ty, cells, ty->w); 59 termpty_cells_clear(ty, cells, ty->w);
59 60
60 ty->circular_offset++; 61 ty->circular_offset++;
61 if (ty->circular_offset >= ty->h) 62 if (ty->circular_offset >= ty->h)
62 ty->circular_offset = 0; 63 ty->circular_offset = 0;
63 } 64 }
64 else 65 else
65 { 66 {
66 cells = &(TERMPTY_SCREEN(ty, 0, end_y)); 67 int x = ty->termstate.left_margin;
67 for (y = start_y; y < end_y; y++) 68 int w = ty->w;
68 { 69
69 cells = &(TERMPTY_SCREEN(ty, 0, (y + 1))); 70 if (ty->termstate.right_margin)
70 cells2 = &(TERMPTY_SCREEN(ty, 0, y)); 71 w = ty->termstate.right_margin - x;
71 termpty_cell_copy(ty, cells, cells2, ty->w); 72
72 } 73 cells = &(TERMPTY_SCREEN(ty, x, end_y));
73 if (clear) 74 for (y = start_y; y < end_y; y++)
74 termpty_cells_clear(ty, cells, ty->w); 75 {
76 cells = &(TERMPTY_SCREEN(ty, x, (y + 1)));
77 cells2 = &(TERMPTY_SCREEN(ty, x, y));
78 termpty_cell_copy(ty, cells, cells2, w);
79 }
80 if (clear)
81 termpty_cells_clear(ty, cells + x, w);
75 } 82 }
76} 83}
77 84
@@ -147,7 +154,13 @@ termpty_text_append(Termpty *ty, const Eina_Unicode *codepoints, int len)
147{ 154{
148 Termcell *cells; 155 Termcell *cells;
149 int i, j; 156 int i, j;
157 int origin = ty->termstate.left_margin;
158 int max_right = ty->w;
159
160 if (ty->termstate.right_margin)
161 max_right = ty->termstate.right_margin;
150 162
163 /* TODO: have content_change_box*/
151 termio_content_change(ty->obj, ty->cursor_state.cx, ty->cursor_state.cy, len); 164 termio_content_change(ty->obj, ty->cursor_state.cx, ty->cursor_state.cy, len);
152 165
153 cells = &(TERMPTY_SCREEN(ty, 0, ty->cursor_state.cy)); 166 cells = &(TERMPTY_SCREEN(ty, 0, ty->cursor_state.cy));
@@ -157,16 +170,16 @@ termpty_text_append(Termpty *ty, const Eina_Unicode *codepoints, int len)
157 170
158 if (ty->termstate.wrapnext) 171 if (ty->termstate.wrapnext)
159 { 172 {
160 cells[ty->w - 1].att.autowrapped = 1; 173 cells[max_right-1].att.autowrapped = 1;
161 ty->termstate.wrapnext = 0; 174 ty->termstate.wrapnext = 0;
162 ty->cursor_state.cx = 0; 175 ty->cursor_state.cx = origin;
163 ty->cursor_state.cy++; 176 ty->cursor_state.cy++;
164 termpty_text_scroll_test(ty, EINA_TRUE); 177 termpty_text_scroll_test(ty, EINA_TRUE);
165 cells = &(TERMPTY_SCREEN(ty, 0, ty->cursor_state.cy)); 178 cells = &(TERMPTY_SCREEN(ty, 0, ty->cursor_state.cy));
166 } 179 }
167 if (ty->termstate.insert) 180 if (ty->termstate.insert)
168 { 181 {
169 for (j = ty->w - 1; j > ty->cursor_state.cx; j--) 182 for (j = max_right-1; j > ty->cursor_state.cx; j--)
170 termpty_cell_copy(ty, &(cells[j - 1]), &(cells[j]), 1); 183 termpty_cell_copy(ty, &(cells[j - 1]), &(cells[j]), 1);
171 } 184 }
172 185
@@ -194,7 +207,7 @@ termpty_text_append(Termpty *ty, const Eina_Unicode *codepoints, int len)
194 cells[ty->cursor_state.cx].att.strike = 1; 207 cells[ty->cursor_state.cx].att.strike = 1;
195 } 208 }
196 cells[ty->cursor_state.cx].att.dblwidth = _termpty_is_dblwidth_get(ty, g); 209 cells[ty->cursor_state.cx].att.dblwidth = _termpty_is_dblwidth_get(ty, g);
197 if (EINA_UNLIKELY((cells[ty->cursor_state.cx].att.dblwidth) && (ty->cursor_state.cx < (ty->w - 1)))) 210 if (EINA_UNLIKELY((cells[ty->cursor_state.cx].att.dblwidth) && (ty->cursor_state.cx < (max_right - 1))))
198 { 211 {
199 TERMPTY_FMTCLR(cells[ty->cursor_state.cx].att); 212 TERMPTY_FMTCLR(cells[ty->cursor_state.cx].att);
200 termpty_cell_codepoint_att_fill(ty, 0, cells[ty->cursor_state.cx].att, 213 termpty_cell_codepoint_att_fill(ty, 0, cells[ty->cursor_state.cx].att,
@@ -207,12 +220,12 @@ termpty_text_append(Termpty *ty, const Eina_Unicode *codepoints, int len)
207 ty->termstate.wrapnext = 0; 220 ty->termstate.wrapnext = 0;
208 if (EINA_UNLIKELY(cells[ty->cursor_state.cx].att.dblwidth)) 221 if (EINA_UNLIKELY(cells[ty->cursor_state.cx].att.dblwidth))
209 offset = 2; 222 offset = 2;
210 if (EINA_UNLIKELY(ty->cursor_state.cx >= (ty->w - offset))) 223 if (EINA_UNLIKELY(ty->cursor_state.cx >= (max_right - offset)))
211 ty->termstate.wrapnext = 1; 224 ty->termstate.wrapnext = 1;
212 else 225 else
213 { 226 {
214 ty->cursor_state.cx += offset; 227 ty->cursor_state.cx += offset;
215 TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w); 228 TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, max_right);
216 } 229 }
217 } 230 }
218 else 231 else
@@ -223,13 +236,13 @@ termpty_text_append(Termpty *ty, const Eina_Unicode *codepoints, int len)
223 if (EINA_UNLIKELY(cells[ty->cursor_state.cx].att.dblwidth)) 236 if (EINA_UNLIKELY(cells[ty->cursor_state.cx].att.dblwidth))
224 offset = 2; 237 offset = 2;
225 ty->cursor_state.cx += offset; 238 ty->cursor_state.cx += offset;
226 if (ty->cursor_state.cx > (ty->w - offset)) 239 if (ty->cursor_state.cx > (max_right - offset))
227 { 240 {
228 ty->cursor_state.cx = ty->w - offset; 241 ty->cursor_state.cx = max_right - offset;
229 TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w); 242 TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, max_right);
230 return; 243 return;
231 } 244 }
232 TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w); 245 TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, max_right);
233 } 246 }
234 } 247 }
235} 248}