Terminal control/Coloured text: Difference between revisions
Content deleted Content added
→{{header|Locomotive Basic}}: add screenshots |
|||
(13 intermediate revisions by 8 users not shown) | |||
Line 13:
* How to cause blinking or flashing (if supported by the terminal)
<br><br>
=={{header|8086 Assembly}}==
{{works with|MS-DOS}}
Prints the letter 'A' to the screen in bright cyan (color 11 in VGA)
<syntaxhighlight lang="asm"> .model small
.stack 1024
.data
.code
start:
mov ax,@data
mov ds,ax
mov ax,@code
mov es,ax
cld ;String functions are set to auto-increment
mov ax,13h ;select 320x200 VGA
int 10h
mov ah,0Eh
mov al,'A' ;select char to print
mov bx,11 ;select color to print it in
int 10h
ExitDOS:
mov ax,4C00h ;return to dos
int 21h
end start</syntaxhighlight>
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
<syntaxhighlight lang="aarch64 assembly">
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program colorterminal64.s */
Line 85 ⟶ 117:
/* for this file see task include a file in language AArch64 assembly */
.include "../includeARM64.inc"
</syntaxhighlight>
<pre>
Program start
Line 97 ⟶ 129:
=={{header|Ada}}==
{{libheader|ANSIAda}}
<
with Ansi;
Line 116 ⟶ 148:
New_Line;
end loop;
end Coloured;</
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi}}
<syntaxhighlight lang="arm assembly">
/* ARM assembly Raspberry PI */
Line 204 ⟶ 236:
bx lr @ return
</syntaxhighlight>
=={{header|Arturo}}==
<
print color #red str
Line 217 ⟶ 249:
print color #cyan str
print color #black str
print color #white str</
=={{header|AutoHotkey}}==
[[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.
<
hConsole := DllCall( "GetStdHandle", int, STDOUT := -11 )
Loop 15
Line 239 ⟶ 271:
return out
return 0
}</
=={{header|BaCon}}==
<
COLOR FG TO BLACK
PRINT "a word"
Line 254 ⟶ 286:
' Other colours include YELLOW, BLUE, MAGENTA, CYAN, WHITE
' Second keyword can be BG for background colour control
' The COLOR command also accepts keywords of NORMAL, INTENSE, INVERSE, RESET</
=={{header|BASIC}}==
Line 261 ⟶ 293:
{{works with|QBasic}}
<
COLOR n
PRINT "Rosetta Code"
NEXT</
==={{header|Commodore BASIC}}===
Line 274 ⟶ 306:
Eight (8) colors available.
<
20 for i=0 to 7
30 poke 646,i:print "rosetta code!"
40 next i
50 poke 646,0:end</
====Commodore 64====
Line 284 ⟶ 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.
<
20 for i=0 to 15
30 poke 646,i:print "rosetta code!"
40 next
50 poke 646,14:end</
====Commodore 128====
Line 294 ⟶ 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.
<
20 for i=0 to 15
30 color 5,i:print "rosetta code!"
Line 302 ⟶ 334:
70 color 5,i:print "rosetta code!"
80 next i
90 end</
====Commodore Plus/4====
Line 308 ⟶ 340:
This machine is capable of 8 luminance values for 15 colors, plus black, yielding a total of 121 unique colors.
<
20 for c=1 to 16
30 for b=0 to 7
40 color 1,c,b:print "rosetta code!"
50 next b:next c
60 color 1,0:end</
=={{header|BBC BASIC}}==
<
COLOUR col% : REM foreground
COLOUR 128+(15-col%) : REM background
PRINT "Rosetta Code"
NEXT</
[[File:coloured_text_bbc.gif]]
=={{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.
<
,_:!#@_:"m3["39*,,,\,,"m4["39*,,,\"g"\->:#,_55+"m["39*,,,</
=={{header|C}}==
On a terminal that understands ANSI escape sequences, such as color xterm, this shows you some annoyingly huge, annoyingly colorful tables.
<
void table(const char *title, const char *mode)
Line 359 ⟶ 391:
table("inverted ( ESC[7m )", "7;");
return 0;
}</
=={{header|C sharp|C#}}==
Line 366 ⟶ 398:
Visual Studios Intellisense will list all available colours.
<
static void Main(string[] args)
{
Line 379 ⟶ 411:
Console.ReadKey();
}
</syntaxhighlight>
=={{header|C++}}==
Coloured text and the background colour can be set using ANSI escape codes.
For a list of these codes see: https://en.wikipedia.org/wiki/ANSI_escape_code.
There are also many useful codes given in the Java example.
<syntaxhighlight lang="c++">
#include <iostream>
int main() {
std::cout << "\033[42m";
std::cout << "\033[4;37m";
std::cout << "Green background with underlined white text" << std::endl;
std::cout << "\033[0m" << std::endl;
std::cout << "\033[0;103m";
std::cout << "\033[1;34m";
std::cout << "Bright yellow background with bold blue text" << std::endl;
std::cout << "\033[0m" << std::endl;
std::cout << "\033[46m";
std::cout << "\033[1;95m";
std::cout << "Cyan background with bold bright magenta text" << std::endl;
std::cout << "\033[0m" << std::endl;
}
</syntaxhighlight>
[[Media:ColouredTextC++.PNG]]
=={{header|COBOL}}==
Line 385 ⟶ 443:
{{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? -->
<
IDENTIFICATION DIVISION.
PROGRAM-ID. coloured-text.
Line 473 ⟶ 531:
GOBACK
.</
=={{header|Common Lisp}}==
==={{header|ncurses}}===
To interface the ncurses C library from Lisp, the ''croatoan'' library is used.
<
(with-screen (scr :input-blocking t :input-echoing nil :cursor-visible nil)
(dolist (i '(:red :green :yellow :blue :magenta :cyan :white))
Line 484 ⟶ 542:
(refresh scr)
;; wait for keypress
(get-char scr)))</
=={{header|D}}==
For terminals that understand color escape sequences:
<
std.conv,
std.stdio;
Line 540 ⟶ 598:
"Hello, world!".color(c).writeln;
}
}</
=={{header|Dc}}==
Line 546 ⟶ 604:
Regarding blinking... may be I add that later.
<
# C: for( initcode ; condcode ; incrcode ) {body}
Line 578 ⟶ 636:
] lFx ## for b
AP
] lFx ## for f</
=={{header|F_Sharp|F#}}==
{{trans|C#}}
<
Console.ForegroundColor <- ConsoleColor.Red
Line 598 ⟶ 656:
Console.ResetColor()
Console.WriteLine("Back to normal")
Console.ReadKey()</
=={{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.
<
DECIMAL
( support routines)
Line 622 ⟶ 680:
: TEXT ( color ) 30 + ATTR ; ( use: YELLOW TEXT )
: BACKGROUND ( color ) 40 + ATTR ; ( use: BLUE BACKGROUND )
</
With the code loaded into Forth, color control is a part of the language
<
BLUE TEXT BOLD ATTR ok
CYAN TEXT ok</
=={{header|Fortran}}==
<
! and ANSI supporting terminal (tested Linux, various terminals).
program coloured_terminal_text
Line 665 ⟶ 723:
write(ERROR_UNIT, '(a)') background_green // 'Bonus Round' // reset
end program coloured_terminal_text</
===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.
<
use kernel32
implicit none
Line 689 ⟶ 747:
print "(A)", "This is a red string."
q = SetConsoleTextAttribute(hConsole, csbi%wAttributes)
end program</
=={{header|FreeBASIC}}==
Line 695 ⟶ 753:
Draws a 4x4 grid of coloured text with coloured backgrounds. Auto-blinking text isn't supported.
<
color i, 15-i
print "Colour "+str(i),
if i mod 4 = 3 then color 0,0: print
next i</
=={{header|FunL}}==
<
bold()
Line 714 ⟶ 772:
reset()
println( RED + 'Red', GREEN + 'Green', BLUE + 'Blue', MAGENTA + 'Magenta', CYAN + 'Cyan', YELLOW + 'Yellow' + RESET )</
=={{header|Go}}==
===External command===
<
import (
Line 745 ⟶ 803:
cmd.Stdout = os.Stdout
cmd.Run()
}</
Optional tasks
<
import (
Line 781 ⟶ 839:
cmd.Stdout = os.Stdout
return cmd.Run()
}</
===ANSI escape codes===
<
import "fmt"
Line 791 ⟶ 849:
fmt.Println("\033[32mGreen")
fmt.Println("\033[34mBlue")
}</
Optional tasks
<
import "fmt"
Line 803 ⟶ 861:
fmt.Println(" Blinking Red ")
fmt.Print("\033[25;40m") // blink off, black background
}</
===Ncurses===
{{libheader|Curses}}
<
import (
Line 836 ⟶ 894:
s.Println("Blue")
s.GetChar()
}</
Optional tasks
<
import (
Line 867 ⟶ 925:
s.Print(" Blinking Red ")
s.GetChar()
}</
=={{header|Golo}}==
<
----
This module demonstrates terminal colours.
Line 907 ⟶ 965:
}
println("")
}</
=={{header|GW-BASIC}}==
Sixteen foreground colours, in non-flashing and flashing, and eight background colours.
<
20 COLOR I, 7 - (I MOD 8)
30 PRINT I;
40 IF I MOD 4 = 3 THEN COLOR 7, 0 : PRINT
50 NEXT I</
=={{header|Haskell}}==
Line 924 ⟶ 982:
{{Works with|ansi-terminal|0.5.5.1}}
<
import System.Console.ANSI
Line 940 ⟶ 998:
colorStrLn Vivid Green Dull Black "This is green on black."
colorStrLn Vivid Yellow Dull Black "This is yellow on black."
colorStrLn Dull Black Vivid Blue "This is black on light blue."</
=={{header|J}}==
Line 947 ⟶ 1,005:
<!--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.
<
CSI=: 27 91 { a.
Line 975 ⟶ 1,033:
J=: J , (backward 5),'\____/'
smoutput(color BLACK),(clear 2),(move 8 22),J,(WHITE color BLACK),(downward 2)
</syntaxhighlight>
=={{header|Java}}==
<syntaxhighlight lang="java">
public class TerminalControlColouredText {
public static void main(String[] args) {
System.out.print(Color.GREEN_BACKGROUND);
System.out.print(Color.WHITE_UNDERLINED);
System.out.println("Green background with underlined white text");
System.out.println(Color.RESET);
System.out.print(Color.YELLOW_BACKGROUND_BRIGHT);
System.out.print(Color.BLUE_BOLD);
System.out.println("Bright yellow background with bold blue text");
System.out.println(Color.RESET);
System.out.print(Color.CYAN_BACKGROUND);
System.out.print(Color.MAGENTA_BOLD_BRIGHT);
System.out.println("Cyan background with bold bright magenta text");
System.out.println(Color.RESET);
}
private enum Color {
// Restore original background and text colours
RESET("\033[0m"),
// Text colours
BLACK("\033[0;30m"),
RED("\033[0;31m"),
GREEN("\033[0;32m"),
YELLOW("\033[0;33m"),
BLUE("\033[0;34m"),
MAGENTA("\033[0;35m"),
CYAN("\033[0;36m"),
WHITE("\033[0;37m"),
// Bold text colours
BLACK_BOLD("\033[1;30m"),
RED_BOLD("\033[1;31m"),
GREEN_BOLD("\033[1;32m"),
YELLOW_BOLD("\033[1;33m"),
BLUE_BOLD("\033[1;34m"),
MAGENTA_BOLD("\033[1;35m"),
CYAN_BOLD("\033[1;36m"),
WHITE_BOLD("\033[1;37m"),
// Underlined text colours
BLACK_UNDERLINED("\033[4;30m"),
RED_UNDERLINED("\033[4;31m"),
GREEN_UNDERLINED("\033[4;32m"),
YELLOW_UNDERLINED("\033[4;33m"),
BLUE_UNDERLINED("\033[4;34m"),
MAGENTA_UNDERLINED("\033[4;35m"),
CYAN_UNDERLINED("\033[4;36m"),
WHITE_UNDERLINED("\033[4;37m"),
// Bright text colours
BLACK_BRIGHT("\033[0;90m"),
RED_BRIGHT("\033[0;91m"),
GREEN_BRIGHT("\033[0;92m"),
YELLOW_BRIGHT("\033[0;93m"),
BLUE_BRIGHT("\033[0;94m"),
MAGENTA_BRIGHT("\033[0;95m"),
CYAN_BRIGHT("\033[0;96m"),
WHITE_BRIGHT("\033[0;97m"),
// Bold and bright text colours
BLACK_BOLD_BRIGHT("\033[1;90m"),
RED_BOLD_BRIGHT("\033[1;91m"),
GREEN_BOLD_BRIGHT("\033[1;92m"),
YELLOW_BOLD_BRIGHT("\033[1;93m"),
BLUE_BOLD_BRIGHT("\033[1;94m"),
MAGENTA_BOLD_BRIGHT("\033[1;95m"),
CYAN_BOLD_BRIGHT("\033[1;96m"),
WHITE_BOLD_BRIGHT("\033[1;97m"),
// Background colours
BLACK_BACKGROUND("\033[40m"),
RED_BACKGROUND("\033[41m"),
GREEN_BACKGROUND("\033[42m"),
YELLOW_BACKGROUND("\033[43m"),
BLUE_BACKGROUND("\033[44m"),
MAGENTA_BACKGROUND("\033[45m"),
CYAN_BACKGROUND("\033[46m"),
WHITE_BACKGROUND("\033[47m"),
// Bright background colours
BLACK_BACKGROUND_BRIGHT("\033[0;100m"),
RED_BACKGROUND_BRIGHT("\033[0;101m"),
GREEN_BACKGROUND_BRIGHT("\033[0;102m"),
YELLOW_BACKGROUND_BRIGHT("\033[0;103m"),
BLUE_BACKGROUND_BRIGHT("\033[0;104m"),
MAGENTA_BACKGROUND_BRIGHT("\033[0;105m"),
CYAN_BACKGROUND_BRIGHT("\033[0;106m"),
WHITE_BACKGROUND_BRIGHT("\033[0;107m");
private Color(String aCode) {
code = aCode;
}
@Override
public String toString() {
return code;
}
private final String code;
}
}
</syntaxhighlight>
[[Media:ColouredTextJava.PNG]]
=={{header|jq}}==
''Adapted from [[#Wren|Wren]]''
{{works with|jq}}
''Also works with gojq, the Go implmentation of jq''
<syntaxhighlight lang="jq">
# Pseudosleep for at least the given number of seconds,
# and emit the actual number of seconds that have elapsed.
def sleep($seconds):
now
| . as $now
| until( . - $now >= $seconds; now)
| . - $now ;
def esc: "\u001b";
def colors: ["Black", "Red", "Green", "Yellow", "Blue", "Magenta", "Cyan", "White"];
# display words using 'bright' colors
(range(1; 1 + (colors|length)) | "\(esc)[\(30+.);1m\(colors[.])"), # red to white
sleep(3), # wait for 3 seconds
"\(esc)[47m", # set background color to white
"\(esc)[2J", # clear screen to background color
"\(esc)[H", # home the cursor
# display words again using 'blinking' colors
"\(esc)[5m", # blink on
(range(0;6) | "\(esc)[\(30+.);1m\(colors[.])"), # black to cyan
sleep(3), # wait for 3 more seconds
"\(esc)[0m", # reset all attributes
"\(esc)[2J", # clear screen to background color
"\(esc)[H" # home the cursor
</syntaxhighlight>
''Invocation''
Using jq: jq -nrf coloured_text.jq
=={{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.
<syntaxhighlight lang="julia">
using AnsiColor
Line 1,014 ⟶ 1,220:
println("This terminal appears not to support color.")
end
</syntaxhighlight>
{{out}}
Line 1,030 ⟶ 1,236:
=={{header|Kotlin}}==
{{Works with|Ubuntu|14.04}}
<
const val ESC = "\u001B"
Line 1,055 ⟶ 1,261:
}
println(WHITE) // set foreground color to normal white
}</
=={{header|Lasso}}==
<
define ec(code::string) => {
Line 1,089 ⟶ 1,295:
stdoutnl('So this is the Rosetta Code!')
stdout( ec('normal'))
</syntaxhighlight>
=={{header|Locomotive Basic}}==
[[File:Cpcbasic colored text mode1.png|thumb|Graphics mode 1]]
[[File:Cpcbasic colored text mode0.png|thumb|Graphics mode 0]]
<syntaxhighlight lang="locobasic">10 mode 1:defint a-z
20 print "Mode 1 (4 colors):"
30 for y=0 to 3
Line 1,127 ⟶ 1,334:
330 print "*End of color demo*"
340 locate 1,25:print "<Press any key>";:call &bb06
350 mode 1</
=={{header|Lua}}==
Assumes an ansi-capable terminal..
<
colors = { 30,31,32,33,34,35,36,37,90,91,92,93,94,95,96,97 }
for _,bg in ipairs(colors) do
Line 1,138 ⟶ 1,345:
end
print("\027[0m") -- be nice, reset
end</
{{out}}
''(image upload is broken)''
Line 1,144 ⟶ 1,351:
=={{header|Mathematica}}/{{header|Wolfram Language}}==
Delegating to tput on terminal enabled OS(Mac Os, Linux)
<
Run["tput setaf 2"]; Print["Coloured Text"];
Run["tput setaf 3"]; Print["Coloured Text"]</
[[File:colouredtextmma.png]]
=={{header|Nim}}==
<
setForegroundColor(fgRed)
echo "FATAL ERROR! Cannot write to /boot/vmlinuz-3.2.0-33-generic"
Line 1,172 ⟶ 1,379:
setForegroundColor(fgMagenta)
echo "RosettaCode!"</
=={{header|OCaml}}==
Line 1,178 ⟶ 1,385:
Using the library [http://forge.ocamlcore.org/projects/ansiterminal/ ANSITerminal] in the interactive loop:
<
# open ANSITerminal ;;
# print_string [cyan; on_blue] "Hello\n" ;;
Hello
- : unit = ()</
=={{header|ooRexx}}==
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.
<syntaxhighlight lang="rexx">
#!/usr/bin/rexx
/*.----------------------------------------------------------------------.*/
Line 1,318 ⟶ 1,525:
end
return
</syntaxhighlight>
This is what the output looks like:
Line 1,327 ⟶ 1,534:
=={{header|PARI/GP}}==
<
=={{header|Pascal}}==
Line 1,333 ⟶ 1,540:
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.
<
uses CRT;
Line 1,351 ⟶ 1,558:
TextBackground(White);
TextColor(Black);
end.</
=={{header|PascalABC.NET}}==
<syntaxhighlight lang="delphi">
##
uses System;
Console.ForegroundColor := ConsoleColor.Red;
Console.BackgroundColor := ConsoleColor.Yellow;
Console.WriteLine('Red on Yellow');
Console.ForegroundColor := ConsoleColor.Black;
Console.BackgroundColor := ConsoleColor.White;
Console.WriteLine('Black on White');
</syntaxhighlight>
=={{header|Perl}}==
<
red => "\e[1;31m",
green => "\e[1;32m",
Line 1,375 ⟶ 1,594:
say colored('MAGENTA', 'bold magenta');
say colored('CYAN ON RED', 'bold cyan on_red');
say colored('YELLOW', 'bold yellow');</
<
#ON WINDOWS USING POWERSHELL or WT.EXE
$ForegroundColor = {
Line 1,421 ⟶ 1,640:
print "White On Blue";
print $ClearColors;
</syntaxhighlight>
=={{header|Phix}}==
{{trans|PureBasic}}
The following builtin constants (0..15) may be used:
BLACK, BLUE,
BRIGHT_BLUE, BRIGHT_GREEN, BRIGHT_CYAN, BRIGHT_RED, BRIGHT_MAGENTA,
YELLOW, BRIGHT_WHITE
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #000080;font-style:italic;">--
-- demo\rosetta\Coloured_text.exw
--
--</span>
<span style="color: #
<span style="color: #
<span style="color: #7060A8;">bk_color</span><span style="color: #0000FF;">(</span><span style="color: #004600;">BLACK</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;">"Background color# 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15\n"</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"</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">foreground</span><span style="color: #0000FF;">=</span><span style="color: #000000;">0</span> <span style="color: #008080;">to</span> <span style="color: #000000;">15</span> <span style="color: #008080;">do</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;">"Foreground color# %02d "</span><span style="color: #0000FF;">,</span><span style="color: #000000;">foreground</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">for</span> <span style="color: #
<span style="color: #
<span style="color: #
<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;">"%02d"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">foreground</span><span style="color: #0000FF;">)</span>
<span style="color: #
<span style="color: #
<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;">" "</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
Line 1,450 ⟶ 1,672:
<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>
<!--</
Output matches PureBasic
=={{header|PicoLisp}}==
{{trans|UNIX Shell}}
<
(quit "This application requires a colour terminal") )
Line 1,469 ⟶ 1,691:
(call 'tput 'sgr0) # reset
(prinl)</
=={{header|PowerShell}}==
<syntaxhighlight lang="powershell">
foreach ($color in [enum]::GetValues([System.ConsoleColor])) {Write-Host "$color color." -ForegroundColor $color}
</syntaxhighlight>
=={{header|PureBasic}}==
<
PrintN("Background color# 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15")
PrintN(" -----------------------------------------------")
Line 1,496 ⟶ 1,718:
Print(#CRLF$ + #CRLF$ + "Press ENTER to exit"): Input()
CloseConsole()
EndIf</
[[Image:terminal_control,colored_text.png]]
=={{header|Python}}==
{{libheader|colorama}}
<
from colorama import init, Fore, Back, Style
init(autoreset=True)
Line 1,513 ⟶ 1,735:
print Fore.MAGENTA + "Rosetta Code!"
print Back.YELLOW + Fore.BLUE + Style.BRIGHT + " " * 40 + " == Good Bye!"
</syntaxhighlight>
This is a windows only solution without colorama
<
from ctypes import *
Line 1,533 ⟶ 1,755:
color(7)
raw_input("holding cmd")
</syntaxhighlight>
=={{header|Racket}}==
{{trans|Tcl}}
<
#lang racket
Line 1,562 ⟶ 1,784:
(reset))
(displayln "Steady only"))
</syntaxhighlight>
=={{header|Raku}}==
(formerly Perl 6)
<syntaxhighlight lang="raku"
say colored('RED ON WHITE', 'bold red on_white');
Line 1,573 ⟶ 1,795:
say colored('MAGENTA', 'bold magenta');
say colored('CYAN ON RED', 'bold cyan on_red');
say colored('YELLOW', 'bold yellow');</
=={{header|REXX}}==
Line 1,597 ⟶ 1,819:
<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.)
<
parse arg !; if !all() then exit /*exit if documentation specified*/
if \!dos & \!os2 then exit /*if this isn't DOS, then exit. */
Line 1,630 ⟶ 1,852:
!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
!var:call !fid;if !kexx then return space(dosenv(arg(1)));return space(value(arg(1),,!env))</
=={{header|Ring}}==
<
# Project : Terminal control/Coloured text
Line 1,645 ⟶ 1,867:
cc_print(forecolor | CC_BG_WHITE, "Rosetta Code" + nl)
next
</syntaxhighlight>
Output image:
Line 1,654 ⟶ 1,876:
{{libheader|colored}}
<
require 'rubygems'
require 'colored'
Line 1,677 ⟶ 1,899:
puts 'white on green'.white_on_green
puts 'white on magenta'.white_on_magenta
puts 'white on red'.white_on_red</
[[File:Colored-text-ruby.png]]
Line 1,683 ⟶ 1,905:
=={{header|Rust}}==
<
const RESET: &str = "\x1B[0m";
Line 1,705 ⟶ 1,927:
println!("{}", RESET);
}
}</
=={{header|Scala}}==
===Scala idiom (Functional Programming)===
{{Works with|Ubuntu|14.04}}
<
val ESC = "\u001B"
val (normal, bold, blink, black, white) =
Line 1,734 ⟶ 1,956:
println(white) // set foreground color to normal white
}
</syntaxhighlight>
=={{header|Sidef}}==
{{trans|Raku}}
<
say a.colored('RED ON WHITE', 'bold red on_white');
Line 1,745 ⟶ 1,967:
say a.colored('MAGENTA', 'bold magenta');
say a.colored('CYAN ON RED', 'bold cyan on_red');
say a.colored('YELLOW', 'bold yellow');</
=={{header|Tcl}}==
This only works on Unix terminals as it delegates to the system <tt>tput</tt> command.
<
proc capability cap {expr {![catch {exec tput -S << $cap}]}}
proc colorterm {} {expr {[capability setaf] && [capability setab]}}
Line 1,774 ⟶ 1,996:
} else {
puts "Steady only"
}</
=={{header|TPP}}==
<
This is red
--color green
Line 1,788 ⟶ 2,010:
This is magenta
--color yellow
This is yellow</
=={{header|True BASIC}}==
<syntaxhighlight lang="qbasic">FOR n = 1 TO 15
SET COLOR n
PRINT "Rosetta Code"
NEXT n
END</syntaxhighlight>
=={{header|UNIX Shell}}==
<
# Check if the terminal supports colour
Line 1,833 ⟶ 2,064:
echo "Flashing text"
tput sgr0 # reset everything before exiting</
=={{header|Wren}}==
<
var colors = ["Black", "Red", "Green", "Yellow", "Blue", "Magenta", "Cyan", "White"]
Line 1,853 ⟶ 2,084:
System.write("\e[0m") // reset all attributes
System.write("\e[2J") // clear screen to background color
System.write("\e[H") // home the cursor</
=={{header|XPL0}}==
Line 1,871 ⟶ 2,102:
PCs and by simulators, such as DOSBox, on other computers.
<
def Black, Blue, Green, Cyan, Red, Magenta, Brown, White, \attribute colors
Gray, LBlue, LGreen, LCyan, LRed, LMagenta, Yellow, BWhite; \EGA palette
Line 1,885 ⟶ 2,116:
Attrib(Cyan<<4+Black); \black on cyan
ChOut(6,^r);
]</
=={{header|zkl}}==
{{trans|C}}
Terminal window on Linux, prints tables of colored glyphs.
<
println("\n\e[1m%s\e[m\n bg\t fg".fmt(title));
foreach b in ([40..48].chain([100..107])){
Line 1,905 ⟶ 2,136:
table("underline ( ESC[4m ), support varies", "4;");
table("blink ( ESC[5m )", "5;");
table("inverted ( ESC[7m )", "7;");</
=={{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.
<
20 READ c$: REM get our text for display
30 INK l: REM set the text colour
Line 1,921 ⟶ 2,152:
110 STOP
900 DATA "Black","Blue","Red","Magenta","Green","Cyan","Yellow","White"</
{{omit from|Axe}}
|