0

Minicom has this useful setting called "character tx delay":

minicom screenshot

Is there a setting like this for GNU screen, too?

1
  • screen has a slowpaste setting that only applies when pasting text. For shell scripts, expect has a send_slow option.
    – meuh
    Commented Jul 1, 2021 at 21:06

2 Answers 2

1

I'm not a screen expert, so there is probably a better solution, but this might be good enough for you. slowpaste only applies to the paste command, but it is possible to use xsel to copy the current X11 selection to a file, and then use screen's readreg command to read this file into a register. Finally, paste can paste a register's contents. The following in ~/.screenrc worked for me:

defslowpaste 100
bindkey ^v exec sh -c 'xsel -o >/tmp/sel; screen -X eval "readreg p /tmp/sel" "paste p"'

Using slowpaste and a per-character delay in milliseconds does not seem to work in this startup file as there is no current window yet, but setting the default value with defslowpaste works well.

This binds the control-v key to a shell script of 2 commands. The first one runs xsel -o to get the X11 selection into a file /tmp/sel. The second one invokes screen with 2 builtin commands: readreg reads the file into register p, and paste causes the characters to appear with a delay of 100msecs between them.

This uses the information from Stéphane Chazelas's answer about exec returning immediately, so you cannot use eval to chain it with other commands; the answer also explains how using the default exec "fdpat" of ... you can now replace the xsel by a cat, for example, and read input from the user upto an end-of-file control-D.

1
  • I dont know how to read stdin to a register, but I'll continue with some experiments. The eval is needed because there are 3 commands. The exec is needed to run a program (not a builtin screen command), and the sh is needed to have the redirection work (>file).
    – meuh
    Commented Jul 3, 2021 at 6:10
1

It seems like there is no general TX delay. However, for pasting text with the paste command, screen has a slowpaste setting:

Command: slowpaste msec

Command: defslowpaste msec

(none)

Define the speed text is inserted in the current window by the paste command. If the slowpaste value is nonzero text is written character by character. screen will pause for msec milliseconds after each write to allow the application to process the input. only use slowpaste if your underlying system exposes flow control problems while pasting large amounts of text. defslowpaste specifies the default for new windows.

Source: https://www.gnu.org/software/screen/manual/screen.html

You can add the following line to your .screenrc to obtain a "slowpaste mode" for input from stdin:

bindkey ^V exec ... sh -c 'cat >"$HOME/.screen-slowpaste.tmp" && screen -S "$STY" -X eval "slowpaste 1" "readreg p \"$HOME/.screen-slowpaste.tmp\"" "paste p"'

It works by registering a new key binding for CTRLV which uses cat to listen for input from stdin (send EOF via CTRLD to finish) and saves it into a file called $HOME/.screen-slowpaste.tmp. Afterwards, the contents are read into a register with readreg and pasted. In this example, the delay has been set to 1 ms with slowpaste 1.

You could also skip the temporary file by saving the input as an environment variable with SCREENSLOWPASTE="$(cat </dev/stdin)" and copying it into the register with register p "$SCREENSLOWPASTE". However, this variant is very limited in the amount of text you can paste and you'll run into "command too long" errors quickly.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .