Screen don't get update after search & replace.
[eco.git] / status.c
blob6b94333dee6c7cca4e6ad6f85871ef3744bb1bd1
1 /*
2 * Copyright (C) 2008 Diego Hernan Borghetti.
3 * Eco
4 */
6 #include <stdio.h>
7 #include <string.h>
8 #include <stdarg.h>
10 #include "term.h"
11 #include "screen.h"
12 #include "buffer.h"
13 #include "view.h"
14 #include "eco.h"
15 #include "status.h"
18 void e_status_putc(E_Eco *ec, int c)
20 if (ec->view->stcol > ec->view->rcol)
21 return;
23 e_term_move(ec->view->strow, ec->view->stcol);
24 if (c == '*') {
25 e_term_fgcol(ec->tr, E_TR_RED);
26 e_term_bgcol(ec->tr, E_TR_BLACK);
28 else {
29 e_term_fgcol(ec->tr, ec->view->stfg);
30 e_term_bgcol(ec->tr, ec->view->stbg);
33 e_term_putc(c);
34 ec->view->stcol++;
37 void e_status_putc_string(E_Eco *ec, char *s)
39 int i;
41 for (i= 0; i < strlen (s); i++)
42 e_status_putc(ec, s[i]);
45 void e_status_putc_msg(E_Eco *ec)
47 int i;
49 if (!ec->view->stmsg)
50 return;
52 for (i= 0; i < ec->view->stused; i++)
53 e_status_putc(ec, ec->view->stbuf[i]);
56 void e_status_set_msg(E_Eco *ec, char *fmt, ...)
58 va_list ap;
60 va_start(ap, fmt);
61 vsnprintf(ec->view->stbuf, 79, fmt, ap);
62 ec->view->stused= strlen(ec->view->stbuf);
63 va_end(ap);
65 ec->view->stused++;
66 ec->view->stmsg= 1;
67 return;
70 char *e_status_get_msg(E_Eco *ec, char *prompt)
72 int i, c, val;
74 ec->view->stcol= ec->view->col;
75 ec->view->strow= ec->view->rrow;
77 /* need clean the status line. */
78 /* this work in all terms ? */
79 e_term_move(ec->view->strow, ec->view->stcol);
80 e_term_eeol();
81 i= 0;
82 val= 0;
84 if (prompt)
85 e_status_putc_string(ec, prompt);
86 else
87 e_status_putc(ec, ':');
89 for (;;) {
90 c= e_term_getc();
91 if (c == '\r') {
92 ec->view->stbuf[i]= '\0';
93 if (i)
94 val= 1;
95 break;
97 else if (c == '\b' && i) {
98 ec->view->stcol--;
99 e_status_putc(ec, ' ');
100 ec->view->stcol--;
101 e_term_move(ec->view->strow, ec->view->stcol);
102 ec->view->stbuf[i]= '\0';
103 i--;
104 e_term_flush();
106 else if (c > 0x00 && c < 0x20) {
107 c= c + '@';
108 if (c == 'G')
109 return(NULL);
111 else if ((c >= 0x20) && (c < 0x7f)) {
112 ec->view->stbuf[i]= c;
113 i++;
114 e_status_putc(ec, c);
115 e_term_flush();
119 if (val)
120 return(ec->view->stbuf);
121 return(NULL);
124 void e_status_draw(E_Eco *ec)
126 char buf[24];
127 int ocol, orow;
128 int rcol, i;
131 * The status draw is always call after e_update, so
132 * the physical and virtual cursor are already sync,
133 * we need save the current position to restore
134 * in the end.
136 orow= ec->tr->row;
137 ocol= ec->tr->col;
139 ec->view->stcol= ec->view->col;
140 ec->view->strow= ec->view->rrow;
142 if (ec->view->b->flag & BUFFER_FLUSH)
143 e_status_putc(ec, '*');
145 e_status_putc(ec, '(');
146 e_status_putc_string(ec, ec->view->b->name);
148 for (i= 0, rcol= 0; i < ec->view->b->dot; i++) {
149 if (ec->view->b->line->text[i] == '\t')
150 rcol+= 7;
151 rcol++;
154 sprintf(buf, ") L(%d/%d) C(%d/%d) ", ec->view->b->nl, ec->view->b->nlines,
155 rcol+1, ec->view->b->line->used+1);
156 e_status_putc_string(ec, buf);
158 /* put the percent of the file. */
159 if (ec->view->b->line == ec->view->b->lines)
160 e_status_putc_string(ec, "Top ");
161 else if (!ec->view->b->line->next)
162 e_status_putc_string(ec, "Bottom ");
163 else {
164 int ratio= (100L * ec->view->b->nl)/ec->view->b->nlines;
166 if (ratio > 99)
167 ratio= 99;
169 sprintf(buf, "%2d%% ", ratio);
170 e_status_putc_string(ec, buf);
173 e_status_putc_msg(ec);
175 while (ec->view->stcol < ec->view->rcol)
176 e_status_putc(ec, ' ');
178 e_term_move(orow, ocol);
179 e_term_flush();