I want to get a BASH terminal flashing. The goal is to get the terminal to flash between two colours, say white and black, substantially, using standard Linux utilities. I don't mind if the terminal is filled with characters and cleared in order to do this. A rough picture of what this could look like is as follows:
BASH: how can the terminal be set to flash?
You can toggle between normal and reverse video with the following shell commands:
printf '\e[?5h' # Turn on reverse video
printf '\e[?5l' # Turn on normal video
Nitpicking: this one depends on the terminal emulation. Ok now almost every emulator supports this ANSI code, but there used to be many other terminal, just look at the terminfo database... But you are right, this is what OP asked for :-) –
Gooseflesh
Yeah, I was looking into the correct way of using
terminfo
or termcap
(I can't even remember which one is the modern database and/or which is horribly obsolete), but couldn't track it down quickly so I just left this. (These are ANSI escape characters, so most common terminals should support them.) –
Coolish terminfo is the young one, termcap is the grandaddy from the 70s. I remember TeleVideo terminals that did not know ANSI sequences. Snff, maybe I could still find one in a museum... –
Gooseflesh
@Coolish Thank you very much for your assistance. These ANSI codes are exactly what I need. –
Grethel
@SergeBallesta Thank you for your illuminating comments. I'm using GNOME Terminal and xterm, both of which are fairly standard and can recognise the ANSI codes. –
Grethel
termcap was late 1970s, and terminfo was early 1980s (5-6 years difference, more than 30 years ago for the later of the two). Call them mismatched siblings. –
Disparate
I found it necessary to sleep in between:
printf '\e[?5h' ; sleep 0.1; printf '\e[?5l'; sleep 0.1
–
Downpipe Also I found that this solution does not work within a
tmux
session. –
Downpipe Here's a tiny bash script i use for this purpose. It also resets the terminal when you ctrl-c.
#!/usr/bin/env bash
set -e
trap ctrl_c INT
function ctrl_c() {
printf '\e[?5l'
}
while true; do
printf '\e[?5h'
sleep 0.5
printf '\e[?5l'
sleep 0.5
done
What you are asking is called the visible bell. It can be enabled on major terminal emulators like xterm (Ctrl + middle button menu) or putty( Settings/Terminal/Bell). Unfortunately, there is no general way to do it.
But once it has been done, echo Ctrl+G
causes the terminal to flash instead of beeping.
The visible bell is just one application of flashing; I think the OP wants to know how to actually tell the terminal how to flash. –
Coolish
That triggers the bell, which the terminal may or may not (depending on the setting), display using flashing. But what is the actual terminal command that will causing flashing, whether or not the visible bell is set? –
Coolish
@SergeBallesta Thank you for your informative comments on the visible bell. The solution provided by chepner is more direct, but your solution is informative in a more general way. –
Grethel
You can can call Python inline from Bash as follows
python -c 'import curses ; w=curses.initscr() ; curses.flash() ; curses.endwin() '
© 2022 - 2024 — McMap. All rights reserved.
notify-send
which is a bit less verbose. – Unread