Terminal control/Inverse video: Difference between revisions
m
→{{header|Wren}}: Changed to Wren S/H
Puppydrum64 (talk | contribs) |
m (→{{header|Wren}}: Changed to Wren S/H) |
||
(4 intermediate revisions by 4 users not shown) | |||
Line 9:
{{trans|Python}}
<
=={{header|6502 Assembly}}==
Line 22:
SYS680
</pre>
<
; *** labels ***
Line 44:
.byte $92 ; the REVERSE OFF control code
.null " normal" ; null terminated string
</syntaxhighlight>
</lang>▼
=={{header|Action!}}==
<
BYTE i
Line 63:
PrintInv("Inverse")
Print(" video")
RETURN</
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Inverse_video.png Screenshot from Atari 8-bit computer]
=={{header|Ada}}==
<
procedure Reverse_Video is
Line 79:
Put (Norm_Video & " Normal");
end Reverse_Video;
</syntaxhighlight>
=={{header|ARM Assembly}}==
{{works with|https://akkit.org/info/gbatek.htm Game Boy Advance}}
This is a slightly different take on the age-old XOR technique to flip the colors of a monochrome graphic. While the Game Boy Advance uses 16 bits per pixel, we'll use a monochrome bitmap font, where each bit that's a 1 is an instruction to fill in a pixel and each bit that's a 0 is an instruction to leave it blank. By flipping the bits of the font itself, we can create the "inverse video" effect. The ARM's <code>EOR</code> instruction can't be used to write to memory directly; you would have to load from memory into a register first, apply the <code>EOR</code> operation with the desired value, and write back. Our method of flipping the bits of the font will save time.
The Game Boy Advance's video memory is very simple, a two-dimensional array of 16-bit values ranging from memory locations <code>0x06000000</code> to <code>0x06012BFF</code> represents each pixel of the screen. Write a 15-bit hex color value to an element of the array to turn the corresponding pixel to that color value.
<
; Program Start
Line 221 ⟶ 222:
strB r4,[r6]
LDMFD sp!,{r4-r6,lr}
bx lr</
{{out}}
Line 228 ⟶ 229:
=={{header|AutoHotkey}}==
Call SetConsoleTextAttribute() to change foreground and background colors.
<
hConsole := DllCall( "GetStdHandle", int, STDOUT := -11 )
Line 241 ⟶ 242:
SetConsoleTextAttribute(hConsole, Attributes){
return DllCall( "SetConsoleTextAttribute", UPtr, hConsole, UShort, Attributes)
}</
=={{header|AWK}}==
<
system ("tput rev")
print "foo"
system ("tput sgr0")
print "bar"
}</
=={{header|Axe}}==
A delay is added because the screen redraws with the normal font after the program exits.
<
Disp "INVERTED"
Fix 2
Disp "REGULAR",i
Pause 4500</
=={{header|BaCon}}==
<
PRINT "a word"
COLOR RESET
PRINT "a word"</
=={{header|BASIC}}==
==={{header|Applesoft BASIC}}===
<
==={{header|BBC BASIC}}===
<
COLOUR 15 : REM White foreground
PRINT "Inverse";
COLOUR 128+15 : REM White background
COLOUR 0 : REM Black foreground
PRINT " video"</
Alternative method using 'VDU code' strings:
<
normal$ = CHR$(17)+CHR$(128+15)+CHR$(17)+CHR$(0)
PRINT inverse$ + "Inverse" + normal$ + " video"</
==={{header|Commodore BASIC}}===
Line 287 ⟶ 288:
Commodore computers have defined a "reverse" character set in character ROM. This can be accessed through control characters reserved in the ASCII (PETSCII) character table. To enable reverse characters, print CHR$(18) ("Reverse On"). Reverse characters will continue until a "Reverse Off" CHR$(146) is printed, or until a newline (carriage return CHR$(13)) which may also occur at the end of a print statement.
<
10 print chr$(18);"reverse on";chr$(146);" reverse off"
20 print
Line 295 ⟶ 296:
50 print chr$(18);"this is reversed... ":print "this is not."
60 print
70 print chr$(18);"this is reversed... ";chr$(13);"this is not."</
==={{header|FreeBASIC}}===
<
Locate 2, 2 : Print "Video inverso"
Color 15, 0 ' usa los colores negro (fondo) y blanco (primer plano)
Locate 3, 2 : Print "Video normal"
Sleep</
Line 309 ⟶ 310:
The firmware routine at &bb9c (TXT INVERSE) swaps the current Locomotive BASIC PEN and PAPER colors:
<
20 CALL &bb9c:PRINT "normal"</
==={{header|PureBasic}}===
<
ConsoleColor(0, 15) ;use the colors black (background) and white (forground)
PrintN("Inverse Video")
Line 321 ⟶ 322:
Print(#CRLF$ + #CRLF$ + "Press ENTER to exit"): Input()
CloseConsole()
EndIf</
==={{header|Run BASIC}}===
<
x$ = shell$("tput mr
echo 'foo'")
Line 331 ⟶ 332:
x$ = shell$("tput me
echo 'bar'")
wait</
==={{header|Sinclair ZX81 BASIC}}===
Inverse video is available from the keyboard (accessed with <code>SHIFT</code><code>9</code>), so the normal way to do this would be just
<
but with the 'foo' in inverse video and the 'bar' in normal video.
If this won't work (say, if we may want to use inverse video with string variables rather than string literals), we can use a small subroutine—relying on the fact that the ZX81 character set uses the high bit of each character code to select normal or inverse video.
<
20 GOSUB 50
30 PRINT S$;"BAR"
Line 346 ⟶ 347:
60 LET S$(I)=CHR$ (128+CODE S$(I))
70 NEXT I
80 RETURN</
Note that this subroutine assumes the source string is not already in inverse video: if it could be, you will need to test each character before you attempt to convert it.
==={{header|Yabasic}}===
<
// o también
print reverse "Video inverso"
print color("white","black") "Video normal"</
==={{header|ZX Spectrum Basic}}===
<
20 PRINT "FOO";
30 INVERSE 0
40 PRINT "BAR"</
=={{header|Befunge}}==
Assuming a terminal with support for ANSI escape sequences.
<
=={{header|C}}==
<
int main()
Line 375 ⟶ 376:
return 0;
}</
=={{header|COBOL}}==
<
PROGRAM-ID. terminal-reverse-video.
Line 386 ⟶ 387:
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)
(add-string scr "Reverse" :attributes '(:reverse))
(add-string scr " Normal" :attributes '())
(refresh scr)
(get-char scr)))</
=={{header|Forth}}==
Developed with Gforth 0.7.9
<
: Normal #27 emit "[m" type ;
: test cr Reverse ." Reverse " cr Normal ." Normal " ;
test
</syntaxhighlight>
=={{header|FunL}}==
<
println( "${REVERSED}This is reversed.$RESET This is normal." )</
=={{header|Go}}==
===External command===
<
import (
Line 433 ⟶ 434:
cmd.Stdout = os.Stdout
return cmd.Run()
}</
===ANSI escape codes===
<
import "fmt"
Line 441 ⟶ 442:
func main() {
fmt.Println("\033[7mRosetta\033[m Code")
}</
===Ncurses===
{{libheader|Curses}}
<
import (
Line 463 ⟶ 464:
s.Println(" Code")
s.GetChar()
}</
=={{header|J}}==
Use the definitions given in [[Terminal_control/Coloured_text#J]]
<syntaxhighlight lang="j">
;:';:,#.*."3,(C.A.)/\/&.:;:' NB. some output beforehand
attributes REVERSEVIDEO NB. does as it says
Line 473 ⟶ 474:
attributes OFF NB. no more blinky flashy
parseFrench=:;:,#.*."3,(C.A.)/\/&.:;: NB. just kidding! More output.
</syntaxhighlight>
=={{header|jq}}==
{{works with|jq}}
'''Also works with gojq, the Go implementation of jq, and with fq.'''
'''Invocation:'''
<pre>
jq -nr -f terminal-control-inverse-video.jq
<syntaxhighlight lang=jq>
# Be busy for at least the given number of seconds,
# and emit the actual number of seconds that have elapsed.
# The reason for defining sleep/1 is that it allows the idiom:
# E | F, (sleep(1) as $elapsed | CONTINUE_WITH_E_AS_INPUT)
def sleep($seconds):
now
| . as $now
| until( . - $now >= $seconds; now)
| . - $now ;
def demo:
def ESC: "\u001B";
"\(ESC)[7mInverse",
(sleep(2) | "\(ESC)[0mNormal");
demo
</syntaxhighlight>
=={{header|Julia}}==
Use within the Julia REPL command line.
<
println(WHITE_FG, BLACK_BG, "Normal")
println(WHITE_BG, BLACK_FG, "Reversed")
println(WHITE_FG, BLACK_BG, "Normal")
</syntaxhighlight>
=={{header|Kotlin}}==
{{Works with|Ubuntu|14.04}}
<
fun main(args: Array<String>) {
println("\u001B[7mInverse\u001B[m Normal")
}</
=={{header|Lasso}}==
<
stdout( #esc + '[7m Reversed Video ' + #esc + '[0m Normal Video ')</
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<
Run["echo foo"] (* is displayed in reverse mode *)
Run["tput me"]
Run["echo bar"]</
=={{header|Nim}}==
<
stdout.styledWrite("normal ", styleReverse, "inverse", resetStyle, " normal\n")</
=={{header|OCaml}}==
Line 512 ⟶ 540:
Using the library [http://forge.ocamlcore.org/projects/ansiterminal/ ANSITerminal] in the interactive loop:
<
# open ANSITerminal ;;
# print_string [Inverse] "Hello\n" ;;
Hello
- : unit = ()</
=={{header|Pascal}}==
Line 523 ⟶ 551:
{{libheader|Curses}}
Using Free Pascal and ncurses. On some systems linking to the libtinfo library may be necessary.
<
{$LINKLIB tinfo}
uses
Line 537 ⟶ 565:
endwin;
end.
</syntaxhighlight>
=={{header|Perl}}==
Like Raku.
<
system "tput rev";
print "reversed\n";
system "tput sgr0";
print "normal\n";</
=={{header|Phix}}==
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #000080;font-style:italic;">--
-- demo\rosetta\Inverse_Video.exw
-- ================================
--</span>
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #7060A8;">text_color</span><span style="color: #0000FF;">(</span><span style="color: #004600;">BLACK</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">bk_color</span><span style="color: #0000FF;">(</span><span style="color: #004600;">WHITE</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;">"Inverse"</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">text_color</span><span style="color: #0000FF;">(</span><span style="color: #004600;">WHITE</span><span style="color: #0000FF;">)</span>
<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;">" Video"</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>
<!--</syntaxhighlight>-->
=={{header|PicoLisp}}==
<
(call "tput" "rev")
(prin "def") # These three chars are displayed in reverse video
(call "tput" "sgr0")
(prinl "ghi")</
=={{header|Python}}==
<
print "\033[7mReversed\033[m Normal"</
=={{header|Quackery}}==
<
[ $ 'print("\033[m", end="")' python ] is regulartext ( --> )
inversetext say "inverse video"
regulartext say " normal text"</
=={{header|Racket}}==
<
#lang racket
(require (planet neil/charterm:3:0))
Line 596 ⟶ 626:
(charterm-normal)
(charterm-display "World"))
</syntaxhighlight>
=={{header|Raku}}==
(formerly Perl 6)
<syntaxhighlight lang="raku"
run "tput", "rev";
say "reversed";
run "tput", "sgr0";
say "normal";</
=={{header|REXX}}==
This version only works with PC/REXX and Personal Rexx.
<
@day = 'day'
@night = 'night'
Line 615 ⟶ 645:
call scrwrite , 1+length(@day), @night, , , 112 /* " " " black " white.*/
exit 0 /*stick a fork in it, we're all done. */</
=={{header|Ring}}==
<
nverse = char(17)+char(128)+char(17)+char(15)
normal = char(17)+char(128+15)+char(17)+char(0)
see inverse + " inverse " + normal + " video"
</syntaxhighlight>
=={{header|Ruby}}==
{{Works with|Ubuntu|14.04}}
<
=={{header|Scala}}==
{{Works with|Ubuntu|14.04}}
<
println("\u001B[7mInverse\u001B[m Normal")
}</
=={{header|Standard ML}}==
<
=={{header|Tcl}}==
This only works on Unix terminals.
<
set videoSeq(reverse) [exec tput rev]
set videoSeq(normal) [exec tput rmso]
Line 652 ⟶ 682:
# Print those words
puts "[reverseVideo $inReverse] $inNormal"</
=={{header|TPP}}==
<
This is inverse
--revoff
This is normal</
=={{header|UNIX Shell}}==
Line 665 ⟶ 695:
{{works with|Bourne Shell}}
<
tput mr # foo is reversed
echo 'foo'
tput me # bar is normal video
echo 'bar'</
If the system supports terminfo, then <code>tput rev</code> and <code>tput sgr0</code> also work. (All recent systems have terminfo, except NetBSD, but [http://blog.netbsd.org/tnf/entry/terminfo_has_replaced_termcap NetBSD 6 will have terminfo].) The shorter names <code>mr</code> and <code>me</code> are the backward-compatible names from termcap.
Line 675 ⟶ 705:
If the terminal cannot do reverse video, then ''tput'' will fail with a message to standard error.
<
tput: Unknown terminfo capability `mr'</
Some programs use the ''standout mode'', which might look exactly like reverse video. (The escape sequences might be identical!)
<
echo 'foo'
tput se # exit standout mode
echo 'bar'</
If the system supports terminfo, then <code>tput smso</code> and <code>tput rmso</code> also work.
==={{header|C Shell}}===
<
echo 'foo'
tput me
echo 'bar'</
=={{header|Wren}}==
<
System.print("\e[0mNormal")</
=={{header|XPL0}}==
Line 701 ⟶ 731:
it provides many combinations of foreground and background colors.
<
[Attrib($70);
Text(6, "Inverse");
Line 707 ⟶ 737:
Text(6, " Video");
CrLf(6);
]</
=={{header|Z80 Assembly}}==
{{trans|Locomotive Basic}}
<
PrintChar equ &BB5A
InvertTextColors equ &BB9C
Line 737 ⟶ 767:
call PrintChar
inc hl
jp PrintString</
=={{header|zkl}}==
There is no explicit support for terminals/video. But, assuming an ANSI terminal:
<
{{omit from|ACL2}}
|