termcap

How to get the cursor position in a C program using termcap, without writing a character?

你离开我真会死。 提交于 2019-12-01 19:23:20
I would like to know how to get the cursor position (x, y) in my program, without writing anything on the screen neither tracking it all the time. I found out a way to get its position with this function (I don't check the return of read, write, etc here to write a smaller code on this subject but I do it in my program) : void get_cursor_position(int *col, int *rows) { int a = 0; int i = 0; char buf[4] write(1, "\033[6n", 4); // string asking for the cursor position read(1, buf, 4); while (buf[i]) { if (buf[i] >= 48 && buf[i] <= 57) { if (a == 0) *rows = atoi(&buf[i]) - 1; else *col = atoi(&

What does &= mean? [closed]

南楼画角 提交于 2019-12-01 14:52:15
I'm using termcaps and I don't understand what &= means in this example: term.c_lflag &= ~(ICANON); Could anyone explain to me how this works? That's a common way to set a specific bit to 0 in an integer that represents a bitfield. unsigned a = ...; // ... unsigned int mask = 1 << 11; // mask for 12th bit a |= mask; // set 12th bit to 1 a &= ~mask; // set 12th bit to 0 Enabling a bit works by bitwise- or ing a number with a mask that looks like 000010000 . Disabling a bit works by bitwise- and ing a number with a mask like 111101111 (hence the need for ~ , which stands for bitwise negation).

What does &= mean? [closed]

喜你入骨 提交于 2019-12-01 12:37:47
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . I'm using termcaps and I don't understand what &= means in this example: term.c_lflag &= ~(ICANON); Could anyone explain to me how this works? 回答1: That's a common way to set a specific bit to 0 in an integer that represents a bitfield. unsigned a = ...; // ... unsigned int mask = 1 << 11; // mask for 12th bit a

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(