2 * Copyright (C) 2008 Diego Hernan Borghetti.
16 E_Screen
*e_screen_init(E_Term
*tr
)
22 sc
= (E_Screen
*)malloc(sizeof(E_Screen
));
29 sc
->vscr
= (E_ScreenLine
**)malloc(sizeof(E_ScreenLine
*) * tr
->nrow
);
30 sc
->pscr
= (E_ScreenLine
**)malloc(sizeof(E_ScreenLine
*) * tr
->nrow
);
31 if ((!sc
->vscr
) || (!sc
->pscr
)) {
42 for (i
= 0; i
< tr
->nrow
; i
++) {
43 ln
= (E_ScreenLine
*)malloc(sizeof(E_ScreenLine
)+tr
->ncol
);
49 ln
->fcol
= (char *)malloc(tr
->ncol
);
50 ln
->bcol
= (char *)malloc(tr
->ncol
);
52 for (e
= 0; e
< tr
->ncol
; e
++) {
53 ln
->fcol
[e
]= E_TR_WHITE
;
54 ln
->bcol
[e
]= E_TR_BLACK
;
58 ln
= (E_ScreenLine
*)malloc(sizeof(E_ScreenLine
)+tr
->ncol
);
65 ln
->fcol
= (char *)malloc(tr
->ncol
);
66 ln
->bcol
= (char *)malloc(tr
->ncol
);
67 for (e
= 0; e
< tr
->ncol
; e
++) {
68 ln
->fcol
[e
]= E_TR_WHITE
;
69 ln
->bcol
[e
]= E_TR_BLACK
;
76 void e_screen_free(E_Screen
*sc
)
81 for (i
= 0; i
< sc
->nrow
; i
++) {
83 free((void *)ln
->fcol
);
84 free((void *)ln
->bcol
);
88 free((void *)ln
->fcol
);
89 free((void *)ln
->bcol
);
93 free((void *)sc
->vscr
);
94 free((void *)sc
->pscr
);
98 void e_screen_putc(E_Screen
*sc
, int c
, char fcol
, char bcol
)
102 if (sc
->row
>= 0 && sc
->row
< sc
->nrow
) {
103 ln
= sc
->vscr
[sc
->row
];
104 ln
->text
[sc
->col
]= c
;
105 ln
->fcol
[sc
->col
]= fcol
;
106 ln
->bcol
[sc
->col
]= bcol
;
110 void e_screen_move(E_Screen
*sc
, int row
, int col
)
116 void e_screen_crow(E_Screen
*sc
, int row
, char crow
)
120 if (row
>= 0 && row
< sc
->nrow
) {
126 void e_screen_eeol(E_Screen
*sc
)
131 if (sc
->row
>= 0 && sc
->row
< sc
->nrow
) {
132 ln
= sc
->vscr
[sc
->row
];
133 for (i
= sc
->col
; i
< sc
->ncol
; i
++) {
135 ln
->fcol
[i
]= E_TR_WHITE
;
136 ln
->bcol
[i
]= E_TR_BLACK
;
141 void e_screen_eeop(E_Screen
*sc
)
146 if (sc
->row
>= 0 && sc
->row
< sc
->nrow
) {
147 for(e
= 0; e
< sc
->nrow
; e
++) {
149 for (i
= 0; i
< sc
->ncol
; i
++) {
151 ln
->fcol
[i
]= E_TR_WHITE
;
152 ln
->bcol
[i
]= E_TR_BLACK
;
158 void e_screen_swap(E_Term
*tr
, E_Screen
*sc
, int user_force
)
160 E_ScreenLine
*vln
, *pln
;
165 sy
= e_syntax_search(".c");
167 /* default color, white and black. */
168 e_term_fgcol(tr
, E_TR_WHITE
);
169 e_term_bgcol(tr
, E_TR_BLACK
);
171 for(e
= 0; e
< sc
->nrow
; e
++) {
176 /* Apply the color but skip current row. */
177 if (sy
&& vln
->crow
== 0)
178 e_syntax_apply(sy
, vln
, sc
->ncol
);
180 for (i
= 0; i
< sc
->ncol
; i
++) {
181 /* Check for color changes. */
182 if (vln
->fcol
[i
] != pln
->fcol
[i
] ||
183 vln
->bcol
[i
] != pln
->bcol
[i
]) {
184 pln
->fcol
[i
]= vln
->fcol
[i
];
185 pln
->bcol
[i
]= vln
->bcol
[i
];
189 if (force
|| vln
->text
[i
] != pln
->text
[i
]) {
190 e_term_fgcol(tr
, pln
->fcol
[i
]);
191 e_term_bgcol(tr
, pln
->bcol
[i
]);
193 e_term_putc(vln
->text
[i
]);
194 pln
->text
[i
]= vln
->text
[i
];
199 /* restore the original position of the cursor. */
200 e_term_move(sc
->row
, sc
->col
);