Terminal control/Inverse video: Difference between revisions

From Rosetta Code
Content added Content deleted
m (whitespace/category)
({{header|AWK}})
Line 1: Line 1:
{{task|Terminal control}}[[Category:Terminal Control]]
{{task|Terminal control}}[[Category:Terminal Control]]
The task is to display a word in inverse video followed by a word in normal video.
The task is to display a word in inverse video followed by a word in normal video.

=={{header|AWK}}==
<lang awk>BEGIN {
system ("tput rev")
print "foo"
system ("tput sgr0")
print "bar"
}</lang>


=={{header|BASIC}}==
=={{header|BASIC}}==

Revision as of 00:08, 23 May 2011

Task
Terminal control/Inverse video
You are encouraged to solve this task according to the task description, using any language you may know.

The task is to display a word in inverse video followed by a word in normal video.

AWK

<lang awk>BEGIN { system ("tput rev") print "foo" system ("tput sgr0") print "bar" }</lang>

BASIC

ZX Spectrum Basic

<lang basic>10 INVERSE 1 20 PRINT "FOO"; 30 INVERSE 0 40 PRINT "BAR"</lang>

PicoLisp

<lang PicoLisp>(prin "abc") (call "tput" "rev") (prin "def") # These three chars are displayed in reverse video (call "tput" "sgr0") (prinl "ghi")</lang>

Tcl

This only works on Unix terminals. <lang tcl># Get how the terminal wants to do things... set videoSeq(reverse) [exec tput rev] set videoSeq(normal) [exec tput rmso] proc reverseVideo str {

   global videoSeq
   return "$videoSeq(reverse)${str}$videoSeq(normal)"

}

  1. The things to print

set inReverse "foo" set inNormal "bar"

  1. Print those words

puts "[reverseVideo $inReverse] $inNormal"</lang>

UNIX Shell

Works with: Bourne Shell
Works with: bash

<lang sh>#!/bin/sh tput rev # foo is reversed echo 'foo' tput sgr0 # bar is normal video echo 'bar'</lang>