BASH: how can the terminal be set to flash?
Asked Answered
G

4

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:

Grethel answered 14/8, 2015 at 12:11 Comment(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.phpSpeechmaking
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.Unread
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.Denudate
@Denudate 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.Unread
@Denudate 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.Grethel
C
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
Coolish answered 14/8, 2015 at 13:35 Comment(8)
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.1Downpipe
Also I found that this solution does not work within a tmux session.Downpipe
I
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
Ianteen answered 30/7, 2019 at 9:17 Comment(0)
G
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.

Gooseflesh answered 14/8, 2015 at 13:11 Comment(3)
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
M
1

You can can call Python inline from Bash as follows

 python -c 'import curses ; w=curses.initscr() ; curses.flash() ; curses.endwin() '
Marucci answered 12/4, 2019 at 9:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.