9 enter(char *ask, char *buf, int len, Mousectl *mc, Keyboardctl *kc, Screen *scr)
11 int done, down, tick, n, h, w, l, i;
12 Image *b, *save, *backcol, *bordcol;
20 backcol = allocimagemix(display, DPurpleblue, DWhite);
21 bordcol = allocimage(display, Rect(0,0,1,1), screen->chan, 1, DPurpleblue);
22 if(backcol == nil || bordcol == nil)
26 replclipr(screen, 0, screen->r);
30 while(nbrecv(kc->c, nil) == 1)
62 p = stringsize(font, " ");
67 p = stringsize(font, buf ? buf : "");
70 p.x += stringwidth(font, ask);
72 r = rectaddpt(insetrect(Rpt(ZP, p), -4), o);
77 if(r.min.x < screen->r.min.x)
78 p.x = screen->r.min.x - r.min.x;
79 if(r.min.y < screen->r.min.y)
80 p.y = screen->r.min.y - r.min.y;
83 if(r.max.x > screen->r.max.x)
84 p.x = r.max.x - screen->r.max.x;
85 if(r.max.y > screen->r.max.y)
86 p.y = r.max.y - screen->r.max.y;
92 b = allocwindow(scr, r, Refbackup, DWhite);
96 if(scr == nil && save == nil){
99 save = allocimage(display, r, b->chan, 0, DNofill);
104 draw(save, r, b, nil, r.min);
106 draw(b, r, backcol, nil, ZP);
107 border(b, r, 2, bordcol, ZP);
108 p = addpt(r.min, Pt(6, 6));
110 p = string(b, p, bordcol, ZP, font, ask);
115 p = stringn(b, p, display->black, ZP, font, buf, utfnlen(buf, tick));
116 draw(b, Rect(p.x-1, p.y, p.x+2, p.y+3), display->black, nil, ZP);
117 draw(b, Rect(p.x, p.y, p.x+1, p.y+h), display->black, nil, ZP);
118 draw(b, Rect(p.x-1, p.y+h-3, p.x+2, p.y+h), display->black, nil, ZP);
119 p = string(b, p, display->black, ZP, font, buf+tick);
121 flushimage(display, 1);
130 if(buf == nil || k == Keof || k == '\n'){
134 if(k == Knack || k == Kesc){
136 buf[n = tick = 0] = 0;
139 if(k == Ksoh || k == Khome){
143 if(k == Kenq || k == Kend){
149 tick += chartorune(&k, buf+tick);
153 for(i = 0; i < n; i += l){
154 l = chartorune(&k, buf+tick);
166 strchr(" !\"#$%&'()*+,-./:;<=>?@`[\\]^{|}~", buf[tick-1]))
175 for(i = 0; i < n; i += l){
176 l = chartorune(&k, buf+i);
178 memmove(buf+i, buf+i+l, n - (i+l));
186 if(k < 0x20 || k == Kdel || (k & 0xFF00) == KF || (k & 0xFF00) == Spec)
188 if((len-n) <= (l = runelen(k)))
190 memmove(buf+tick+l, buf+tick, n - tick);
191 runetochar(buf+tick, &k);
196 if(!ptinrect(m.xy, r)){
202 if(buf && m.xy.x >= (t.x - w)){
204 for(i = 0; i < n; i += l){
205 l = chartorune(&k, buf+i);
206 t.x += stringnwidth(font, buf+i, 1);
222 draw(b, save->r, save, nil, save->r.min);
228 replclipr(screen, 0, sc);
232 flushimage(display, 1);