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)
42 p = stringsize(font, " ");
47 p = stringsize(font, buf ? buf : "");
50 p.x += stringwidth(font, ask);
52 r = rectaddpt(insetrect(Rpt(ZP, p), -4), o);
57 if(r.min.x < screen->r.min.x)
58 p.x = screen->r.min.x - r.min.x;
59 if(r.min.y < screen->r.min.y)
60 p.y = screen->r.min.y - r.min.y;
63 if(r.max.x > screen->r.max.x)
64 p.x = r.max.x - screen->r.max.x;
65 if(r.max.y > screen->r.max.y)
66 p.y = r.max.y - screen->r.max.y;
71 save = allocimage(display, r, b->chan, 0, DNofill);
76 draw(save, r, b, nil, r.min);
78 draw(b, r, backcol, nil, ZP);
79 border(b, r, 2, bordcol, ZP);
80 p = addpt(r.min, Pt(6, 6));
82 p = string(b, p, bordcol, ZP, font, ask);
87 p = stringn(b, p, display->black, ZP, font, buf, utfnlen(buf, tick));
88 draw(b, Rect(p.x-1, p.y, p.x+2, p.y+3), display->black, nil, ZP);
89 draw(b, Rect(p.x, p.y, p.x+1, p.y+h), display->black, nil, ZP);
90 draw(b, Rect(p.x-1, p.y+h-3, p.x+2, p.y+h), display->black, nil, ZP);
91 p = string(b, p, display->black, ZP, font, buf+tick);
93 flushimage(display, 1);
98 switch(eread(i, &ev)){
105 if(buf == nil || k == Keof || k == '\n'){
109 if(k == Knack || k == Kesc){
111 buf[n = tick = 0] = 0;
114 if(k == Ksoh || k == Khome){
118 if(k == Kenq || k == Kend){
124 tick += chartorune(&k, buf+tick);
128 for(i = 0; i < n; i += l){
129 l = chartorune(&k, buf+tick);
140 for(i = 0; i < n; i += l){
141 l = chartorune(&k, buf+i);
143 memmove(buf+i, buf+i+l, n - (i+l));
151 if(k < 0x20 || k == Kdel || (k & 0xFF00) == KF || (k & 0xFF00) == Spec)
153 if((len-n) <= (l = runelen(k)))
155 memmove(buf+tick+l, buf+tick, n - tick);
156 runetochar(buf+tick, &k);
162 if(!ptinrect(m->xy, r)){
168 if(buf && m->xy.x >= (t.x - w)){
170 for(i = 0; i < n; i += l){
171 l = chartorune(&k, buf+i);
172 t.x += stringnwidth(font, buf+i, 1);
184 draw(b, save->r, save, nil, save->r.min);
191 flushimage(display, 1);