How do you overlap text in C terminal -
one of training exercises in c programming book goes following: (translated swedish)
if use writing/typing terminal kan sometimes, normal typewriter, underline word stepping on line , writing _ under word. write program writes string in variable
sunderlined.
my attempt looks this:
#include <stdio.h> int main(void) { char *s; printf("input: "); scanf("%ms", &s); (int i=0; s[i] != '\0'; i++) { printf("%c\b_", s[i]); } printf("\n"); return 0; } this not work expect terminal output be:
$> gcc -wall -std=c99 file.c $> ./file.c input: test test //underlined $> but instead get:
$> gcc -wall -std=c99 file.c $> ./file.c input: test ____ $> does know how or book wrong?
i haven't found way allow literal rendering of 1 character on another, sadly (i didn't think possible modern terminals, i'm happy proven wrong wumpus q. wumbley has made point piping through less allows this. i've not had time @ how/why works within less though).
i'd propose workaround - there way enable underscoring little more directly using ansi code \033[4m.
modifying code:
#include <stdio.h> int main() { char *s; printf("input: "); scanf("%ms", &s); printf("\033[4m"); // enable underlining printf("%s", s); // print string printf("\033[0m"); // reset text attributes (disable underlining) printf("\n"); return 0; } you can find other ansi graphic settings in sgr table in csi codes section on wikipedia, here.
the \033 specifies it's terminal escape code, combination of \e [ specifies it's terminal control signal, <number>m specifies we're doing "sgr", "select graphic rendition" command, , number 4 parameter corresponds effect "underline: single". 0 corresponds reset.
i welcome corrections though, don't know ansi code format.
i've skimmed through less source, , suspect it's converting sequences _\ba utf underlined characters - haven't quite got bottom of yet.
Comments
Post a Comment