Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7710477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:08:09+00:00 2026-06-01T01:08:09+00:00

I need to be able to be able to make some text on terminal

  • 0

I need to be able to be able to make some text on terminal more noticeable, and what I thought was to make the text colored. Either the actual text, or the space in each letter’s rectangle-thingy (think vi’s cursor). The only two extra specs that I think are important for my application are : the program should be distro-independent (a certainty is that the code will only be run under BASH), and it shouldn’t output extra characters when writing to a file (either from the actual code, or when piping the output)

I searched the web for some info, but I could only find info for the deprecated cstdlib (stdlib.h), and I need (actually, it’s more of a “want”) to do it using the functionality of iostream.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T01:08:10+00:00Added an answer on June 1, 2026 at 1:08 am

    Most terminals respect the ASCII color sequences. They work by outputting ESC, followed by [, then a semicolon-separated list of color values, then m. These are common values:

    Special
    0  Reset all attributes
    1  Bright
    2  Dim
    4  Underscore   
    5  Blink
    7  Reverse
    8  Hidden
    
    Foreground colors
    30  Black
    31  Red
    32  Green
    33  Yellow
    34  Blue
    35  Magenta
    36  Cyan
    37  White
    
    Background colors
    40  Black
    41  Red
    42  Green
    43  Yellow
    44  Blue
    45  Magenta
    46  Cyan
    47  White
    

    So outputting "\033[31;47m" should make the terminal front (text) color red and the background color white.

    You can wrap it nicely in a C++ form:

    enum Color {
        NONE = 0,
        BLACK, RED, GREEN,
        YELLOW, BLUE, MAGENTA,
        CYAN, WHITE
    }
    
    std::string set_color(Color foreground = 0, Color background = 0) {
        char num_s[3];
        std::string s = "\033[";
    
        if (!foreground && ! background) s += "0"; // reset colors if no params
    
        if (foreground) {
            itoa(29 + foreground, num_s, 10);
            s += num_s;
    
            if (background) s += ";";
        }
    
        if (background) {
            itoa(39 + background, num_s, 10);
            s += num_s;
        }
    
        return s + "m";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to be able to make a program that looks through a mailbox
I need to be able to make a tree like structure in the appengine
I need to be able to make retries in node.js in the event of
In my current project (presentation, slide software) I need to be able to make
We need to make our enterprise ASP.NET/NHibernate browser-based application able to function when connected
For various reasons, I need to put a (mostly) transparent <div> over some text.
I need to make a parser to be able to extract logical structure from
I need a simple encryption for some text strings. I want to create coupon
I need to be able to take an arbitrary text input that may have
I need to make a program in C++ that must read and write text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.