summaryrefslogtreecommitdiffstats
path: root/linenoise/linenoise.h
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2015-09-06 13:03:18 -0700
committerKaz Kylheku <kaz@kylheku.com>2015-09-06 13:03:18 -0700
commit7ffe8d302ab56ffe96023daf015a477934b7f17b (patch)
tree2a083344ce79ed4564361848e6d28b3dd36f88b4 /linenoise/linenoise.h
parent52d027ad3df5905371519ba07ec9d2fe6150c21c (diff)
downloadtxr-7ffe8d302ab56ffe96023daf015a477934b7f17b.tar.gz
txr-7ffe8d302ab56ffe96023daf015a477934b7f17b.tar.bz2
txr-7ffe8d302ab56ffe96023daf015a477934b7f17b.zip
linenoise: error code distinguishes interrupt from eof.
In this commit, we introduce a persistent error variable stored in the lino_t structure, and functions to access it. * linenoise/linenoise.c (struct lino_state): New member, error. (enable_raw_mode): Don't set errno to ENOTTY; set linenoise error to lino_notty. (complete_line, edit, go_raw, linenoise, lino_hist_save, lino_hist_load): Set linenoise error before returning -1. (lino_get_error, lino_set_error): New functions. * linenoise/linenoise.h (enum lino_error, lino_error_t): New enum. (lino_get_error, lino_set_error): Declared.
Diffstat (limited to 'linenoise/linenoise.h')
-rw-r--r--linenoise/linenoise.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/linenoise/linenoise.h b/linenoise/linenoise.h
index acf9ffe2..0822a59b 100644
--- a/linenoise/linenoise.h
+++ b/linenoise/linenoise.h
@@ -36,6 +36,15 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+typedef enum lino_error {
+ lino_no_error, /* No error has occurred. */
+ lino_error, /* Unspecified error */
+ lino_eof, /* Line input terminated by Ctrl-D or EOF. */
+ lino_ioerr, /* Line input terminated by I/O error. */
+ lino_notty, /* Input is not a terminal. */
+ lino_intr /* Line innput terminated by Ctrl-C or interrupt */
+} lino_error_t;
+
typedef struct lino_state lino_t;
typedef struct lino_completions {
@@ -51,6 +60,8 @@ lino_t *lino_make(int ifd, int ofd);
void lino_free(lino_t *);
char *linenoise(lino_t *, const char *prompt);
+lino_error_t lino_get_error(lino_t *);
+lino_error_t lino_set_error(lino_t *, lino_error_t); /* returns old */
int lino_hist_add(lino_t *, const char *line);
int lino_hist_set_max_len(lino_t *, int len);
int lino_hist_save(lino_t *, const char *filename);