Colored text in CLI

General FreeBASIC programming questions.
Post Reply
darkhog
Posts: 132
Joined: Oct 05, 2011 21:19

Colored text in CLI

Post by darkhog »

As you probably know DOS, Linux and Windows supports colored text in their consoles (16 for foreground and 8 for bg). But how to change text color in CLI in FB?
SARG
Posts: 1876
Joined: May 27, 2005 7:15
Location: FRANCE

Re: Colored text in CLI

Post by SARG »

From the help

Color : Sets the display foreground / background color that is used with console output and graphics output of text

Syntax : Declare Function Color ( ByVal foreground As Integer , ByVal background As Integer ) As Integer

Usage : Color [foreground] [, background]
result = Color [( [foreground] [, background] )]

Parameters
foreground = the foreground color to set
background = the background color to set

Code: Select all

' Sets 320x240 in 32bpp color depth
Screen 14, 32

' Sets orange foreground and dark blue background color
Color RGB(255, 128, 0), RGB(0, 0, 64)

' Clears the screen to the background color
Cls                     

' Prints "Hello World!" in the middle of the screen
Locate 15, 14
Print "Hello World!"

Sleep
darkhog
Posts: 132
Joined: Oct 05, 2011 21:19

Re: Colored text in CLI

Post by darkhog »

You did not understand my post, right? I want to do it in CLI w/out setting graphic mode (which will also spawn graphics window on Linux/Windows). Purely in CLI, like QBasic had different colors for its menus, etc. or Turbo Pascal had syntax highlight.
MOD
Posts: 558
Joined: Jun 11, 2009 20:15

Re: Colored text in CLI

Post by MOD »

COLOR also works in console, you don't need a screen. It's always a good idea to read the wiki.

Code: Select all

Print 1234
Color 3, 0
Print 1234
Sleep
SARG
Posts: 1876
Joined: May 27, 2005 7:15
Location: FRANCE

Re: Colored text in CLI

Post by SARG »

darkhog wrote:You did not understand my post, right? .
I understood it and my answer was right. Only the example was not corresponding.....I suppose you didn't read carefully the text of the post. But it doesn't matter ;-)
darkhog
Posts: 132
Joined: Oct 05, 2011 21:19

Re: Colored text in CLI

Post by darkhog »

Sorry. Was very furious when I wrote my 2nd post, because my girlfriend dumped me and that probably affected my judgment and way I wrote previous post. Again, sorry.
counting_pine
Site Admin
Posts: 6323
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Re: Colored text in CLI

Post by counting_pine »

For what it's worth, the documentation page is online at http://www.freebasic.net/wiki/keypgColor. It's easier to see the code in its context there as a not-necessarily-entirely-relevant example.
Post Reply