ref: f94021cad309874252753f9ac7b49b9efe9b04be
dir: /enter.c/
#include <u.h> #include <libc.h> #include <thread.h> #include <draw.h> #include <mouse.h> #include <keyboard.h> enum { Emouse, Eresize, Ekeyboard, }; void threadmain(int argc, char **argv) { Mouse m; Rune k; Mousectl *mctl; Keyboardctl *kctl; char buf[512]; USED(argc, argv); Alt a[] = { { nil, &m, CHANRCV }, { nil, nil, CHANRCV }, { nil, &k, CHANRCV }, { nil, nil, CHANEND }, }; if (initdraw(nil, nil, "enter test") < 0) sysfatal("initdraw: %r"); mctl = initmouse(nil, screen); if (!mctl) sysfatal("initmouse: %r"); kctl = initkeyboard(nil); if (!kctl) sysfatal("initkeyboard: %r"); a[Emouse].c = mctl->c; a[Eresize].c = mctl->resizec; a[Ekeyboard].c = kctl->c; for (;;) { switch (alt(a)) { case Emouse: if (m.buttons == 0) break; snprint(buf, sizeof(buf), "hello world"); if (enter("Ask:", buf, sizeof(buf), mctl, kctl, nil) > 0) fprint(2, "entered: %s\n", buf); break; case Eresize: if (getwindow(display, Refnone) < 0) sysfatal("cannot reattach: %r"); draw(screen, screen->r, display->white, nil, ZP); break; case Ekeyboard: if (k == Kdel || k == 'q') threadexitsall(nil); break; } } }