Terminal control/Cursor positioning

From Rosetta Code
Revision as of 05:22, 19 February 2011 by rosettacode>L2G (omit from Scratch: no concept of a terminal window)
Task
Terminal control/Cursor positioning
You are encouraged to solve this task according to the task description, using any language you may know.

Move the cursor to column 3, row 6 and display the word "Hello", so that the letter H is in column 3 on row 6.

BASIC

Applesoft BASIC

<lang Applesoft BASIC> 10 VTAB 6: HTAB 3

20  PRINT "HELLO"</lang>

Locomotive Basic

<lang locobasic> 10 LOCATE 3,6

20 PRINT "Hello"</lang>

ZX Spectrum Basic

<lang basic> 10 REM The top left corner is at position 0,0

20 REM So we subtract one from the coordinates
30 PRINT AT 5,2 "Hello"</lang>

C

The C version of the minesweeper game uses curses. Minesweeper_game#C

Euphoria

<lang Euphoria>position(6,3) puts(1,"Hello")</lang>

Forth

<lang forth>2 5 at-xy ." Hello"</lang>

<lang logo>setcursor [2 5] type "Hello</lang> You can also draw positioned text on the turtle graphics window. <lang logo>setpos [20 50] setxy 20 30  ; alternate way to set position label "Hello</lang>

PicoLisp

<lang PicoLisp>(call 'tput "cup" 6 3) (prin "Hello")</lang>

PureBasic

<lang PureBasic>EnableGraphicalConsole(#True) ConsoleLocate(3,6) Print("Hello")</lang>

REXX

The REXX language doesn't have any cursor or screen management tools, but some REXX interpreters have added the functionality via different methods.

Works with: PC/REXX

<lang rexx>/*REXX program demonstrates cursor position and writing of text to same.*/

call cursor 3,6 /*move the cursor to row 3, col 6*/ say 'Hello' /*write the text at that location*/

call scrwrite 30,50,'Hello.' /*another method. */

call scrwrite 40,60,'Hello.',,,14 /*another ... in yellow.*/</lang>

Retro

<lang Retro>with console'

hello 3 6 at-xy "Hello" puts ;</lang>

Tcl

<lang tcl>exec tput cup 6 3 >/dev/tty puts "Hello"</lang>