summaryrefslogtreecommitdiff
path: root/test/commands
diff options
context:
space:
mode:
authorJohannes Altmanninger <aclopte@gmail.com>2024-01-28 18:23:08 +0100
committerMaxime Coste <mawww@kakoune.org>2024-01-30 08:24:27 +1100
commit582c3c56b218b9be9745efc69c2eb282bbe99b67 (patch)
treec4c82fc177193886074529cfd5d307f18a3bac6c /test/commands
parentfdbad4d9b2183e03d3cc9a9d71b1055a49350331 (diff)
Do not add trailing newline to non-scrolling fifo buffers
Internally, all lines have a trailing "\n". Buffers created empty (like fifo buffers) start with a single line. When reading data into fifo buffers, we insert *before* the last line's trailing newline ("last newline"). This enables autoscrolling (enabled with "edit -scroll") as long as the cursor is on the last newline. When autoscrolling is disabled, we have a special case to insert *after* the last newline. This means that a cursor on that newline won't be moved. Then we transplant the newline character from the beginning to the end of the buffer. This special case happens only on the very first fifo read; on subsequent reads, the cursor at position 1.1 will not be moved anway because insertions happen below 1.1. Since we always insert (effectively) before the last newline, fifo buffers have a trailing empty line. For autoscrolling buffers this seems correct; it gives users an obvious way to toggle autoscrolling. For non-scrolling buffers the newline is redundant. Remove it. This requires keeping track of whether the last newline comes from the fifo, or was added by us. The shortest fix I could find is to always append to the buffer if not scrolling, and then delete the added newline character if applicable. m_buffer.insert(m_scroll ? pos : m_buffer.next(pos), StringView(data, data+count)); if (not m_scroll and not m_had_trailing_newline) m_buffer.erase(pos, m_buffer.next(pos)); maybe that's the best fix overall; but erasing at the end seems better than erasing in the middle, so do that whenever possible. Reported in https://lists.sr.ht/~mawww/kakoune/%3CZbTK7qit9nzvrMkx@gmail.com%3E
Diffstat (limited to 'test/commands')
-rw-r--r--test/commands/edit-fifo-noscroll/cmd1
-rw-r--r--test/commands/edit-fifo-noscroll/out3
-rw-r--r--test/commands/edit-fifo-noscroll/script19
3 files changed, 23 insertions, 0 deletions
diff --git a/test/commands/edit-fifo-noscroll/cmd b/test/commands/edit-fifo-noscroll/cmd
new file mode 100644
index 00000000..9a2627d5
--- /dev/null
+++ b/test/commands/edit-fifo-noscroll/cmd
@@ -0,0 +1 @@
+:nop %sh{mkfifo fifo}; edit -fifo fifo *fifo*<ret>
diff --git a/test/commands/edit-fifo-noscroll/out b/test/commands/edit-fifo-noscroll/out
new file mode 100644
index 00000000..e0ee5094
--- /dev/null
+++ b/test/commands/edit-fifo-noscroll/out
@@ -0,0 +1,3 @@
+* line1
+* line2
+2049
diff --git a/test/commands/edit-fifo-noscroll/script b/test/commands/edit-fifo-noscroll/script
new file mode 100644
index 00000000..10fe9340
--- /dev/null
+++ b/test/commands/edit-fifo-noscroll/script
@@ -0,0 +1,19 @@
+ui_out -ignore 7
+exec 5>fifo
+ui_out '{ "jsonrpc": "2.0", "method": "refresh", "params": [true] }'
+
+echo '* line1' >&5
+ui_out '{ "jsonrpc": "2.0", "method": "draw", "params": [[[{ "face": { "fg": "black", "bg": "white", "underline": "default", "attributes": [] }, "contents": "*" }, { "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": " line1\u000a" }]], { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, { "fg": "blue", "bg": "default", "underline": "default", "attributes": [] }] }'
+ui_out -ignore 2
+
+echo '* line2' >&5
+ui_out '{ "jsonrpc": "2.0", "method": "draw", "params": [[[{ "face": { "fg": "black", "bg": "white", "underline": "default", "attributes": [] }, "contents": "*" }, { "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": " line1\u000a" }], [{ "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "* line2\u000a" }]], { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, { "fg": "blue", "bg": "default", "underline": "default", "attributes": [] }] }'
+ui_out -ignore 2
+
+dd if=/dev/zero bs=2049 count=1 2>/dev/null | sed s/././g >&5
+ui_out -ignore 3
+ui_in '{ "jsonrpc": "2.0", "method": "keys", "params": [ "gjxH|wc -c<ret>" ] }'
+ui_out -ignore 6
+
+exec 5>&-
+ui_out '{ "jsonrpc": "2.0", "method": "draw_status", "params": [[], [{ "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "*fifo* 3:4 " }, { "face": { "fg": "black", "bg": "yellow", "underline": "default", "attributes": [] }, "contents": "[scratch]" }, { "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": " " }, { "face": { "fg": "blue", "bg": "default", "underline": "default", "attributes": [] }, "contents": "1 sel" }, { "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": " - client0@[kak-tests]" }], { "fg": "cyan", "bg": "default", "underline": "default", "attributes": [] }] }'