terminfo

How do I determine if a terminal is color-capable?

谁说胖子不能爱 提交于 2019-11-28 20:15:56
I would like to change a program to automatically detect whether a terminal is color-capable or not, so when I run said program from within a non-color capable terminal (say M-x shell in (X)Emacs), color is automatically turned off. I don't want to hardcode the program to detect TERM={emacs,dumb}. I am thinking that termcap/terminfo should be able to help with this, but so far I've only managed to cobble together this (n)curses-using snippet of code, which fails badly when it can't find the terminal: #include <stdlib.h> #include <curses.h> int main(void) { int colors=0; initscr(); start_color(

Using the “alternate screen” in a bash script

谁说我不能喝 提交于 2019-11-27 17:31:31
The alternate screen is used by many "user-interactive" terminal applications like vim, htop, screen, alsamixer, less, ... It is like a different buffer of the terminal content, which disappears when the application exits, so the whole terminal gets restored and it looks like the application hasn't output anything. I'd like to achieve exactly the same thing in my own shell (bash) script, except that it doesn't have to be that portable. I'd stick to linux only and xterm-based terminal emulators; but the solution should use something like tput if it's possible. However, I don't want to use some

Using the “alternate screen” in a bash script

谁说胖子不能爱 提交于 2019-11-26 18:59:56
问题 The alternate screen is used by many "user-interactive" terminal applications like vim, htop, screen, alsamixer, less, ... It is like a different buffer of the terminal content, which disappears when the application exits, so the whole terminal gets restored and it looks like the application hasn't output anything. I'd like to achieve exactly the same thing in my own shell (bash) script, except that it doesn't have to be that portable. I'd stick to linux only and xterm-based terminal