bakkeby / st-flexipatch

An st build with preprocessor directives to decide which patches to include during build time
MIT License
347 stars 107 forks source link

Externalpipe with reflow patch only sends terminal content till newline #125

Closed UtkarshVerma closed 5 months ago

UtkarshVerma commented 5 months ago

I noticed that my externalpipe scripts stopped working when I turned on the reflow patch. Now, if any command has consecutive empty lines, the terminal output after that newline is not sent to the script.

This is not the case when the reflow patch is turned off.

Steps to reproduce

  1. Get source and compile: https://github.com/UtkarshVerma/st-flexipatch
  2. Add st-copyurl to PATH.
    #!/bin/sh
    # Remove null bytes from stdin.
    contents="$(cat /dev/stdin)"
    echo "$contents" >~/st
  3. Open the terminal and run the following commands in succession:
    $ ls
    $ printf "\n\n"
    $ ls
  4. Inspect ~/st and notice that terminal content are included only till the printf command (because of the successive newlines). Additionally, the \n in printf command is also unnecessarily expanded.

Here's a video of the following:

https://github.com/bakkeby/st-flexipatch/assets/31820255/3a08a459-5f2b-4ff8-94dc-2702ef7e0b1f

bakkeby commented 5 months ago

Interestingly this was caused by the + 1 that I left off in my initial fix.

The reason I left it off was that when testing the default "open urls in dmenu" external pipe command the last character of the line would be cut off, e.g.

$ echo "https://fubar.com"
https://fubar.com

would show https://fubar.com from the first echo line and https://fubar.co from the second line.

Curiously I can't reproduce that issue anymore. I added that + 1 back in and the copyout script looks to work fine now. Maybe just keep it in mind if you notice other quirks with the externalpipe patch.

UtkarshVerma commented 5 months ago

I tried the new changes and they are no longer ignoring the output after newlines. However, the "\n" in the commands are still being expanded.

Take these pictures for example: Commands that I typed. image

Output sent by externalpipe. "\n" is being expanded. image

I have opened too many issues recently. Please do not get overwhelmed and take your time. I just wanted to initiate a discussion before blindly attempting to solve it.

bakkeby commented 5 months ago

image

I can't seem to replicate. How are you printing / reading that file?

UtkarshVerma commented 5 months ago

Ah, it was echo "$contents" which was expanding the \ns. Everything's fine on st's end. Thanks!

bakkeby commented 5 months ago

Right so this probably comes down to bash echo vs other shell echo?

In bash it defaults to not interpret backslash escapes and it has to be explicitly enabled using the -e flag. In dash for example it interprets backslash escapes by default.

UtkarshVerma commented 5 months ago

Yeah, so I ended up using printf.