mirror of
https://github.com/dankamongmen/notcurses.git
synced 2024-11-06 03:20:26 +00:00
keyplot: input loop #430
This commit is contained in:
parent
fc2dc68619
commit
f1f94deda8
@ -1,6 +1,13 @@
|
||||
#include <cstdlib>
|
||||
#include <ncpp/NotCurses.hh>
|
||||
|
||||
#define NANOSECS_IN_SEC 1000000000
|
||||
|
||||
static inline uint64_t
|
||||
timespec_to_ns(const struct timespec* t){
|
||||
return t->tv_sec * NANOSECS_IN_SEC + t->tv_nsec;
|
||||
}
|
||||
|
||||
int main(void){
|
||||
if(setlocale(LC_ALL, "") == nullptr){
|
||||
return EXIT_FAILURE;
|
||||
@ -28,10 +35,25 @@ int main(void){
|
||||
if(!nc.render()){
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
struct timespec start;
|
||||
if(clock_gettime(CLOCK_MONOTONIC, &start)){
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
while(errno = 0, (r = nc.getc(true, &ni)) != (char32_t)-1){
|
||||
if(r == 0){ // interrupted by signal
|
||||
continue;
|
||||
}
|
||||
struct timespec now;
|
||||
if(clock_gettime(CLOCK_MONOTONIC, &now)){
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
const uint64_t sec = (timespec_to_ns(&now) - timespec_to_ns(&start)) / NANOSECS_IN_SEC;
|
||||
if(ncplot_add_sample(plot, sec, 1)){
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if(!nc.render()){
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
ncplot_destroy(plot);
|
||||
return EXIT_SUCCESS;
|
||||
|
@ -52,7 +52,14 @@ ncplane* ncplot_plane(ncplot* n){
|
||||
|
||||
static inline bool
|
||||
invalid_y(ncplot* n, int64_t y){
|
||||
if(y > n->maxy || y < n->miny){
|
||||
if(n->detectdomain){
|
||||
if(y > n->maxy){
|
||||
n->maxy = y;
|
||||
}
|
||||
if(y < n->miny){
|
||||
n->miny = y;
|
||||
}
|
||||
}else if(y > n->maxy || y < n->miny){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
Loading…
Reference in New Issue
Block a user