0

I am currently learning the Termcaps Library and i want to underline a line. My problem, when i do it, my character becomes a C . Does someone have an idea why ? I compiled with -lcurses This is how I initialized my termcaps :

void        init_termcaps(t_env *e)
{
    char           *name_term;
    int            ierror[2];

    name_term = getenv("TERM");
    ierror[0] = tgetent(NULL, name_term);
    ierror[1] = tcgetattr(0, &e->term);
    print_termcaps_error(ierror);
    e->term.c_lflag &= ~(ECHO | ICANON);
    e->term.c_cc[VMIN] = 1;
    e->term.c_cc[VTIME] = 0;
    if (tcsetattr(0, TCSANOW, &e->term) == -1)
        ft_printexit("ERROR init termcaps\n", 1);
    else
        ft_putendl("termcaps init done.");
}

and this is how I underlined :

void    underline_line(t_llist *tmp)
{
    int i;

    i = 0;
    tputs(ft_tgetstr("us"), AFFCNT, ft_iputchar);
    while (CONTENT->word[i])
    {
        tputs(ft_tgetstr("kr"), AFFCNT, ft_iputchar);
        i++;
    }
    tputs(ft_tgetstr("ue"), AFFCNT, ft_iputchar);
    while (i-- >= 0)
        tputs(ft_tgetstr("le"), AFFCNT, ft_iputchar);
}
Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
albttx
  • 3,444
  • 4
  • 23
  • 42

1 Answers1

1

Your example tries to underline existing text on the screen by

  • turning on the underline-attribute
  • moving the cursor from left-to-right
  • turning the underline attribute off

As a rule, terminals do not work that way. Your example should simply (re)print the word to be underlined rather than moving the cursor. Video attributes are applied to text as it is printed, and cannot be modified except by rewriting the text.

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105