2 * Copyright (C) 2008 Diego Hernan Borghetti.
17 int e_update_get_tab(E_Eco
*ec
, int col
)
21 tab
= 8 + ec
->view
->col
;
27 int e_update_line(E_Eco
*ec
, E_Line
*ln
, int row
)
29 int i
, col
, tab
, invert
;
32 if (ec
->view
->b
->line
== ln
) {
33 /* Mark the current line in the screen. */
34 e_screen_crow(ec
->sc
, row
, 1);
36 i
= ec
->view
->b
->dot_pad
;
39 /* clear the flag if this is not the current line. */
40 e_screen_crow(ec
->sc
, row
, 0);
54 for (col
= ec
->view
->col
; col
< ec
->view
->rcol
&& i
< ln
->used
; i
++, col
++) {
55 if (ln
->text
[i
] == '\t') {
56 tab
= e_update_get_tab(ec
, col
);
58 e_screen_move(ec
->sc
, row
, col
);
59 e_screen_putc(ec
->sc
, ' ', fgcol
, bgcol
);
65 e_screen_move(ec
->sc
, row
, col
);
66 if (ln
->text
[i
] >= 0x20 && ln
->text
[i
] < 0x7f)
67 e_screen_putc(ec
->sc
, ln
->text
[i
], fgcol
, bgcol
);
69 e_screen_putc(ec
->sc
, ' ', fgcol
, bgcol
);
73 /* clean the rest of the line. */
74 if (col
< ec
->view
->rcol
) {
75 e_screen_move(ec
->sc
, row
, col
);
76 e_screen_eeol(ec
->sc
);
81 int __get_real_col(E_Eco
*ec
, E_Line
*ln
, int dot
)
85 for (i
= dot
, col
= ec
->view
->col
; i
< ec
->view
->b
->dot
; i
++) {
86 if (ec
->view
->b
->line
->text
[i
] == '\t')
87 col
= e_update_get_tab(ec
, col
);
94 void __reframe(E_Eco
*ec
)
97 int row
, col
, found
, i
;
99 /* check if we need pad the dot. */
100 col
= __get_real_col(ec
, ec
->view
->b
->line
, 0);
101 ec
->view
->b
->dot_pad
= 0;
103 while (col
> ec
->view
->rcol
) {
104 /* ok we need pad this, but go one-by-one so the
105 * left/right keys work fine.
107 ec
->view
->b
->dot_pad
++;
108 col
= __get_real_col(ec
, ec
->view
->b
->line
, ec
->view
->b
->dot_pad
);
111 p
= ec
->view
->b
->first
;
115 if (p
== ec
->view
->b
->line
) {
124 e_debug_printf("Check if need reframe\n");
126 * This can happen, the current line is before
127 * the first line and from the first to the end
128 * is < nrow, so need be sure.
130 if ((row
< ec
->view
->rrow
) && (found
))
133 /* We have 3 case here.
134 * 1) The current line is out of the screen because a "up"
135 * 2) The current line is out of the screen because a "down"
136 * 3) A scroll up/down
138 if (ec
->view
->b
->flag
& BUFFER_UP
) {
139 /* in this case, the prev line of the current
140 * line is where we need to go.
142 if (ec
->view
->b
->first
->prev
)
143 ec
->view
->b
->first
= ec
->view
->b
->first
->prev
;
144 e_debug_printf("Reframe up buffer\n");
145 BUFFER_UNSET(ec
->view
->b
, BUFFER_UP
);
147 else if (ec
->view
->b
->flag
& BUFFER_DOWN
) {
148 /* in this case the next line of the last line
149 * is our target, so just move one line ;)
151 if (ec
->view
->b
->first
->next
)
152 ec
->view
->b
->first
= ec
->view
->b
->first
->next
;
153 e_debug_printf("Reframe down buffer\n");
154 BUFFER_UNSET(ec
->view
->b
, BUFFER_DOWN
);
157 /* Ok, we are here because page up/down, the normal
158 * scroll with 3+ lines.
160 ec
->view
->b
->first
= ec
->view
->b
->line
;
161 for (i
= 0; i
< 3; i
++) {
162 if (!ec
->view
->b
->first
->prev
)
164 ec
->view
->b
->first
= ec
->view
->b
->first
->prev
;
166 e_debug_printf("Reframe buffer\n");
170 void e_update_cursor(E_Eco
*ec
)
176 * This function sync the physical and virtual
177 * cursor position, assume that the buffer don't
180 * First, match the current row.
183 p
= ec
->view
->b
->first
;
185 if (p
== ec
->view
->b
->line
)
192 /* second check if the line is "extend" or not. */
193 col
= __get_real_col(ec
, ec
->view
->b
->line
, 0);
195 if (col
> ec
->view
->rcol
)
196 col
= __get_real_col(ec
, ec
->view
->b
->line
, ec
->view
->b
->dot_pad
);
198 e_screen_move(ec
->sc
, row
, col
);
199 e_term_move(row
, col
);
202 void e_update(E_Eco
*ec
)
209 fgcol
= e_config_get_char("Screen", "empty_char_fg");
210 bgcol
= e_config_get_char("Screen", "empty_char_bg");
216 /* first save the active view. */
219 /* now update all the view that are show and need redraw. */
222 if ((vp
->flag
& VIEW_REDRAW
) && (vp
->flag
& VIEW_SHOW
)) {
223 /* make the active, just for draw. */
226 /* check for scroll. */
229 ln
= ec
->view
->b
->first
;
231 while (ln
&& (row
< ec
->view
->rrow
)) {
232 row
= e_update_line(ec
, ln
, row
);
237 /* fill the unused lines. */
238 while (row
< ec
->view
->rrow
) {
239 e_screen_move(ec
->sc
, row
, ec
->view
->col
);
240 e_screen_putc(ec
->sc
, '~', E_TR_BLUE
, E_TR_BLACK
);
241 e_screen_move(ec
->sc
, row
, ec
->view
->col
+1);
242 e_screen_eeol(ec
->sc
);
246 /* always remove the scroll flags or
247 * we can get bad result in the next reframe.
249 if (vp
->b
->flag
& BUFFER_UP
) {
250 BUFFER_UNSET(vp
->b
, BUFFER_UP
);
252 if (vp
->b
->flag
& BUFFER_DOWN
) {
253 BUFFER_UNSET(vp
->b
, BUFFER_DOWN
);
255 vp
->flag
&= ~VIEW_REDRAW
;
260 /* restore the active view. */