Skip to content

Commit

Permalink
Do not insert any end-of-line when piping data out
Browse files Browse the repository at this point in the history
This will unfortunately break some use case which will require
using wrapper scripts to add the necessary newline. It is however
harder to do the contrary, and it makes a lot of other use case
possible, such as checksuming.

Fixes #3669
  • Loading branch information
mawww committed Jan 24, 2022
1 parent 00080f8 commit 6f135c0
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 10 deletions.
3 changes: 3 additions & 0 deletions src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ struct {
unsigned int version;
StringView notes;
} constexpr version_notes[] = { {
0,
"» pipe commands do not append final end-of-lines anymore\n"
}, {
20211107,
"» colored and curly underlines support (undocumented in 20210828)\n"
}, {
Expand Down
13 changes: 3 additions & 10 deletions src/normal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -582,23 +582,16 @@ void pipe(Context& context, NormalParams params)
const auto end = changes_tracker.get_new_coord_tolerant(sel.max());

String in = buffer.string(beg, buffer.char_next(end));
const bool insert_eol = in.back() != '\n';
if (insert_eol)
in += '\n';

// Needed in case we read selections inside the cmdline
context.selections_write_only().set({keep_direction(Selection{beg, end}, sel)}, 0);

String out = ShellManager::instance().eval(
cmdline, context, in,
ShellManager::Flags::WaitForStdout).first;

if (insert_eol)
{
in.resize(in.length()-1, 0);
if (not out.empty() and out.back() == '\n')
out.resize(out.length()-1, 0);
}
if (in.back() != '\n' and not out.empty() and out.back() == '\n')
out.resize(out.length()-1, 0);

auto new_end = apply_diff(buffer, beg, in, out);
if (new_end != beg)
new_sels.push_back(keep_direction({beg, buffer.char_prev(new_end), std::move(sel.captures())}, sel));
Expand Down
1 change: 1 addition & 0 deletions test/regression/3669-pipe-adds-extra-newline/cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
|cksum<ret>
1 change: 1 addition & 0 deletions test/regression/3669-pipe-adds-extra-newline/in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
%(foo)
1 change: 1 addition & 0 deletions test/regression/3669-pipe-adds-extra-newline/out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2470157969 3

0 comments on commit 6f135c0

Please sign in to comment.