Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • @Gilles, you want the query to be sent via the prompt after the terminal discipline echo is disabled. See edit. Commented Mar 12, 2016 at 7:06
  • @StéphaneChazelas Using another terminal program (gnome-terminal) (which is a xterm terminal) I got your code to work correctly (both in bash and zsh) Oddly enough: tput colors reports only 8 even if the terminal is capable of presenting 256 colors. Also, the xterm-color (Konsole) tput colors only reports 8 even if that terminal is fully capable of presenting 16 million colors (and all 256 colors, of course). And no, no tmux or screen that may "color" :-) (change that is) the results (I was aware of that detail). In short: your code may fail in some terminal/consoles. Commented Mar 12, 2016 at 21:55
  • Ah, tohex added to my answer, A bit longer than what I was expecting, but the 256 colors have quite a bit of quirk turns. Commented Mar 12, 2016 at 22:02
  • @StéphaneChazelas, is there how to convert XTERM colour format to ANSI colour format? Commented Feb 14, 2022 at 3:34