Terminal control/Unicode output: Difference between revisions

From Rosetta Code
Content added Content deleted
Line 20: Line 20:
=={{header|UNIX Shell}}==
=={{header|UNIX Shell}}==


<lang sh>if
<lang sh>
# We use a switch conditional here, because it enables us to utilize
awk '
# pattern matching against a string
BEGIN {
case $LANG in
if (ENVIRON["LANG"] ~ "UTF")
*UTF*)
exit 0 # exit ok
# This terminal supports Unicode
exit 255 # exit false
printf "\u25b3" # Requires a Unicode compatible printf
}'
;;
then
*)
# This terminal supports Unicode
printf "\u25b3" # Requires a Unicode compatible printf
echo "HW65001 This program requires a Unicode compatible terminal" >&2
exit 252 # Incompatible hardware
else
;;
echo "HW65001 This program requires a Unicode compatible terminal" >&2
esac</lang>
exit 252 # Incompatible hardware
fi</lang>


=={{header|ZX Spectrum Basic}}==
=={{header|ZX Spectrum Basic}}==

Revision as of 08:27, 11 September 2011

Terminal control/Unicode output is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.

The task is to check that the terminal supports Unicode output, before outputting a Unicode character. If the terminal supports Unicode, then the terminal should output a Unicode delta (U+25b3). If the terminal does not support Unicode, then an appropriate error should be raised.

AWK

<lang awk>#!/usr/bin/awk -f BEGIN {

 if (ENVIRON["LANG"] ~ "UTF")
   do
     # This terminal supports Unicode
     # We need a Unicode compatible printf, so we source this externally
     "/usr/bin/printf \\u25b3"
   done
 else
   print "HW65001 This program requires a Unicode compatible terminal"|"cat 1>&2"
   exit 252    # Incompatible hardware
 fi</lang>

UNIX Shell

<lang sh>

  1. We use a switch conditional here, because it enables us to utilize
  2. pattern matching against a string

case $LANG in

 *UTF*)
   # This terminal supports Unicode
   printf "\u25b3"    # Requires a Unicode compatible printf
   ;;
 *)
   echo "HW65001 This program requires a Unicode compatible terminal" >&2
   exit 252    # Incompatible hardware
   ;;

esac</lang>

ZX Spectrum Basic

<lang zxbasic>10 REM There is no Unicode delta in ROM 20 REM So we first define a custom character 30 FOR l=0 TO 7 40 READ n 50 POKE USR "d"+l,n 60 NEXT l 70 REM our custom character is a user defined d 80 PRINT CHR$(147): REM this outputs our delta 9500 REM data for our custom delta 9510 DATA 0,0,8,20,34,65,127,0 </lang>