Termcap with parameters

2019-08-08 09:51发布

问题:

I am coding a shell-like in C and I want to implement the line edition functionality, I already implemented the basic of it, now I want to implement ctrl+l which clear the screen then display the prompt and the line I was working on.

I need to use the termcap :

'cm' String to position the cursor at line l, column c.

My question is how to I pass the variable l and c to the termcap ?

回答1:

Suppose you have the cm capability stored in the term_cm variable. Then you would substitute parameters using the tgoto function:

char *s = tgoto (term_cm, c, l);
tputs (s, 1, putchar);


回答2:

To clear the screen use this :

write(1, tgetstr("cl", 0), strlen(tgetstr("cl", 0)));


标签: c shell termcap