summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2006-10-25 04:52:48 +0000
committerRich Felker <dalias@aerifal.cx>2006-10-25 04:52:48 +0000
commit734da46346f62d0af0feed2ffd74c47e06de7157 (patch)
tree2b55dfcb62ba3fbce2a65367dda5111a399b8485 /main.c
parent9b7a5f39380ca50f0efbb30689cd3ca97bac3920 (diff)
downloaduuterm-734da46346f62d0af0feed2ffd74c47e06de7157.tar.gz
major changes to input handling in preparation for pasting, which will
require support for large blocks of input: output which cannot be written to the tty (pty) is no longer discarded. instead, the display module is responsible for keeping the buffer alive until it has been entirely consumed. one simple (and smart) way to ensure this is to refuse to process events that could generate new input text as long as there is unwritten data. this works as long as there is an earlier layer of buffering (for fbcon, kernel; for x11, xlib). a direct-on-x-protocol display implementation will have to do its own buffer management. this architecture allows pasting to be performed direct from a buffer owned by the display module, which could reside in static or shared memory, or even as a memory-mapped file. it also facilitates reuse of the code in non-tty-connected settings.
Diffstat (limited to 'main.c')
-rw-r--r--main.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/main.c b/main.c
index e14c277..784f7f2 100644
--- a/main.c
+++ b/main.c
@@ -23,7 +23,7 @@ int main(int argc, char *argv[])
int tty, max;
int i, l;
unsigned char b[256];
- fd_set fds;
+ fd_set fds, wfds;
struct timeval tv;
void *buf;
@@ -59,11 +59,13 @@ int main(int argc, char *argv[])
for (;;) {
/* Setup fd_set containing fd's used by display and our tty */
FD_ZERO(&fds);
+ FD_ZERO(&wfds);
FD_SET(tty, &fds);
max = uudisp_fd_set(&d, tty, &fds);
+ if (d.inlen) FD_SET(tty, &wfds);
tv.tv_sec = 0;
tv.tv_usec = 250000;
- if (select(max, &fds, NULL, NULL, &tv) <= 0) {
+ if (select(max, &fds, &wfds, NULL, &tv) <= 0) {
d.blink++;
FD_ZERO(&fds);
}
@@ -78,6 +80,15 @@ int main(int argc, char *argv[])
}
}
+ /* Write input from previous event */
+ if (d.inlen) {
+ int l = write(tty, d.intext, d.inlen);
+ if (l < 0) l = 0;
+ d.intext += l;
+ d.inlen -= l;
+ d.blink = 1;
+ }
+
/* Look for events from the display */
uudisp_next_event(&d, &fds);
@@ -90,10 +101,6 @@ int main(int argc, char *argv[])
uutty_resize(tty, d.w, d.h);
}
}
- if (d.inlen) {
- write(tty, d.intext, d.inlen);
- d.blink = 1;
- }
/* If no more input is pending, refresh display */
FD_ZERO(&fds);