+0.50 -> 0.51
+ - added newtFormSetTimer() (and test case, and python)
+
0.40 -> 0.50
- added CheckboxTree widget
- vastly improved python bindings
#include <stdarg.h>
#include <stdlib.h>
#include <sys/select.h>
+#include <sys/time.h>
#ifdef USE_GPM
#include <ctype.h>
int numFds;
struct fdInfo * fds;
int maxFd;
+ int timer; /* in milliseconds */
+ struct timeval lastTimeout;
};
static void gotoComponent(struct form * form, int newComp);
gotoComponent(form, new);
}
+void newtFormSetTimer(newtComponent co, int millisecs) {
+ struct form * form = co->data;
+
+ form->timer = millisecs;
+}
+
void newtFormSetHeight(newtComponent co, int height) {
struct form * form = co->data;
int key, i, max;
int done = 0;
fd_set readSet, writeSet;
+ struct timeval nextTimeout, now, timeout;
#ifdef USE_GPM
int x, y;
Gpm_Connect conn;
} else
gotoComponent(form, form->currComp);
+ /* Calculate when we next need to return with a timeout */
+ if (form->timer) {
+ if (!form->lastTimeout.tv_sec && !form->lastTimeout.tv_usec)
+ gettimeofday(&form->lastTimeout, NULL);
+
+ nextTimeout.tv_sec = form->lastTimeout.tv_sec + (form->timer / 1000);
+ nextTimeout.tv_usec = form->lastTimeout.tv_usec +
+ (form->timer % 1000) * 1000;
+ }
+
while (!done) {
newtRefresh();
FD_SET(form->fds[i].fd, &writeSet);
}
- i = select(max + 1, &readSet, &writeSet, NULL, NULL);
+ if (form->timer) {
+ gettimeofday(&now, 0);
+
+ if (now.tv_sec > nextTimeout.tv_sec) {
+ timeout.tv_sec = timeout.tv_usec = 0;
+ } else if (now.tv_sec == nextTimeout.tv_sec) {
+ timeout.tv_sec = 0;
+ if (now.tv_usec > nextTimeout.tv_usec)
+ timeout.tv_usec = 0;
+ else
+ timeout.tv_usec = nextTimeout.tv_usec - now.tv_usec;
+ } else if (now.tv_sec < nextTimeout.tv_sec) {
+ timeout.tv_sec = nextTimeout.tv_sec - now.tv_sec;
+ if (now.tv_usec > nextTimeout.tv_usec)
+ timeout.tv_sec--,
+ timeout.tv_usec = nextTimeout.tv_usec + 1000000 -
+ now.tv_usec;
+ else
+ timeout.tv_usec = nextTimeout.tv_usec - now.tv_usec;
+ }
+ } else {
+ timeout.tv_sec = timeout.tv_usec = 0;
+ }
+
+ i = select(max + 1, &readSet, &writeSet, NULL,
+ form->timer ? &timeout : NULL);
if (i < 0) continue; /* ?? What should we do here? */
+ if (i == 0) {
+ done = 1;
+ es->reason = NEWT_EXIT_TIMEOUT;
+ gettimeofday(&form->lastTimeout, NULL);
+ } else
#ifdef USE_GPM
if (gpm_fd > 0 && FD_ISSET(gpm_fd, &readSet)) {
Gpm_GetEvent(&event);
int * actualWidth, int * actualHeight);
struct newtExitStruct {
- enum { NEWT_EXIT_HOTKEY, NEWT_EXIT_COMPONENT, NEWT_EXIT_FDREADY } reason;
+ enum { NEWT_EXIT_HOTKEY, NEWT_EXIT_COMPONENT, NEWT_EXIT_FDREADY,
+ NEWT_EXIT_TIMEOUT } reason;
union {
int key;
newtComponent co;
} ;
newtComponent newtForm(newtComponent vertBar, const char * help, int flags);
+void newtFormSetTimer(newtComponent form, int millisecs);
void newtFormWatchFd(newtComponent form, int fd, int fdFlags);
void newtFormSetSize(newtComponent co);
newtComponent newtFormGetCurrent(newtComponent co);
Summary: A development library for text mode user interfaces.
Name: newt
-%define version 0.50
+%define version 0.50.1
Version: %{version}
Release: 14
Copyright: LGPL
int main(void) {
newtComponent b1, b2, r1, r2, r3, e2, e3, l1, l2, l3, scale;
- newtComponent lb, t, rsf, answer;
+ newtComponent lb, t, rsf, answer, timeLabel;
newtComponent cs[10];
newtComponent f, chklist, e1;
struct callbackInfo cbis[3];
void ** selectedList;
int i, numsel;
char buf[20];
+ const char * spinner = "-\\|/\\|/";
+ const char * spinState;
+ struct newtExitStruct es;
newtInit();
newtCls();
newtListboxInsertEntry(lb, "Eleventh", (void *) 11, (void *) 10);
newtListboxDeleteEntry(lb, (void *) 11);
+ spinState = spinner;
+ timeLabel = newtLabel(45, 8, "Spinner: -");
+
t = newtTextbox(45, 10, 17, 5, NEWT_FLAG_WRAP);
newtTextboxSetText(t, "This is some text does it look okay?\nThis should be alone.\nThis shouldn't be printed");
- newtFormAddComponents(f, lb, t, NULL);
+ newtFormAddComponents(f, lb, timeLabel, t, NULL);
newtRefresh();
+ newtFormSetTimer(f, 200);
do {
- answer = newtRunForm(f);
+ newtFormRun(f, &es);
- if (answer == b2) {
+ if (es.reason == NEWT_EXIT_COMPONENT && es.u.co == b2) {
newtScaleSet(scale, atoi(scaleVal));
newtRefresh();
answer = NULL;
+ } else if (es.reason == NEWT_EXIT_TIMEOUT) {
+ spinState++;
+ if (!*spinState) spinState = spinner;
+ sprintf(buf, "Spinner: %c", *spinState);
+ newtLabelSetText(timeLabel, buf);
}
- } while (!answer);
+ } while (es.reason != NEWT_EXIT_COMPONENT);
scaleVal = strdup(scaleVal);
enr2 = strdup(enr2);