5

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:

5
  • If you do not care whether or not the screen is filled and cleared, then just do exactly that and switch the color of the font and the background appropriately. You just hav to use the correct escape sequence. arwin.net/tech/bash.php Commented Aug 14, 2015 at 12:20
  • Normally programs achieve this behavior with ncurses-library and can do this in their output, I don't know if there is a tool to do this in bash natively. Commented Aug 14, 2015 at 12:22
  • 1
    If there were a program that did this more than about once an hour, I'd never use it. Nor would people that value their eyes. Commented Aug 14, 2015 at 12:22
  • @msw yeah but it could be a nice feature to alert someone. By the way when this is what you want to make, you can use notify-send which is a bit less verbose. Commented Aug 14, 2015 at 12:24
  • @msw I want to know this for two purposes. The first is as a way to highlight clearly activities in a large array of open terminals. The second is as a way to transmit binary data visually on a computer display for encoding using a vision algorithm. Commented Aug 14, 2015 at 16:18

4 Answers 4

11

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
Sign up to request clarification or add additional context in comments.

8 Comments

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 :-)
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.)
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...
@chepner Thank you very much for your assistance. These ANSI codes are exactly what I need.
@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.
|
5

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

Comments

1

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.

3 Comments

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.
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?
@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.
1

You can can call Python inline from Bash as follows

 python -c 'import curses ; w=curses.initscr() ; curses.flash() ; curses.endwin() '

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.