Terminal control/Coloured text: Difference between revisions
Content added Content deleted
m (→{{header|Phix}}: now p2js compatible) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 16: | Line 16: | ||
{{works with|MS-DOS}} |
{{works with|MS-DOS}} |
||
Prints the letter 'A' to the screen in bright cyan (color 11 in VGA) |
Prints the letter 'A' to the screen in bright cyan (color 11 in VGA) |
||
< |
<syntaxhighlight lang="asm"> .model small |
||
.stack 1024 |
.stack 1024 |
||
.data |
.data |
||
Line 43: | Line 43: | ||
mov ax,4C00h ;return to dos |
mov ax,4C00h ;return to dos |
||
int 21h |
int 21h |
||
end start</ |
end start</syntaxhighlight> |
||
=={{header|AArch64 Assembly}}== |
=={{header|AArch64 Assembly}}== |
||
{{works with|as|Raspberry Pi 3B version Buster 64 bits}} |
{{works with|as|Raspberry Pi 3B version Buster 64 bits}} |
||
<syntaxhighlight lang="aarch64 assembly"> |
|||
<lang AArch64 Assembly> |
|||
/* ARM assembly AARCH64 Raspberry PI 3B */ |
/* ARM assembly AARCH64 Raspberry PI 3B */ |
||
/* program colorterminal64.s */ |
/* program colorterminal64.s */ |
||
Line 117: | Line 117: | ||
/* for this file see task include a file in language AArch64 assembly */ |
/* for this file see task include a file in language AArch64 assembly */ |
||
.include "../includeARM64.inc" |
.include "../includeARM64.inc" |
||
</syntaxhighlight> |
|||
</lang> |
|||
<pre> |
<pre> |
||
Program start |
Program start |
||
Line 129: | Line 129: | ||
=={{header|Ada}}== |
=={{header|Ada}}== |
||
{{libheader|ANSIAda}} |
{{libheader|ANSIAda}} |
||
< |
<syntaxhighlight lang="ada">with Ada.Text_Io; |
||
with Ansi; |
with Ansi; |
||
Line 148: | Line 148: | ||
New_Line; |
New_Line; |
||
end loop; |
end loop; |
||
end Coloured;</ |
end Coloured;</syntaxhighlight> |
||
=={{header|ARM Assembly}}== |
=={{header|ARM Assembly}}== |
||
{{works with|as|Raspberry Pi}} |
{{works with|as|Raspberry Pi}} |
||
<syntaxhighlight lang="arm assembly"> |
|||
<lang ARM Assembly> |
|||
/* ARM assembly Raspberry PI */ |
/* ARM assembly Raspberry PI */ |
||
Line 236: | Line 236: | ||
bx lr @ return |
bx lr @ return |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Arturo}}== |
=={{header|Arturo}}== |
||
< |
<syntaxhighlight lang="rebol">str: "Hello World" |
||
print color #red str |
print color #red str |
||
Line 249: | Line 249: | ||
print color #cyan str |
print color #cyan str |
||
print color #black str |
print color #black str |
||
print color #white str</ |
print color #white str</syntaxhighlight> |
||
=={{header|AutoHotkey}}== |
=={{header|AutoHotkey}}== |
||
[[Image:AutoHotkey_terminal_control_coloured_text.jpeg|thumb|right]] |
[[Image:AutoHotkey_terminal_control_coloured_text.jpeg|thumb|right]] |
||
AutoHotkey is not written for the command line, so we need to use the WinAPI directly. For simplicity, this example demonstrates only the foreground colours. |
AutoHotkey is not written for the command line, so we need to use the WinAPI directly. For simplicity, this example demonstrates only the foreground colours. |
||
< |
<syntaxhighlight lang="ahk">DllCall( "AllocConsole" ) ; create a console if not launched from one |
||
hConsole := DllCall( "GetStdHandle", int, STDOUT := -11 ) |
hConsole := DllCall( "GetStdHandle", int, STDOUT := -11 ) |
||
Loop 15 |
Loop 15 |
||
Line 271: | Line 271: | ||
return out |
return out |
||
return 0 |
return 0 |
||
}</ |
}</syntaxhighlight> |
||
=={{header|BaCon}}== |
=={{header|BaCon}}== |
||
< |
<syntaxhighlight lang="freebasic">' ANSI terminal coloured text |
||
COLOR FG TO BLACK |
COLOR FG TO BLACK |
||
PRINT "a word" |
PRINT "a word" |
||
Line 286: | Line 286: | ||
' Other colours include YELLOW, BLUE, MAGENTA, CYAN, WHITE |
' Other colours include YELLOW, BLUE, MAGENTA, CYAN, WHITE |
||
' Second keyword can be BG for background colour control |
' Second keyword can be BG for background colour control |
||
' The COLOR command also accepts keywords of NORMAL, INTENSE, INVERSE, RESET</ |
' The COLOR command also accepts keywords of NORMAL, INTENSE, INVERSE, RESET</syntaxhighlight> |
||
=={{header|BASIC}}== |
=={{header|BASIC}}== |
||
Line 293: | Line 293: | ||
{{works with|QBasic}} |
{{works with|QBasic}} |
||
< |
<syntaxhighlight lang="qbasic">FOR n = 1 TO 15 |
||
COLOR n |
COLOR n |
||
PRINT "Rosetta Code" |
PRINT "Rosetta Code" |
||
NEXT</ |
NEXT</syntaxhighlight> |
||
==={{header|Commodore BASIC}}=== |
==={{header|Commodore BASIC}}=== |
||
Line 306: | Line 306: | ||
Eight (8) colors available. |
Eight (8) colors available. |
||
< |
<syntaxhighlight lang="gwbasic">10 print chr$(147) |
||
20 for i=0 to 7 |
20 for i=0 to 7 |
||
30 poke 646,i:print "rosetta code!" |
30 poke 646,i:print "rosetta code!" |
||
40 next i |
40 next i |
||
50 poke 646,0:end</ |
50 poke 646,0:end</syntaxhighlight> |
||
====Commodore 64==== |
====Commodore 64==== |
||
Line 316: | Line 316: | ||
Sixteen (16) colors available. This program also works on the rare Commodore CBM-II P500, which featured the same VIC-II video chip as the Commodore 64. Simply change the memory address from 646 to 236. |
Sixteen (16) colors available. This program also works on the rare Commodore CBM-II P500, which featured the same VIC-II video chip as the Commodore 64. Simply change the memory address from 646 to 236. |
||
< |
<syntaxhighlight lang="gwbasic">10 print chr$(147) |
||
20 for i=0 to 15 |
20 for i=0 to 15 |
||
30 poke 646,i:print "rosetta code!" |
30 poke 646,i:print "rosetta code!" |
||
40 next |
40 next |
||
50 poke 646,14:end</ |
50 poke 646,14:end</syntaxhighlight> |
||
====Commodore 128==== |
====Commodore 128==== |
||
Line 326: | Line 326: | ||
Outputs 16 colors to both the 80-column and 40-column displays, however the palette between the two displays is not exactly the same. |
Outputs 16 colors to both the 80-column and 40-column displays, however the palette between the two displays is not exactly the same. |
||
< |
<syntaxhighlight lang="gwbasic">10 graphic 5,1 |
||
20 for i=0 to 15 |
20 for i=0 to 15 |
||
30 color 5,i:print "rosetta code!" |
30 color 5,i:print "rosetta code!" |
||
Line 334: | Line 334: | ||
70 color 5,i:print "rosetta code!" |
70 color 5,i:print "rosetta code!" |
||
80 next i |
80 next i |
||
90 end</ |
90 end</syntaxhighlight> |
||
====Commodore Plus/4==== |
====Commodore Plus/4==== |
||
Line 340: | Line 340: | ||
This machine is capable of 8 luminance values for 15 colors, plus black, yielding a total of 121 unique colors. |
This machine is capable of 8 luminance values for 15 colors, plus black, yielding a total of 121 unique colors. |
||
< |
<syntaxhighlight lang="gwbasic">10 graphic 0,1 |
||
20 for c=1 to 16 |
20 for c=1 to 16 |
||
30 for b=0 to 7 |
30 for b=0 to 7 |
||
40 color 1,c,b:print "rosetta code!" |
40 color 1,c,b:print "rosetta code!" |
||
50 next b:next c |
50 next b:next c |
||
60 color 1,0:end</ |
60 color 1,0:end</syntaxhighlight> |
||
=={{header|BBC BASIC}}== |
=={{header|BBC BASIC}}== |
||
< |
<syntaxhighlight lang="bbcbasic"> FOR col% = 0 TO 14 |
||
COLOUR col% : REM foreground |
COLOUR col% : REM foreground |
||
COLOUR 128+(15-col%) : REM background |
COLOUR 128+(15-col%) : REM background |
||
PRINT "Rosetta Code" |
PRINT "Rosetta Code" |
||
NEXT</ |
NEXT</syntaxhighlight> |
||
[[File:coloured_text_bbc.gif]] |
[[File:coloured_text_bbc.gif]] |
||
=={{header|Befunge}}== |
=={{header|Befunge}}== |
||
Assuming a terminal with support for ANSI escape sequences, this displays the words ''Red'', ''Green'', ''Blue'', ''Magenta'', ''Cyan'' and ''Yellow'', using the corresponding text colour and a "complementary" background colour. |
Assuming a terminal with support for ANSI escape sequences, this displays the words ''Red'', ''Green'', ''Blue'', ''Magenta'', ''Cyan'' and ''Yellow'', using the corresponding text colour and a "complementary" background colour. |
||
< |
<syntaxhighlight lang="befunge"><v0"1Red"0"2Green"0"4Blue"0"5Magenta"0"6Cyan"0"3Yellow"00 |
||
,_:!#@_:"m3["39*,,,\,,"m4["39*,,,\"g"\->:#,_55+"m["39*,,,</ |
,_:!#@_:"m3["39*,,,\,,"m4["39*,,,\"g"\->:#,_55+"m["39*,,,</syntaxhighlight> |
||
=={{header|C}}== |
=={{header|C}}== |
||
On a terminal that understands ANSI escape sequences, such as color xterm, this shows you some annoyingly huge, annoyingly colorful tables. |
On a terminal that understands ANSI escape sequences, such as color xterm, this shows you some annoyingly huge, annoyingly colorful tables. |
||
< |
<syntaxhighlight lang="c">#include <stdio.h> |
||
void table(const char *title, const char *mode) |
void table(const char *title, const char *mode) |
||
Line 391: | Line 391: | ||
table("inverted ( ESC[7m )", "7;"); |
table("inverted ( ESC[7m )", "7;"); |
||
return 0; |
return 0; |
||
}</ |
}</syntaxhighlight> |
||
=={{header|C sharp|C#}}== |
=={{header|C sharp|C#}}== |
||
Line 398: | Line 398: | ||
Visual Studios Intellisense will list all available colours. |
Visual Studios Intellisense will list all available colours. |
||
< |
<syntaxhighlight lang="csharp"> |
||
static void Main(string[] args) |
static void Main(string[] args) |
||
{ |
{ |
||
Line 411: | Line 411: | ||
Console.ReadKey(); |
Console.ReadKey(); |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|COBOL}}== |
=={{header|COBOL}}== |
||
Line 417: | Line 417: | ||
{{works with|OpenCOBOL}} |
{{works with|OpenCOBOL}} |
||
<!-- I couldn't find a way to upload a picture of the output. The 'Upload File' option isn't there for me. Would someone else mind uploading it? --> |
<!-- I couldn't find a way to upload a picture of the output. The 'Upload File' option isn't there for me. Would someone else mind uploading it? --> |
||
< |
<syntaxhighlight lang="cobol">*> Apologies for the repetitiveness. |
||
IDENTIFICATION DIVISION. |
IDENTIFICATION DIVISION. |
||
PROGRAM-ID. coloured-text. |
PROGRAM-ID. coloured-text. |
||
Line 505: | Line 505: | ||
GOBACK |
GOBACK |
||
.</ |
.</syntaxhighlight> |
||
=={{header|Common Lisp}}== |
=={{header|Common Lisp}}== |
||
==={{header|ncurses}}=== |
==={{header|ncurses}}=== |
||
To interface the ncurses C library from Lisp, the ''croatoan'' library is used. |
To interface the ncurses C library from Lisp, the ''croatoan'' library is used. |
||
< |
<syntaxhighlight lang="lisp">(defun coloured-text () |
||
(with-screen (scr :input-blocking t :input-echoing nil :cursor-visible nil) |
(with-screen (scr :input-blocking t :input-echoing nil :cursor-visible nil) |
||
(dolist (i '(:red :green :yellow :blue :magenta :cyan :white)) |
(dolist (i '(:red :green :yellow :blue :magenta :cyan :white)) |
||
Line 516: | Line 516: | ||
(refresh scr) |
(refresh scr) |
||
;; wait for keypress |
;; wait for keypress |
||
(get-char scr)))</ |
(get-char scr)))</syntaxhighlight> |
||
=={{header|D}}== |
=={{header|D}}== |
||
For terminals that understand color escape sequences: |
For terminals that understand color escape sequences: |
||
< |
<syntaxhighlight lang="d">import |
||
std.conv, |
std.conv, |
||
std.stdio; |
std.stdio; |
||
Line 572: | Line 572: | ||
"Hello, world!".color(c).writeln; |
"Hello, world!".color(c).writeln; |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Dc}}== |
=={{header|Dc}}== |
||
Line 578: | Line 578: | ||
Regarding blinking... may be I add that later. |
Regarding blinking... may be I add that later. |
||
< |
<syntaxhighlight lang="dc">## after PARI/GP |
||
# C: for( initcode ; condcode ; incrcode ) {body} |
# C: for( initcode ; condcode ; incrcode ) {body} |
||
Line 610: | Line 610: | ||
] lFx ## for b |
] lFx ## for b |
||
AP |
AP |
||
] lFx ## for f</ |
] lFx ## for f</syntaxhighlight> |
||
=={{header|F_Sharp|F#}}== |
=={{header|F_Sharp|F#}}== |
||
{{trans|C#}} |
{{trans|C#}} |
||
< |
<syntaxhighlight lang="fsharp">open System |
||
Console.ForegroundColor <- ConsoleColor.Red |
Console.ForegroundColor <- ConsoleColor.Red |
||
Line 630: | Line 630: | ||
Console.ResetColor() |
Console.ResetColor() |
||
Console.WriteLine("Back to normal") |
Console.WriteLine("Back to normal") |
||
Console.ReadKey()</ |
Console.ReadKey()</syntaxhighlight> |
||
=={{header|Forth}}== |
=={{header|Forth}}== |
||
ANS/ISO Forth does not specify how screen color is handled. This demonstration creates a set of commands for an ANSI terminal that give the programmer control of text color. |
ANS/ISO Forth does not specify how screen color is handled. This demonstration creates a set of commands for an ANSI terminal that give the programmer control of text color. |
||
< |
<syntaxhighlight lang="forth">( ANSI terminal control lexicon Colored Text) |
||
DECIMAL |
DECIMAL |
||
( support routines) |
( support routines) |
||
Line 654: | Line 654: | ||
: TEXT ( color ) 30 + ATTR ; ( use: YELLOW TEXT ) |
: TEXT ( color ) 30 + ATTR ; ( use: YELLOW TEXT ) |
||
: BACKGROUND ( color ) 40 + ATTR ; ( use: BLUE BACKGROUND ) |
: BACKGROUND ( color ) 40 + ATTR ; ( use: BLUE BACKGROUND ) |
||
</ |
</syntaxhighlight> |
||
With the code loaded into Forth, color control is a part of the language |
With the code loaded into Forth, color control is a part of the language |
||
< |
<syntaxhighlight lang="forth">WHITE TEXT BLUE BACKGROUND ok |
||
BLUE TEXT BOLD ATTR ok |
BLUE TEXT BOLD ATTR ok |
||
CYAN TEXT ok</ |
CYAN TEXT ok</syntaxhighlight> |
||
=={{header|Fortran}}== |
=={{header|Fortran}}== |
||
< |
<syntaxhighlight lang="fortran">! Standard Fortran, should work with any modern compiler (tested gfortran 9) |
||
! and ANSI supporting terminal (tested Linux, various terminals). |
! and ANSI supporting terminal (tested Linux, various terminals). |
||
program coloured_terminal_text |
program coloured_terminal_text |
||
Line 697: | Line 697: | ||
write(ERROR_UNIT, '(a)') background_green // 'Bonus Round' // reset |
write(ERROR_UNIT, '(a)') background_green // 'Bonus Round' // reset |
||
end program coloured_terminal_text</ |
end program coloured_terminal_text</syntaxhighlight> |
||
===Intel Fortran on Windows=== |
===Intel Fortran on Windows=== |
||
Using Windows API functions, see for instance '''[https://msdn.microsoft.com/en-us/library/ms686047.aspx SetConsoleTextAttribute]''' in MSDN. On can set foreground and background colors, available attributes are [https://msdn.microsoft.com/en-us/library/ms682088.aspx here]. It's not possible to cause blinking without using a thread to change attributes at time intervals. The program reverts the console attributes to the preceding values. Failing to do that, it is still possible to reset console colors with the '''color''' command, without arguments. |
Using Windows API functions, see for instance '''[https://msdn.microsoft.com/en-us/library/ms686047.aspx SetConsoleTextAttribute]''' in MSDN. On can set foreground and background colors, available attributes are [https://msdn.microsoft.com/en-us/library/ms682088.aspx here]. It's not possible to cause blinking without using a thread to change attributes at time intervals. The program reverts the console attributes to the preceding values. Failing to do that, it is still possible to reset console colors with the '''color''' command, without arguments. |
||
< |
<syntaxhighlight lang="fortran">program textcolor |
||
use kernel32 |
use kernel32 |
||
implicit none |
implicit none |
||
Line 721: | Line 721: | ||
print "(A)", "This is a red string." |
print "(A)", "This is a red string." |
||
q = SetConsoleTextAttribute(hConsole, csbi%wAttributes) |
q = SetConsoleTextAttribute(hConsole, csbi%wAttributes) |
||
end program</ |
end program</syntaxhighlight> |
||
=={{header|FreeBASIC}}== |
=={{header|FreeBASIC}}== |
||
Line 727: | Line 727: | ||
Draws a 4x4 grid of coloured text with coloured backgrounds. Auto-blinking text isn't supported. |
Draws a 4x4 grid of coloured text with coloured backgrounds. Auto-blinking text isn't supported. |
||
< |
<syntaxhighlight lang="freebasic">for i as uinteger = 0 to 15 |
||
color i, 15-i |
color i, 15-i |
||
print "Colour "+str(i), |
print "Colour "+str(i), |
||
if i mod 4 = 3 then color 0,0: print |
if i mod 4 = 3 then color 0,0: print |
||
next i</ |
next i</syntaxhighlight> |
||
=={{header|FunL}}== |
=={{header|FunL}}== |
||
< |
<syntaxhighlight lang="funl">import console.* |
||
bold() |
bold() |
||
Line 746: | Line 746: | ||
reset() |
reset() |
||
println( RED + 'Red', GREEN + 'Green', BLUE + 'Blue', MAGENTA + 'Magenta', CYAN + 'Cyan', YELLOW + 'Yellow' + RESET )</ |
println( RED + 'Red', GREEN + 'Green', BLUE + 'Blue', MAGENTA + 'Magenta', CYAN + 'Cyan', YELLOW + 'Yellow' + RESET )</syntaxhighlight> |
||
=={{header|Go}}== |
=={{header|Go}}== |
||
===External command=== |
===External command=== |
||
< |
<syntaxhighlight lang="go">package main |
||
import ( |
import ( |
||
Line 777: | Line 777: | ||
cmd.Stdout = os.Stdout |
cmd.Stdout = os.Stdout |
||
cmd.Run() |
cmd.Run() |
||
}</ |
}</syntaxhighlight> |
||
Optional tasks |
Optional tasks |
||
< |
<syntaxhighlight lang="go">package main |
||
import ( |
import ( |
||
Line 813: | Line 813: | ||
cmd.Stdout = os.Stdout |
cmd.Stdout = os.Stdout |
||
return cmd.Run() |
return cmd.Run() |
||
}</ |
}</syntaxhighlight> |
||
===ANSI escape codes=== |
===ANSI escape codes=== |
||
< |
<syntaxhighlight lang="go">package main |
||
import "fmt" |
import "fmt" |
||
Line 823: | Line 823: | ||
fmt.Println("\033[32mGreen") |
fmt.Println("\033[32mGreen") |
||
fmt.Println("\033[34mBlue") |
fmt.Println("\033[34mBlue") |
||
}</ |
}</syntaxhighlight> |
||
Optional tasks |
Optional tasks |
||
< |
<syntaxhighlight lang="go">package main |
||
import "fmt" |
import "fmt" |
||
Line 835: | Line 835: | ||
fmt.Println(" Blinking Red ") |
fmt.Println(" Blinking Red ") |
||
fmt.Print("\033[25;40m") // blink off, black background |
fmt.Print("\033[25;40m") // blink off, black background |
||
}</ |
}</syntaxhighlight> |
||
===Ncurses=== |
===Ncurses=== |
||
{{libheader|Curses}} |
{{libheader|Curses}} |
||
< |
<syntaxhighlight lang="go">package main |
||
import ( |
import ( |
||
Line 868: | Line 868: | ||
s.Println("Blue") |
s.Println("Blue") |
||
s.GetChar() |
s.GetChar() |
||
}</ |
}</syntaxhighlight> |
||
Optional tasks |
Optional tasks |
||
< |
<syntaxhighlight lang="go">package main |
||
import ( |
import ( |
||
Line 899: | Line 899: | ||
s.Print(" Blinking Red ") |
s.Print(" Blinking Red ") |
||
s.GetChar() |
s.GetChar() |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Golo}}== |
=={{header|Golo}}== |
||
< |
<syntaxhighlight lang="golo">#!/usr/bin/env golosh |
||
---- |
---- |
||
This module demonstrates terminal colours. |
This module demonstrates terminal colours. |
||
Line 939: | Line 939: | ||
} |
} |
||
println("") |
println("") |
||
}</ |
}</syntaxhighlight> |
||
=={{header|GW-BASIC}}== |
=={{header|GW-BASIC}}== |
||
Sixteen foreground colours, in non-flashing and flashing, and eight background colours. |
Sixteen foreground colours, in non-flashing and flashing, and eight background colours. |
||
< |
<syntaxhighlight lang="gwbasic">10 FOR I = 0 TO 31 |
||
20 COLOR I, 7 - (I MOD 8) |
20 COLOR I, 7 - (I MOD 8) |
||
30 PRINT I; |
30 PRINT I; |
||
40 IF I MOD 4 = 3 THEN COLOR 7, 0 : PRINT |
40 IF I MOD 4 = 3 THEN COLOR 7, 0 : PRINT |
||
50 NEXT I</ |
50 NEXT I</syntaxhighlight> |
||
=={{header|Haskell}}== |
=={{header|Haskell}}== |
||
Line 956: | Line 956: | ||
{{Works with|ansi-terminal|0.5.5.1}} |
{{Works with|ansi-terminal|0.5.5.1}} |
||
< |
<syntaxhighlight lang="haskell">#!/usr/bin/runhaskell |
||
import System.Console.ANSI |
import System.Console.ANSI |
||
Line 972: | Line 972: | ||
colorStrLn Vivid Green Dull Black "This is green on black." |
colorStrLn Vivid Green Dull Black "This is green on black." |
||
colorStrLn Vivid Yellow Dull Black "This is yellow on black." |
colorStrLn Vivid Yellow Dull Black "This is yellow on black." |
||
colorStrLn Dull Black Vivid Blue "This is black on light blue."</ |
colorStrLn Dull Black Vivid Blue "This is black on light blue."</syntaxhighlight> |
||
=={{header|J}}== |
=={{header|J}}== |
||
Line 979: | Line 979: | ||
<!--WARNING--> |
<!--WARNING--> |
||
Quite different from the fixed c solution, we flexibly construct character vectors that combine various functions. This code constructs two such sequences, DB is useful to write vertical text, and the noun J output to the terminal draws to the extent of my artistic ability the J icon at the relative position. |
Quite different from the fixed c solution, we flexibly construct character vectors that combine various functions. This code constructs two such sequences, DB is useful to write vertical text, and the noun J output to the terminal draws to the extent of my artistic ability the J icon at the relative position. |
||
< |
<syntaxhighlight lang="j">NB. relies on an vt100 terminal |
||
CSI=: 27 91 { a. |
CSI=: 27 91 { a. |
||
Line 1,007: | Line 1,007: | ||
J=: J , (backward 5),'\____/' |
J=: J , (backward 5),'\____/' |
||
smoutput(color BLACK),(clear 2),(move 8 22),J,(WHITE color BLACK),(downward 2) |
smoutput(color BLACK),(clear 2),(move 8 22),J,(WHITE color BLACK),(downward 2) |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
Julia has rudimentary color terminal support built-in. Slightly more elaborate color and effect support is available with the <code>AnsiColor</code> package. |
Julia has rudimentary color terminal support built-in. Slightly more elaborate color and effect support is available with the <code>AnsiColor</code> package. |
||
<syntaxhighlight lang="julia"> |
|||
<lang Julia> |
|||
using AnsiColor |
using AnsiColor |
||
Line 1,046: | Line 1,046: | ||
println("This terminal appears not to support color.") |
println("This terminal appears not to support color.") |
||
end |
end |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
Line 1,062: | Line 1,062: | ||
=={{header|Kotlin}}== |
=={{header|Kotlin}}== |
||
{{Works with|Ubuntu|14.04}} |
{{Works with|Ubuntu|14.04}} |
||
< |
<syntaxhighlight lang="scala">// version 1.1.2 |
||
const val ESC = "\u001B" |
const val ESC = "\u001B" |
||
Line 1,087: | Line 1,087: | ||
} |
} |
||
println(WHITE) // set foreground color to normal white |
println(WHITE) // set foreground color to normal white |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Lasso}}== |
=={{header|Lasso}}== |
||
< |
<syntaxhighlight lang="lasso">#!/usr/bin/lasso9 |
||
define ec(code::string) => { |
define ec(code::string) => { |
||
Line 1,121: | Line 1,121: | ||
stdoutnl('So this is the Rosetta Code!') |
stdoutnl('So this is the Rosetta Code!') |
||
stdout( ec('normal')) |
stdout( ec('normal')) |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Locomotive Basic}}== |
=={{header|Locomotive Basic}}== |
||
< |
<syntaxhighlight lang="locobasic">10 mode 1:defint a-z |
||
20 print "Mode 1 (4 colors):" |
20 print "Mode 1 (4 colors):" |
||
30 for y=0 to 3 |
30 for y=0 to 3 |
||
Line 1,159: | Line 1,159: | ||
330 print "*End of color demo*" |
330 print "*End of color demo*" |
||
340 locate 1,25:print "<Press any key>";:call &bb06 |
340 locate 1,25:print "<Press any key>";:call &bb06 |
||
350 mode 1</ |
350 mode 1</syntaxhighlight> |
||
=={{header|Lua}}== |
=={{header|Lua}}== |
||
Assumes an ansi-capable terminal.. |
Assumes an ansi-capable terminal.. |
||
< |
<syntaxhighlight lang="lua">print("Normal \027[1mBold\027[0m \027[4mUnderline\027[0m \027[7mInverse\027[0m") |
||
colors = { 30,31,32,33,34,35,36,37,90,91,92,93,94,95,96,97 } |
colors = { 30,31,32,33,34,35,36,37,90,91,92,93,94,95,96,97 } |
||
for _,bg in ipairs(colors) do |
for _,bg in ipairs(colors) do |
||
Line 1,170: | Line 1,170: | ||
end |
end |
||
print("\027[0m") -- be nice, reset |
print("\027[0m") -- be nice, reset |
||
end</ |
end</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
''(image upload is broken)'' |
''(image upload is broken)'' |
||
Line 1,176: | Line 1,176: | ||
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
||
Delegating to tput on terminal enabled OS(Mac Os, Linux) |
Delegating to tput on terminal enabled OS(Mac Os, Linux) |
||
< |
<syntaxhighlight lang="mathematica">Run["tput setaf 1"]; Print["Coloured Text"]; |
||
Run["tput setaf 2"]; Print["Coloured Text"]; |
Run["tput setaf 2"]; Print["Coloured Text"]; |
||
Run["tput setaf 3"]; Print["Coloured Text"]</ |
Run["tput setaf 3"]; Print["Coloured Text"]</syntaxhighlight> |
||
[[File:colouredtextmma.png]] |
[[File:colouredtextmma.png]] |
||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
< |
<syntaxhighlight lang="nim">import Terminal |
||
setForegroundColor(fgRed) |
setForegroundColor(fgRed) |
||
echo "FATAL ERROR! Cannot write to /boot/vmlinuz-3.2.0-33-generic" |
echo "FATAL ERROR! Cannot write to /boot/vmlinuz-3.2.0-33-generic" |
||
Line 1,204: | Line 1,204: | ||
setForegroundColor(fgMagenta) |
setForegroundColor(fgMagenta) |
||
echo "RosettaCode!"</ |
echo "RosettaCode!"</syntaxhighlight> |
||
=={{header|OCaml}}== |
=={{header|OCaml}}== |
||
Line 1,210: | Line 1,210: | ||
Using the library [http://forge.ocamlcore.org/projects/ansiterminal/ ANSITerminal] in the interactive loop: |
Using the library [http://forge.ocamlcore.org/projects/ansiterminal/ ANSITerminal] in the interactive loop: |
||
< |
<syntaxhighlight lang="ocaml">$ ocaml unix.cma -I +ANSITerminal ANSITerminal.cma |
||
# open ANSITerminal ;; |
# open ANSITerminal ;; |
||
# print_string [cyan; on_blue] "Hello\n" ;; |
# print_string [cyan; on_blue] "Hello\n" ;; |
||
Hello |
Hello |
||
- : unit = ()</ |
- : unit = ()</syntaxhighlight> |
||
=={{header|ooRexx}}== |
=={{header|ooRexx}}== |
||
This program is based on the shell script in the Bash Prompt HowTo at |
This program is based on the shell script in the Bash Prompt HowTo at |
||
http://www.tldp.org/, by Giles Orr. It uses object-oriented features of Open Object Rexx. |
http://www.tldp.org/, by Giles Orr. It uses object-oriented features of Open Object Rexx. |
||
<syntaxhighlight lang="rexx"> |
|||
<lang REXX> |
|||
#!/usr/bin/rexx |
#!/usr/bin/rexx |
||
/*.----------------------------------------------------------------------.*/ |
/*.----------------------------------------------------------------------.*/ |
||
Line 1,350: | Line 1,350: | ||
end |
end |
||
return |
return |
||
</syntaxhighlight> |
|||
</lang> |
|||
This is what the output looks like: |
This is what the output looks like: |
||
Line 1,359: | Line 1,359: | ||
=={{header|PARI/GP}}== |
=={{header|PARI/GP}}== |
||
< |
<syntaxhighlight lang="parigp">for(b=40, 47, for(c=30, 37, printf("\e[%d;%d;1mRosetta Code\e[0m\n", c, b)))</syntaxhighlight> |
||
=={{header|Pascal}}== |
=={{header|Pascal}}== |
||
Line 1,365: | Line 1,365: | ||
The CRT unit allows us to play with the console window, since at least the old Turbo Pascal days. We can clear the screen and specify colors by number or by name, among other tricks. |
The CRT unit allows us to play with the console window, since at least the old Turbo Pascal days. We can clear the screen and specify colors by number or by name, among other tricks. |
||
< |
<syntaxhighlight lang="pascal">program Colorizer; |
||
uses CRT; |
uses CRT; |
||
Line 1,383: | Line 1,383: | ||
TextBackground(White); |
TextBackground(White); |
||
TextColor(Black); |
TextColor(Black); |
||
end.</ |
end.</syntaxhighlight> |
||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
< |
<syntaxhighlight lang="perl">my %colors = ( |
||
red => "\e[1;31m", |
red => "\e[1;31m", |
||
green => "\e[1;32m", |
green => "\e[1;32m", |
||
Line 1,407: | Line 1,407: | ||
say colored('MAGENTA', 'bold magenta'); |
say colored('MAGENTA', 'bold magenta'); |
||
say colored('CYAN ON RED', 'bold cyan on_red'); |
say colored('CYAN ON RED', 'bold cyan on_red'); |
||
say colored('YELLOW', 'bold yellow');</ |
say colored('YELLOW', 'bold yellow');</syntaxhighlight> |
||
< |
<syntaxhighlight lang="perl"> |
||
#ON WINDOWS USING POWERSHELL or WT.EXE |
#ON WINDOWS USING POWERSHELL or WT.EXE |
||
$ForegroundColor = { |
$ForegroundColor = { |
||
Line 1,453: | Line 1,453: | ||
print "White On Blue"; |
print "White On Blue"; |
||
print $ClearColors; |
print $ClearColors; |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
Line 1,461: | Line 1,461: | ||
BRIGHT_BLUE, BRIGHT_GREEN, BRIGHT_CYAN, BRIGHT_RED, BRIGHT_MAGENTA, |
BRIGHT_BLUE, BRIGHT_GREEN, BRIGHT_CYAN, BRIGHT_RED, BRIGHT_MAGENTA, |
||
YELLOW, BRIGHT_WHITE |
YELLOW, BRIGHT_WHITE |
||
<!--< |
<!--<syntaxhighlight lang="phix">(phixonline)--> |
||
<span style="color: #000080;font-style:italic;">-- |
<span style="color: #000080;font-style:italic;">-- |
||
-- demo\rosetta\Coloured_text.exw |
-- demo\rosetta\Coloured_text.exw |
||
Line 1,485: | Line 1,485: | ||
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\n\npress enter to exit"</span><span style="color: #0000FF;">)</span> |
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\n\npress enter to exit"</span><span style="color: #0000FF;">)</span> |
||
<span style="color: #0000FF;">{}</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">wait_key</span><span style="color: #0000FF;">()</span> |
<span style="color: #0000FF;">{}</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">wait_key</span><span style="color: #0000FF;">()</span> |
||
<!--</ |
<!--</syntaxhighlight>--> |
||
Output matches PureBasic |
Output matches PureBasic |
||
=={{header|PicoLisp}}== |
=={{header|PicoLisp}}== |
||
{{trans|UNIX Shell}} |
{{trans|UNIX Shell}} |
||
< |
<syntaxhighlight lang="picolisp">(unless (member (sys "TERM") '("linux" "xterm" "xterm-color" "xterm-256color" "rxvt")) |
||
(quit "This application requires a colour terminal") ) |
(quit "This application requires a colour terminal") ) |
||
Line 1,504: | Line 1,504: | ||
(call 'tput 'sgr0) # reset |
(call 'tput 'sgr0) # reset |
||
(prinl)</ |
(prinl)</syntaxhighlight> |
||
=={{header|PowerShell}}== |
=={{header|PowerShell}}== |
||
<syntaxhighlight lang="powershell"> |
|||
<lang PowerShell> |
|||
foreach ($color in [enum]::GetValues([System.ConsoleColor])) {Write-Host "$color color." -ForegroundColor $color} |
foreach ($color in [enum]::GetValues([System.ConsoleColor])) {Write-Host "$color color." -ForegroundColor $color} |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|PureBasic}}== |
=={{header|PureBasic}}== |
||
< |
<syntaxhighlight lang="purebasic">If OpenConsole() |
||
PrintN("Background color# 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15") |
PrintN("Background color# 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15") |
||
PrintN(" -----------------------------------------------") |
PrintN(" -----------------------------------------------") |
||
Line 1,531: | Line 1,531: | ||
Print(#CRLF$ + #CRLF$ + "Press ENTER to exit"): Input() |
Print(#CRLF$ + #CRLF$ + "Press ENTER to exit"): Input() |
||
CloseConsole() |
CloseConsole() |
||
EndIf</ |
EndIf</syntaxhighlight> |
||
[[Image:terminal_control,colored_text.png]] |
[[Image:terminal_control,colored_text.png]] |
||
=={{header|Python}}== |
=={{header|Python}}== |
||
{{libheader|colorama}} |
{{libheader|colorama}} |
||
< |
<syntaxhighlight lang="python"> |
||
from colorama import init, Fore, Back, Style |
from colorama import init, Fore, Back, Style |
||
init(autoreset=True) |
init(autoreset=True) |
||
Line 1,548: | Line 1,548: | ||
print Fore.MAGENTA + "Rosetta Code!" |
print Fore.MAGENTA + "Rosetta Code!" |
||
print Back.YELLOW + Fore.BLUE + Style.BRIGHT + " " * 40 + " == Good Bye!" |
print Back.YELLOW + Fore.BLUE + Style.BRIGHT + " " * 40 + " == Good Bye!" |
||
</syntaxhighlight> |
|||
</lang> |
|||
This is a windows only solution without colorama |
This is a windows only solution without colorama |
||
< |
<syntaxhighlight lang="python"> |
||
from ctypes import * |
from ctypes import * |
||
Line 1,568: | Line 1,568: | ||
color(7) |
color(7) |
||
raw_input("holding cmd") |
raw_input("holding cmd") |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Racket}}== |
=={{header|Racket}}== |
||
{{trans|Tcl}} |
{{trans|Tcl}} |
||
< |
<syntaxhighlight lang="racket"> |
||
#lang racket |
#lang racket |
||
Line 1,597: | Line 1,597: | ||
(reset)) |
(reset)) |
||
(displayln "Steady only")) |
(displayln "Steady only")) |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Raku}}== |
=={{header|Raku}}== |
||
(formerly Perl 6) |
(formerly Perl 6) |
||
<lang |
<syntaxhighlight lang="raku" line>use Terminal::ANSIColor; |
||
say colored('RED ON WHITE', 'bold red on_white'); |
say colored('RED ON WHITE', 'bold red on_white'); |
||
Line 1,608: | Line 1,608: | ||
say colored('MAGENTA', 'bold magenta'); |
say colored('MAGENTA', 'bold magenta'); |
||
say colored('CYAN ON RED', 'bold cyan on_red'); |
say colored('CYAN ON RED', 'bold cyan on_red'); |
||
say colored('YELLOW', 'bold yellow');</ |
say colored('YELLOW', 'bold yellow');</syntaxhighlight> |
||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
Line 1,632: | Line 1,632: | ||
<br><br>The program displays 16 lines, each of a different color with text stating the color of the text. |
<br><br>The program displays 16 lines, each of a different color with text stating the color of the text. |
||
<br>(The black text, of course, is essentially invisible as the background is also black.) |
<br>(The black text, of course, is essentially invisible as the background is also black.) |
||
< |
<syntaxhighlight lang="rexx">/*REXX program to display sixteen lines, each of a different color. */ |
||
parse arg !; if !all() then exit /*exit if documentation specified*/ |
parse arg !; if !all() then exit /*exit if documentation specified*/ |
||
if \!dos & \!os2 then exit /*if this isn't DOS, then exit. */ |
if \!dos & \!os2 then exit /*if this isn't DOS, then exit. */ |
||
Line 1,665: | Line 1,665: | ||
!rex:parse upper version !ver !vernum !verdate .;!brexx='BY'==!vernum;!kexx='KEXX'==!ver;!pcrexx='REXX/PERSONAL'==!ver|'REXX/PC'==!ver;!r4='REXX-R4'==!ver;!regina='REXX-REGINA'==left(!ver,11);!roo='REXX-ROO'==!ver;call !env;return |
!rex:parse upper version !ver !vernum !verdate .;!brexx='BY'==!vernum;!kexx='KEXX'==!ver;!pcrexx='REXX/PERSONAL'==!ver|'REXX/PC'==!ver;!r4='REXX-R4'==!ver;!regina='REXX-REGINA'==left(!ver,11);!roo='REXX-ROO'==!ver;call !env;return |
||
!sys:!cms=!sys=='CMS';!os2=!sys=='OS2';!tso=!sys=='TSO'|!sys=='MVS';!vse=!sys=='VSE';!dos=pos('DOS',!sys)\==0|pos('WIN',!sys)\==0|!sys=='CMD';call !rex;return |
!sys:!cms=!sys=='CMS';!os2=!sys=='OS2';!tso=!sys=='TSO'|!sys=='MVS';!vse=!sys=='VSE';!dos=pos('DOS',!sys)\==0|pos('WIN',!sys)\==0|!sys=='CMD';call !rex;return |
||
!var:call !fid;if !kexx then return space(dosenv(arg(1)));return space(value(arg(1),,!env))</ |
!var:call !fid;if !kexx then return space(dosenv(arg(1)));return space(value(arg(1),,!env))</syntaxhighlight> |
||
=={{header|Ring}}== |
=={{header|Ring}}== |
||
< |
<syntaxhighlight lang="ring"> |
||
# Project : Terminal control/Coloured text |
# Project : Terminal control/Coloured text |
||
Line 1,680: | Line 1,680: | ||
cc_print(forecolor | CC_BG_WHITE, "Rosetta Code" + nl) |
cc_print(forecolor | CC_BG_WHITE, "Rosetta Code" + nl) |
||
next |
next |
||
</syntaxhighlight> |
|||
</lang> |
|||
Output image: |
Output image: |
||
Line 1,689: | Line 1,689: | ||
{{libheader|colored}} |
{{libheader|colored}} |
||
< |
<syntaxhighlight lang="ruby">#!/usr/bin/ruby -w |
||
require 'rubygems' |
require 'rubygems' |
||
require 'colored' |
require 'colored' |
||
Line 1,712: | Line 1,712: | ||
puts 'white on green'.white_on_green |
puts 'white on green'.white_on_green |
||
puts 'white on magenta'.white_on_magenta |
puts 'white on magenta'.white_on_magenta |
||
puts 'white on red'.white_on_red</ |
puts 'white on red'.white_on_red</syntaxhighlight> |
||
[[File:Colored-text-ruby.png]] |
[[File:Colored-text-ruby.png]] |
||
Line 1,718: | Line 1,718: | ||
=={{header|Rust}}== |
=={{header|Rust}}== |
||
< |
<syntaxhighlight lang="rust">const ESC: &str = "\x1B["; |
||
const RESET: &str = "\x1B[0m"; |
const RESET: &str = "\x1B[0m"; |
||
Line 1,740: | Line 1,740: | ||
println!("{}", RESET); |
println!("{}", RESET); |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Scala}}== |
=={{header|Scala}}== |
||
===Scala idiom (Functional Programming)=== |
===Scala idiom (Functional Programming)=== |
||
{{Works with|Ubuntu|14.04}} |
{{Works with|Ubuntu|14.04}} |
||
< |
<syntaxhighlight lang="scala">object ColouredText extends App { |
||
val ESC = "\u001B" |
val ESC = "\u001B" |
||
val (normal, bold, blink, black, white) = |
val (normal, bold, blink, black, white) = |
||
Line 1,769: | Line 1,769: | ||
println(white) // set foreground color to normal white |
println(white) // set foreground color to normal white |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Sidef}}== |
=={{header|Sidef}}== |
||
{{trans|Raku}} |
{{trans|Raku}} |
||
< |
<syntaxhighlight lang="ruby">var a = frequire('Term::ANSIColor'); |
||
say a.colored('RED ON WHITE', 'bold red on_white'); |
say a.colored('RED ON WHITE', 'bold red on_white'); |
||
Line 1,780: | Line 1,780: | ||
say a.colored('MAGENTA', 'bold magenta'); |
say a.colored('MAGENTA', 'bold magenta'); |
||
say a.colored('CYAN ON RED', 'bold cyan on_red'); |
say a.colored('CYAN ON RED', 'bold cyan on_red'); |
||
say a.colored('YELLOW', 'bold yellow');</ |
say a.colored('YELLOW', 'bold yellow');</syntaxhighlight> |
||
=={{header|Tcl}}== |
=={{header|Tcl}}== |
||
This only works on Unix terminals as it delegates to the system <tt>tput</tt> command. |
This only works on Unix terminals as it delegates to the system <tt>tput</tt> command. |
||
< |
<syntaxhighlight lang="tcl"># Utility interfaces to the low-level command |
||
proc capability cap {expr {![catch {exec tput -S << $cap}]}} |
proc capability cap {expr {![catch {exec tput -S << $cap}]}} |
||
proc colorterm {} {expr {[capability setaf] && [capability setab]}} |
proc colorterm {} {expr {[capability setaf] && [capability setab]}} |
||
Line 1,809: | Line 1,809: | ||
} else { |
} else { |
||
puts "Steady only" |
puts "Steady only" |
||
}</ |
}</syntaxhighlight> |
||
=={{header|TPP}}== |
=={{header|TPP}}== |
||
< |
<syntaxhighlight lang="tpp">--color red |
||
This is red |
This is red |
||
--color green |
--color green |
||
Line 1,823: | Line 1,823: | ||
This is magenta |
This is magenta |
||
--color yellow |
--color yellow |
||
This is yellow</ |
This is yellow</syntaxhighlight> |
||
=={{header|True BASIC}}== |
=={{header|True BASIC}}== |
||
< |
<syntaxhighlight lang="qbasic">FOR n = 1 TO 15 |
||
SET COLOR n |
SET COLOR n |
||
PRINT "Rosetta Code" |
PRINT "Rosetta Code" |
||
NEXT n |
NEXT n |
||
END</ |
END</syntaxhighlight> |
||
=={{header|UNIX Shell}}== |
=={{header|UNIX Shell}}== |
||
< |
<syntaxhighlight lang="sh">#!/bin/sh |
||
# Check if the terminal supports colour |
# Check if the terminal supports colour |
||
Line 1,877: | Line 1,877: | ||
echo "Flashing text" |
echo "Flashing text" |
||
tput sgr0 # reset everything before exiting</ |
tput sgr0 # reset everything before exiting</syntaxhighlight> |
||
=={{header|Wren}}== |
=={{header|Wren}}== |
||
< |
<syntaxhighlight lang="ecmascript">import "timer" for Timer |
||
var colors = ["Black", "Red", "Green", "Yellow", "Blue", "Magenta", "Cyan", "White"] |
var colors = ["Black", "Red", "Green", "Yellow", "Blue", "Magenta", "Cyan", "White"] |
||
Line 1,897: | Line 1,897: | ||
System.write("\e[0m") // reset all attributes |
System.write("\e[0m") // reset all attributes |
||
System.write("\e[2J") // clear screen to background color |
System.write("\e[2J") // clear screen to background color |
||
System.write("\e[H") // home the cursor</ |
System.write("\e[H") // home the cursor</syntaxhighlight> |
||
=={{header|XPL0}}== |
=={{header|XPL0}}== |
||
Line 1,915: | Line 1,915: | ||
PCs and by simulators, such as DOSBox, on other computers. |
PCs and by simulators, such as DOSBox, on other computers. |
||
< |
<syntaxhighlight lang="xpl0">code ChOut=8, Attrib=69; |
||
def Black, Blue, Green, Cyan, Red, Magenta, Brown, White, \attribute colors |
def Black, Blue, Green, Cyan, Red, Magenta, Brown, White, \attribute colors |
||
Gray, LBlue, LGreen, LCyan, LRed, LMagenta, Yellow, BWhite; \EGA palette |
Gray, LBlue, LGreen, LCyan, LRed, LMagenta, Yellow, BWhite; \EGA palette |
||
Line 1,929: | Line 1,929: | ||
Attrib(Cyan<<4+Black); \black on cyan |
Attrib(Cyan<<4+Black); \black on cyan |
||
ChOut(6,^r); |
ChOut(6,^r); |
||
]</ |
]</syntaxhighlight> |
||
=={{header|zkl}}== |
=={{header|zkl}}== |
||
{{trans|C}} |
{{trans|C}} |
||
Terminal window on Linux, prints tables of colored glyphs. |
Terminal window on Linux, prints tables of colored glyphs. |
||
< |
<syntaxhighlight lang="zkl">fcn table(title,mode){ |
||
println("\n\e[1m%s\e[m\n bg\t fg".fmt(title)); |
println("\n\e[1m%s\e[m\n bg\t fg".fmt(title)); |
||
foreach b in ([40..48].chain([100..107])){ |
foreach b in ([40..48].chain([100..107])){ |
||
Line 1,949: | Line 1,949: | ||
table("underline ( ESC[4m ), support varies", "4;"); |
table("underline ( ESC[4m ), support varies", "4;"); |
||
table("blink ( ESC[5m )", "5;"); |
table("blink ( ESC[5m )", "5;"); |
||
table("inverted ( ESC[7m )", "7;");</ |
table("inverted ( ESC[7m )", "7;");</syntaxhighlight> |
||
=={{header|ZX Spectrum Basic}}== |
=={{header|ZX Spectrum Basic}}== |
||
The ZX Spectrum will always output colour. However if the television is black and white, these will show as various levels of luminence corresponding to the numerical colour value. |
The ZX Spectrum will always output colour. However if the television is black and white, these will show as various levels of luminence corresponding to the numerical colour value. |
||
< |
<syntaxhighlight lang="zxbasic">10 FOR l=0 TO 7 |
||
20 READ c$: REM get our text for display |
20 READ c$: REM get our text for display |
||
30 INK l: REM set the text colour |
30 INK l: REM set the text colour |
||
Line 1,965: | Line 1,965: | ||
110 STOP |
110 STOP |
||
900 DATA "Black","Blue","Red","Magenta","Green","Cyan","Yellow","White"</ |
900 DATA "Black","Blue","Red","Magenta","Green","Cyan","Yellow","White"</syntaxhighlight> |
||
{{omit from|Axe}} |
{{omit from|Axe}} |