aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2021-04-09 22:47:17 +0200
committerMattias Andrée <maandree@kth.se>2021-04-09 22:47:17 +0200
commita9bc337202ac7614821958063c5cec51e16dd48c (patch)
tree6c42a4c344a853691e85df67feab575482818d39
parentAdd libterminput.7 (diff)
downloadlibterminput-a9bc337202ac7614821958063c5cec51e16dd48c.tar.gz
libterminput-a9bc337202ac7614821958063c5cec51e16dd48c.tar.bz2
libterminput-a9bc337202ac7614821958063c5cec51e16dd48c.tar.xz
Add libterminput_is_ready
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r--Makefile3
-rw-r--r--TODO1
-rw-r--r--libterminput.74
-rw-r--r--libterminput.c3
-rw-r--r--libterminput.h10
-rw-r--r--libterminput_is_ready.356
-rw-r--r--libterminput_read.31
7 files changed, 76 insertions, 2 deletions
diff --git a/Makefile b/Makefile
index 10796c5..763a966 100644
--- a/Makefile
+++ b/Makefile
@@ -58,7 +58,7 @@ install: libterminput.a libterminput.$(LIBEXT)
cp -- libterminput.$(LIBEXT) "$(DESTDIR)$(PREFIX)/lib/libterminput.$(LIBMINOREXT)"
ln -sf -- libterminput.$(LIBMINOREXT) "$(DESTDIR)$(PREFIX)/lib/libterminput.$(LIBMAJOREXT)"
ln -sf -- libterminput.$(LIBMAJOREXT) "$(DESTDIR)$(PREFIX)/lib/libterminput.$(LIBEXT)"
- cp -- libterminput_read.3 libterminput_set_flags.3 "$(DESTDIR)$(MANPREFIX)/man3"
+ cp -- libterminput_read.3 libterminput_set_flags.3 libterminput_is_ready.3 "$(DESTDIR)$(MANPREFIX)/man3"
ln -sf -- libterminput_set_flags.3 "$(DESTDIR)$(MANPREFIX)/man3/libterminput_clear_flags.3"
cp -- libterminput.7 "$(DESTDIR)$(MANPREFIX)/man7"
@@ -71,6 +71,7 @@ uninstall:
-rm -f -- "$(DESTDIR)$(MANPREFIX)/man3/libterminput_read.3"
-rm -f -- "$(DESTDIR)$(MANPREFIX)/man3/libterminput_set_flags.3"
-rm -f -- "$(DESTDIR)$(MANPREFIX)/man3/libterminput_clear_flags.3"
+ -rm -f -- "$(DESTDIR)$(MANPREFIX)/man3/libterminput_is_ready.3"
-rm -f -- "$(DESTDIR)$(MANPREFIX)/man7/libterminput.7"
clean:
diff --git a/TODO b/TODO
index 3c37d72..50b03d9 100644
--- a/TODO
+++ b/TODO
@@ -1,3 +1,2 @@
-Add libterminput_is_ready()
Add cursor position report support
Add test
diff --git a/libterminput.7 b/libterminput.7
index db4c751..d56a6d3 100644
--- a/libterminput.7
+++ b/libterminput.7
@@ -13,6 +13,9 @@ libterminput provides the following functions:
.BR libterminput_read (3)
Read and parse input from the terminal.
.TP
+.BR libterminput_is_ready (3)
+Check if there is read data buffered.
+.TP
.BR libterminput_set_flags (3)
Add input parsing flags.
.TP
@@ -20,5 +23,6 @@ Add input parsing flags.
Remove input parsing flags.
.SH SEE ALSO
+.BR libterminput_is_ready (3),
.BR libterminput_read (3),
.BR libterminput_set_flags (3)
diff --git a/libterminput.c b/libterminput.c
index 7ca36de..147e756 100644
--- a/libterminput.c
+++ b/libterminput.c
@@ -888,3 +888,6 @@ libterminput_clear_flags(struct libterminput_state *ctx, enum libterminput_flags
ctx->flags ^= flags;
return 0;
}
+
+
+extern inline int libterminput_is_ready(union libterminput_input *input, struct libterminput_state *ctx);
diff --git a/libterminput.h b/libterminput.h
index 45ac2a4..0182a54 100644
--- a/libterminput.h
+++ b/libterminput.h
@@ -183,6 +183,16 @@ struct libterminput_state {
*/
int libterminput_read(int fd, union libterminput_input *input, struct libterminput_state *ctx);
+inline int
+libterminput_is_ready(union libterminput_input *input, struct libterminput_state *ctx)
+{
+ if (!ctx->inited)
+ return 0;
+ if (input->type == LIBTERMINPUT_KEYPRESS && input->keypress.times > 1)
+ return 1;
+ return ctx->stored_head > ctx->stored_tail;
+}
+
int libterminput_set_flags(struct libterminput_state *ctx, enum libterminput_flags flags);
int libterminput_clear_flags(struct libterminput_state *ctx, enum libterminput_flags flags);
diff --git a/libterminput_is_ready.3 b/libterminput_is_ready.3
new file mode 100644
index 0000000..293d60e
--- /dev/null
+++ b/libterminput_is_ready.3
@@ -0,0 +1,56 @@
+.TH LIBTERMINPUT_IS_READY 3 LIBTERMINPUT
+.SH NAME
+libterminput_is_ready \- Check if there is read data buffered
+
+.SH SYNOPSIS
+.nf
+#include <libterminput.h>
+
+inline int libterminput_is_ready(union libterminput_input *input, struct libterminput_state *ctx);
+.fi
+.PP
+Link with
+.IR \-lterminput .
+
+.SH DESCRIPTION
+The
+.BR libterminput_is_ready ()
+function check if a call to the
+.BR libterminput_read (3)
+function will skip reading from the file
+descriptor passed to it because it already
+has read data buffered.
+
+.SH RETURN VALUE
+The
+.BR libterminput_is_ready ()
+function return 1 if the next call to the
+.BR libterminput_read (3)
+function will not from file descriptor
+passed to it, and 0 otherwise.
+
+.SH ERRORS
+The
+.BR libterminput_is_ready ()
+function cannot fail.
+
+.SH EXAMPLES
+None.
+
+.SH APPLICATION USAGE
+None.
+
+.SH RATIONALE
+None.
+
+.SH FUTURE DIRECTIONS
+None.
+
+.SH NOTES
+None.
+
+.SH BUGS
+None.
+
+.SH SEE ALSO
+.BR libterminput_read (3)
diff --git a/libterminput_read.3 b/libterminput_read.3
index 904342c..2cf401b 100644
--- a/libterminput_read.3
+++ b/libterminput_read.3
@@ -433,4 +433,5 @@ None.
None.
.SH SEE ALSO
+.BR libterminput_is_ready (3),
.BR libterminput_set_flags (3)