1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-12-25 04:24:48 +03:00

Add support for non-scrolling fifo buffers

This commit is contained in:
Maxime Coste 2014-05-02 18:58:04 +01:00
parent 26dd21706e
commit e83123de1f
5 changed files with 25 additions and 11 deletions

View File

@ -12,7 +12,7 @@ def -shell-params -file-completion \
fi fi
echo "eval -try-client '$kak_opt_toolsclient' %{ echo "eval -try-client '$kak_opt_toolsclient' %{
edit! -fifo ${output} *grep* edit! -fifo ${output} -scroll *grep*
set buffer filetype grep set buffer filetype grep
hook buffer BufClose .* %{ nop %sh{ rm -r $(dirname ${output}) } } hook buffer BufClose .* %{ nop %sh{ rm -r $(dirname ${output}) } }
}" }"

View File

@ -7,7 +7,7 @@ def -shell-params make %{ %sh{
( eval ${kak_opt_makecmd} "$@" > ${output} 2>&1 ) > /dev/null 2>&1 < /dev/null & ( eval ${kak_opt_makecmd} "$@" > ${output} 2>&1 ) > /dev/null 2>&1 < /dev/null &
echo "eval -try-client '$kak_opt_toolsclient' %{ echo "eval -try-client '$kak_opt_toolsclient' %{
edit! -fifo ${output} *make* edit! -fifo ${output} -scroll *make*
set buffer filetype make set buffer filetype make
hook buffer BufClose .* %{ nop %sh{ rm -r $(dirname ${output}) } } hook buffer BufClose .* %{ nop %sh{ rm -r $(dirname ${output}) } }
}" }"

View File

@ -22,16 +22,29 @@ CharCount get_column(const Buffer& buffer,
return col; return col;
} }
Buffer* create_fifo_buffer(String name, int fd) Buffer* create_fifo_buffer(String name, int fd, bool scroll)
{ {
Buffer* buffer = new Buffer(std::move(name), Buffer::Flags::Fifo | Buffer::Flags::NoUndo); Buffer* buffer = new Buffer(std::move(name), Buffer::Flags::Fifo | Buffer::Flags::NoUndo);
auto watcher = new FDWatcher(fd, [buffer](FDWatcher& watcher) { auto watcher = new FDWatcher(fd, [buffer, scroll](FDWatcher& watcher) {
constexpr size_t buffer_size = 1024 * 16; constexpr size_t buffer_size = 1024 * 16;
char data[buffer_size]; char data[buffer_size];
ssize_t count = read(watcher.fd(), data, buffer_size); ssize_t count = read(watcher.fd(), data, buffer_size);
buffer->insert(buffer->end()-1, count > 0 ? String(data, data+count) auto pos = buffer->end()-1;
bool prevent_scrolling = pos == buffer->begin() and not scroll;
if (prevent_scrolling)
++pos;
buffer->insert(pos, count > 0 ? String(data, data+count)
: "*** kak: fifo closed ***\n"); : "*** kak: fifo closed ***\n");
if (prevent_scrolling)
{
buffer->erase(buffer->begin(), buffer->begin()+1);
buffer->insert(buffer->end(), "\n");
}
if (count <= 0) if (count <= 0)
{ {
kak_assert(buffer->flags() & Buffer::Flags::Fifo); kak_assert(buffer->flags() & Buffer::Flags::Fifo);

View File

@ -41,7 +41,7 @@ inline void avoid_eol(const Buffer& buffer, Selection& sel)
CharCount get_column(const Buffer& buffer, CharCount get_column(const Buffer& buffer,
CharCount tabstop, BufferCoord coord); CharCount tabstop, BufferCoord coord);
Buffer* create_fifo_buffer(String name, int fd); Buffer* create_fifo_buffer(String name, int fd, bool scroll = false);
} }

View File

@ -46,7 +46,7 @@ Buffer* open_or_create(const String& filename, Context& context)
return buffer; return buffer;
} }
Buffer* open_fifo(const String& name , const String& filename) Buffer* open_fifo(const String& name , const String& filename, bool scroll)
{ {
int fd = open(parse_filename(filename).c_str(), O_RDONLY); int fd = open(parse_filename(filename).c_str(), O_RDONLY);
fcntl(fd, F_SETFD, FD_CLOEXEC); fcntl(fd, F_SETFD, FD_CLOEXEC);
@ -55,7 +55,7 @@ Buffer* open_fifo(const String& name , const String& filename)
BufferManager::instance().delete_buffer_if_exists(name); BufferManager::instance().delete_buffer_if_exists(name);
return create_fifo_buffer(std::move(name), fd); return create_fifo_buffer(std::move(name), fd, scroll);
} }
const PerArgumentCommandCompleter filename_completer({ const PerArgumentCommandCompleter filename_completer({
@ -111,7 +111,7 @@ void edit(const ParametersParser& parser, Context& context)
buffer = new Buffer(name, Buffer::Flags::None); buffer = new Buffer(name, Buffer::Flags::None);
} }
else if (parser.has_option("fifo")) else if (parser.has_option("fifo"))
buffer = open_fifo(name, parser.option_value("fifo")); buffer = open_fifo(name, parser.option_value("fifo"), parser.has_option("scroll"));
else else
buffer = open_or_create(name, context); buffer = open_or_create(name, context);
} }
@ -139,7 +139,8 @@ void edit(const ParametersParser& parser, Context& context)
ParameterDesc edit_params{ ParameterDesc edit_params{
SwitchMap{ { "scratch", { false, "create a scratch buffer, not linked to a file" } }, SwitchMap{ { "scratch", { false, "create a scratch buffer, not linked to a file" } },
{ "fifo", { true, "create a buffer reading its content from a named fifo" } } }, { "fifo", { true, "create a buffer reading its content from a named fifo" } },
{ "scroll", { false, "place the initial cursor so that the fifo will scroll to show new data" } } },
ParameterDesc::Flags::None, 1, 3 ParameterDesc::Flags::None, 1, 3
}; };