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
)
32 if (ec
->view
->b
->line
== ln
) {
33 fgcol
= e_config_get_int("Screen", "current_line_foreground");
34 bgcol
= e_config_get_int("Screen", "current_line_background");
40 e_screen_color(ec
->sc
, row
, fgcol
, bgcol
);
41 i
= ec
->view
->b
->dot_pad
;
44 e_screen_color(ec
->sc
, row
, E_TR_WHITE
, E_TR_BLACK
);
48 for (col
= ec
->view
->col
; col
< ec
->view
->rcol
&& i
< ln
->used
; i
++, col
++) {
49 if (ln
->text
[i
] == '\t') {
50 tab
= e_update_get_tab(ec
, col
);
52 e_screen_move(ec
->sc
, row
, col
);
53 e_screen_putc(ec
->sc
, ' ');
59 e_screen_move(ec
->sc
, row
, col
);
60 if (ln
->text
[i
] >= 0x20 && ln
->text
[i
] < 0x7f)
61 e_screen_putc(ec
->sc
, ln
->text
[i
]);
63 e_screen_putc(ec
->sc
, ' ');
67 /* clean the rest of the line. */
68 if (col
< ec
->view
->rcol
) {
69 e_screen_move(ec
->sc
, row
, col
);
70 e_screen_eeol(ec
->sc
);
75 int __get_real_col(E_Eco
*ec
, E_Line
*ln
, int dot
)
79 for (i
= dot
, col
= ec
->view
->col
; i
< ec
->view
->b
->dot
; i
++) {
80 if (ec
->view
->b
->line
->text
[i
] == '\t')
81 col
= e_update_get_tab(ec
, col
);
88 void __reframe(E_Eco
*ec
)
91 int row
, col
, found
, i
;
93 /* check if we need pad the dot. */
94 col
= __get_real_col(ec
, ec
->view
->b
->line
, 0);
95 ec
->view
->b
->dot_pad
= 0;
97 while (col
> ec
->view
->rcol
) {
98 /* ok we need pad this, but go one-by-one so the
99 * left/right keys work fine.
101 ec
->view
->b
->dot_pad
++;
102 col
= __get_real_col(ec
, ec
->view
->b
->line
, ec
->view
->b
->dot_pad
);
105 p
= ec
->view
->b
->first
;
109 if (p
== ec
->view
->b
->line
) {
118 e_debug_printf("Check if need reframe\n");
120 * This can happen, the current line is before
121 * the first line and from the first to the end
122 * is < nrow, so need be sure.
124 if ((row
< ec
->view
->rrow
) && (found
))
128 * The first line of the buffer is out of the screen,
130 * The easy why is just make the current line, the first
131 * line of the buffer, so we have a complet scroll, but
132 * we can define some number here, so the user can
133 * set the number of line to scroll.
135 ec
->view
->b
->first
= ec
->view
->b
->line
;
136 for (i
= 0; i
< 3; i
++) {
137 if (!ec
->view
->b
->first
->prev
)
139 ec
->view
->b
->first
= ec
->view
->b
->first
->prev
;
141 e_debug_printf("Reframe buffer\n");
144 void e_update_cursor(E_Eco
*ec
)
150 * This function sync the physical and virtual
151 * cursor position, assume that the buffer don't
154 * First, match the current row.
157 p
= ec
->view
->b
->first
;
159 if (p
== ec
->view
->b
->line
)
166 /* second check if the line is "extend" or not. */
167 col
= __get_real_col(ec
, ec
->view
->b
->line
, 0);
169 if (col
> ec
->view
->rcol
)
170 col
= __get_real_col(ec
, ec
->view
->b
->line
, ec
->view
->b
->dot_pad
);
172 e_screen_move(ec
->sc
, row
, col
);
173 e_term_move(row
, col
);
176 void e_update(E_Eco
*ec
)
182 /* first save the active view. */
185 /* now update all the view that are show and need redraw. */
188 if ((vp
->flag
& VIEW_REDRAW
) && (vp
->flag
& VIEW_SHOW
)) {
189 /* make the active, just for draw. */
192 /* check for scroll. */
195 ln
= ec
->view
->b
->first
;
197 while (ln
&& (row
< ec
->view
->rrow
)) {
198 row
= e_update_line(ec
, ln
, row
);
203 /* fill the unused lines. */
204 while (row
< ec
->view
->rrow
) {
205 e_screen_move(ec
->sc
, row
, ec
->view
->col
);
206 e_screen_putc(ec
->sc
, '~');
207 e_screen_move(ec
->sc
, row
, ec
->view
->col
+1);
208 e_screen_eeol(ec
->sc
);
212 vp
->flag
&= ~VIEW_REDRAW
;
217 /* restore the active view. */