[input] return error once we've emptied ibuf and hit stdineof

pull/2197/head
nick black 3 years ago
parent da6fc8420d
commit 0de21824cc
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC

@ -1992,6 +1992,11 @@ internal_get(inputctx* ictx, const struct timespec* ts, ncinput* ni){
}
pthread_mutex_lock(&ictx->ilock);
while(!ictx->ivalid){
if(ictx->stdineof){
pthread_mutex_unlock(&ictx->ilock);
logwarn("read eof on stdin\n");
return -1;
}
if(ts == NULL){
pthread_cond_wait(&ictx->icond, &ictx->ilock);
}else{

@ -1,38 +0,0 @@
#include <limits.h>
#include <notcurses/direct.h>
int main(void){
srand(time(NULL)); // gross
long guess, secret = rand();
struct ncdirect* n = ncdirect_core_init(NULL, stdout, NCDIRECT_OPTION_INHIBIT_CBREAK);
if(n == NULL){
return EXIT_FAILURE;
}
int r = 0;
do{
if(!(r |= (ncdirect_set_fg_default(n)))){
if(!(r |= (printf("Guess the long: ") < 0))){
if(!(r |= fflush(stdout))){
int rargs = scanf("%ld", &guess); // super shitty to the max
if(rargs != 1){
r = -1;
break;
}
int offoom = labs(__builtin_clzl(guess) - __builtin_clzl(secret));
if(guess > secret){
r |= ncdirect_set_fg_rgb8(n, 0x40, 0x80, offoom * 6);
r |= (printf("\tLOL jabronies guess %ld. Too high!\n", guess) < 0);
}else if(guess < secret){
r |= ncdirect_set_fg_rgb8(n, offoom * 6, 0x80, 0x40);
r |= (printf("\tSpineless worm! %ld? Too low!\n", guess) < 0);
}
}
}
}
}while(!r && guess != secret);
if(r || printf("You enjoy 20/20 vision into the minds of antimen!\n") < 0){
ncdirect_stop(n);
return EXIT_FAILURE;
}
return ncdirect_stop(n) ? EXIT_FAILURE : EXIT_SUCCESS;
}
Loading…
Cancel
Save