8 eenter(char *ask, char *buf, int len, Mouse *m)
10 int done, down, tick, n, h, w, l, i;
11 Image *b, *save, *backcol, *bordcol;
18 backcol = allocimagemix(display, DPurpleblue, DWhite);
19 bordcol = allocimage(display, Rect(0,0,1,1), screen->chan, 1, DPurpleblue);
20 if(backcol == nil || bordcol == nil)
41 p = stringsize(font, " ");
47 replclipr(b, 0, b->r);
50 p = stringsize(font, buf ? buf : "");
53 p.x += stringwidth(font, ask);
55 r = rectaddpt(insetrect(Rpt(ZP, p), -4), o);
60 if(r.min.x < screen->r.min.x)
61 p.x = screen->r.min.x - r.min.x;
62 if(r.min.y < screen->r.min.y)
63 p.y = screen->r.min.y - r.min.y;
66 if(r.max.x > screen->r.max.x)
67 p.x = r.max.x - screen->r.max.x;
68 if(r.max.y > screen->r.max.y)
69 p.y = r.max.y - screen->r.max.y;
74 save = allocimage(display, r, b->chan, 0, DNofill);
79 draw(save, r, b, nil, r.min);
81 draw(b, r, backcol, nil, ZP);
82 border(b, r, 2, bordcol, ZP);
83 p = addpt(r.min, Pt(6, 6));
85 p = string(b, p, bordcol, ZP, font, ask);
90 p = stringn(b, p, display->black, ZP, font, buf, utfnlen(buf, tick));
91 draw(b, Rect(p.x-1, p.y, p.x+2, p.y+3), display->black, nil, ZP);
92 draw(b, Rect(p.x, p.y, p.x+1, p.y+h), display->black, nil, ZP);
93 draw(b, Rect(p.x-1, p.y+h-3, p.x+2, p.y+h), display->black, nil, ZP);
94 p = string(b, p, display->black, ZP, font, buf+tick);
96 flushimage(display, 1);
106 /* screen might have been resized */
107 if(b != screen || !eqrect(screen->clipr, sc)){
113 replclipr(b, 0, b->r);
122 if(buf == nil || k == Keof || k == '\n'){
126 if(k == Knack || k == Kesc){
128 buf[n = tick = 0] = 0;
131 if(k == Ksoh || k == Khome){
135 if(k == Kenq || k == Kend){
141 tick += chartorune(&k, buf+tick);
145 for(i = 0; i < n; i += l){
146 l = chartorune(&k, buf+tick);
158 strchr(" !\"#$%&'()*+,-./:;<=>?@`[\\]^{|}~", buf[tick-1]))
167 for(i = 0; i < n; i += l){
168 l = chartorune(&k, buf+i);
170 memmove(buf+i, buf+i+l, n - (i+l));
178 if(k < 0x20 || k == Kdel || (k & 0xFF00) == KF || (k & 0xFF00) == Spec)
180 if((len-n) <= (l = runelen(k)))
182 memmove(buf+tick+l, buf+tick, n - tick);
183 runetochar(buf+tick, &k);
189 if(!ptinrect(m->xy, r)){
195 if(buf && m->xy.x >= (t.x - w)){
197 for(i = 0; i < n; i += l){
198 l = chartorune(&k, buf+i);
199 t.x += stringnwidth(font, buf+i, 1);
211 draw(b, save->r, save, nil, save->r.min);
221 flushimage(display, 1);