LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Formated output from C (https://www.linuxquestions.org/questions/programming-9/formated-output-from-c-328563/)

Ephracis 05-30-2005 11:13 AM

Formated output from C
 
I would like to know if there is any way to create some nice formatted output (like bold text) to the console in C. I have played a little with ncurses before but that creates a new "windows" which is destroyed when the program dies.

Regards.

kryptonite0110 05-30-2005 12:15 PM

in linux you use escape codes, youse the termios structure and set: c_oflag |= OPOST for output processing, and then (i believe) you can just write your standard escape sequences to stdout:

http://www.faqs.org/docs/Linux-HOWTO...CAPE-SEQUENCES

Ephracis 05-30-2005 12:56 PM

Wasn't the site at that url just talking about changing the bash prompt? How would I do if I wanted to use something like printf and get output in bold?

itsme86 05-30-2005 04:07 PM

Run this program and see if you can learn anything from it:
Code:

#include <stdio.h>

int main(void)
{
  int i, color, attrs[] = { 0, 1, 5, 7 };

  for(i = 0;i < 4;++i)
  {
    printf("\33[0;37m%d | ", attrs[i]);
    for(color = 30;color < 38;++color)
      printf("\33[%d;%dm%d ", attrs[i], color, color);
    printf("\n");
  }

  printf("\33[0;37m");
  return 0;
}

EDIT: A google search on "ansi escape codes" will give you lots of good information about it.


All times are GMT -5. The time now is 12:55 AM.