termux / termux-app

Termux - a terminal emulator application for Android OS extendible by variety of packages.
https://f-droid.org/en/packages/com.termux
Other
34.69k stars 3.65k forks source link

copied text includes whitespace #2108

Open dead10ck opened 3 years ago

dead10ck commented 3 years ago

Problem description

When you select a few lines from Termux and copy them, a whole bunch of extra whitespace gets copied to the clipboard. It's as if all the blank space on the screen is rendered as whitespace characters, instead of... well, nothing. e.g. if your screen is 120 characters wide, and a line only has 20 characters, what gets copied to the clipboard is those 20 characters and then 100 whitespaces.

It makes it pretty useless for copying more than one line at a time.

Steps to reproduce

Run a command that prints out a few short lines, then copy all the lines, then paste in another app.

Expected behavior

Only the actual text should be copied.

Additional information

agnostic-apollo commented 3 years ago

I can't reproduce this in android 7 device or android 11 avd. You will only copy 100 spaces if your commands outputted 100 spaces. Otherwise, it wouldn't. What commands are you running? Are you using bash shell or instead some shell text editor like emacs or terminal multiplexer like tmux?

Check here and here.

dead10ck commented 3 years ago

Interesting, I am using tmux, but it was still happening outside of it. I am also using zsh, and I tried switching to bash, and the problem went away. So it must be something about zsh or the syntax coloring plugin I'm using. The strange thing is this doesn't happen on my laptop, in Alacritty or GNOME Terminal. Someone mentioned in that second Stackoverflow question that most Terminal applications will strip trailing whitespaces when you copy. So maybe this is a feature request?

agnostic-apollo commented 3 years ago

Getting selected code is handled by TerminalBuffer. It might be possible to optionally do what you ask by adding a termux.properties for it. I haven't looked into the code much, so will have to see in future, but provide clear instructions on how to reproduce the issue in termux (preferably fresh install), so it can be tested.

yesco commented 3 years ago

I've noticed a similar issue, especially when copying from the terminal window. I paste into emacs and I get all the spaces, and no newlines. I guess having the trailing spaces removed seems reasonable. I'm surprised there is no newlines when I copy. I need to massage the paste quite a lot.

I also had this curious feeling when I was CTRL-King in the shell editing, that it should have been stored in the paste-buffer, but that's possibly a bit of stretch.

harieamjari commented 3 years ago

Does the text in your window get messy when you tried zooming in and out? If yes, you should try doing it on a new fresh session.

saralaya00 commented 3 years ago

I have faced something similar where I end up getting couple of odd characters when pasting with ctrl+alt+v For the record I use a Samsng S20 FE, bluetooth keyboard with samsung dex termux with zsh + ohmyzsh

This only seems to happen the first time or whenever I copy new text Screenshot_20210815-013718_Termux

ghost commented 3 years ago

@olos00 Disable bracketed paste in zsh.

unset zle_bracketed_paste