From e9180cf83ade29192d8407337f614e5a024017a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Fri, 17 Oct 2014 15:43:48 +0200 Subject: Make editor usable as a filter: echo foo | vis - | cat The terminal output is by default redirected to stderr, making stdout available for communications purposes. If a file is "opened" from stdin (i.e. vis is given '-' as argument) and a subsequent write without a filename is performed as in ":wq" the output is written to stdout. --- text.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'text.h') diff --git a/text.h b/text.h index 34e350d..44c9f69 100644 --- a/text.h +++ b/text.h @@ -2,7 +2,7 @@ #define TEXT_H #include -#include +#include #define EPOS ((size_t)-1) /* invalid position */ @@ -34,6 +34,9 @@ typedef struct { Text *text_load(const char *file); Text *text_load_fd(int fd); +/* return the fd from which this text was loaded or -1 if it was + * loaded from a filename */ +int text_fd_get(Text*); /* the filename from which this text was loaded or first saved to */ const char *text_filename_get(Text*); /* associate a filename with the yet unnamed buffer */ @@ -82,6 +85,7 @@ bool text_modified(Text*); /* test whether the underlying file uses UNIX style \n or Windows style \r\n newlines */ bool text_newlines_crnl(Text*); int text_save(Text*, const char *file); +ssize_t text_write(Text*, int fd); void text_free(Text*); typedef struct Regex Regex; -- cgit v1.2.3