aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2019-06-29 21:03:38 +0200
committerGitHub <noreply@github.com>2019-06-29 21:03:38 +0200
commit2d4a37ebab354afb94dfe600b302d8a2b1f2d889 (patch)
treefb6c12cef807625b9008487389c3eefd42a8b6af
parentc207095445286321cbb319ab1498c34b204760cf (diff)
downloadrneovim-2d4a37ebab354afb94dfe600b302d8a2b1f2d889.tar.gz
rneovim-2d4a37ebab354afb94dfe600b302d8a2b1f2d889.tar.bz2
rneovim-2d4a37ebab354afb94dfe600b302d8a2b1f2d889.zip
:ls : show "R", "F" for terminal-jobs #10370
This matches Vim behavior. From `:help :ls` : R a terminal buffer with a running job F a terminal buffer with a finished job ? a terminal buffer without a job: `:terminal NONE` TODO: implement `:terminal NONE`. ref #10349
-rw-r--r--src/nvim/buffer.c8
-rw-r--r--src/nvim/channel.c8
-rw-r--r--src/nvim/event/process.h3
-rw-r--r--test/functional/ex_cmds/ls_spec.lua33
4 files changed, 48 insertions, 4 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c
index 043ae420cd..5678f518f5 100644
--- a/src/nvim/buffer.c
+++ b/src/nvim/buffer.c
@@ -29,6 +29,7 @@
#include "nvim/api/vim.h"
#include "nvim/ascii.h"
#include "nvim/assert.h"
+#include "nvim/channel.h"
#include "nvim/vim.h"
#include "nvim/buffer.h"
#include "nvim/charset.h"
@@ -2608,9 +2609,10 @@ void buflist_list(exarg_T *eap)
const int changed_char = (buf->b_flags & BF_READERR)
? 'x'
: (bufIsChanged(buf) ? '+' : ' ');
- const int ro_char = !MODIFIABLE(buf)
- ? '-'
- : (buf->b_p_ro ? '=' : ' ');
+ int ro_char = !MODIFIABLE(buf) ? '-' : (buf->b_p_ro ? '=' : ' ');
+ if (buf->terminal) {
+ ro_char = channel_job_running((uint64_t)buf->b_p_channel) ? 'R' : 'F';
+ }
msg_putchar('\n');
len = vim_snprintf(
diff --git a/src/nvim/channel.c b/src/nvim/channel.c
index 3a45a8aec7..104c79efd9 100644
--- a/src/nvim/channel.c
+++ b/src/nvim/channel.c
@@ -762,6 +762,14 @@ static void set_info_event(void **argv)
channel_decref(chan);
}
+bool channel_job_running(uint64_t id)
+{
+ Channel *chan = find_channel(id);
+ return (chan
+ && chan->streamtype == kChannelStreamProc
+ && !process_is_stopped(&chan->stream.proc));
+}
+
Dictionary channel_info(uint64_t id)
{
Channel *chan = find_channel(id);
diff --git a/src/nvim/event/process.h b/src/nvim/event/process.h
index ba2c2a6a11..13dc3839ce 100644
--- a/src/nvim/event/process.h
+++ b/src/nvim/event/process.h
@@ -56,7 +56,8 @@ static inline Process process_init(Loop *loop, ProcessType type, void *data)
static inline bool process_is_stopped(Process *proc)
{
- return proc->stopped_time != 0;
+ bool exited = (proc->status >= 0);
+ return exited || (proc->stopped_time != 0);
}
#ifdef INCLUDE_GENERATED_DECLARATIONS
diff --git a/test/functional/ex_cmds/ls_spec.lua b/test/functional/ex_cmds/ls_spec.lua
new file mode 100644
index 0000000000..0ff6f2da8a
--- /dev/null
+++ b/test/functional/ex_cmds/ls_spec.lua
@@ -0,0 +1,33 @@
+local helpers = require('test.functional.helpers')(after_each)
+local clear = helpers.clear
+local command = helpers.command
+local eq = helpers.eq
+local eval = helpers.eval
+local feed = helpers.feed
+local retry = helpers.retry
+
+describe(':ls', function()
+ before_each(function()
+ clear()
+ end)
+
+ it('R, F for :terminal buffers', function()
+ command('edit foo')
+ command('set hidden')
+ command('terminal')
+ command('vsplit')
+ command('terminal')
+ feed('iexit<cr>')
+ retry(nil, 5000, function()
+ local ls_output = eval('execute("ls")')
+ -- Normal buffer.
+ eq('\n 1 h ', string.match(ls_output, '\n *1....'))
+ -- Terminal buffer [R]unning.
+ eq('\n 2 #aR', string.match(ls_output, '\n *2....'))
+ -- Terminal buffer [F]inished.
+ eq('\n 3 %aF', string.match(ls_output, '\n *3....'))
+ end)
+ end)
+
+end)
+