Terminal control/Cursor positioning: Difference between revisions

From Rosetta Code
Content added Content deleted
Line 14: Line 14:


=== {{header|ZX Spectrum Basic}} ===
=== {{header|ZX Spectrum Basic}} ===
<lang basic> 10 REM The top left corner is at position 0,0
<lang zxbasic> 10 REM The top left corner is at position 0,0
20 REM So we subtract one from the coordinates
20 REM So we subtract one from the coordinates
30 PRINT AT 5,2 "Hello"</lang>
30 PRINT AT 5,2 "Hello"</lang>

Revision as of 10:46, 5 August 2011

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 zxbasic> 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>

BBC BASIC

<lang bbcbasic>PRINT TAB(3,6);"Hello"</lang>

Blast

<lang blast># This will display a message at a specific position on the terminal screen .begin cursor 6,3 display "Hello!" return

  1. This is the end of the script</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>

Liberty BASIC

<lang lb>locate 3, 6 print "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>

PowerShell

The following will only work in the PowerShell console host. Most notably it will not work in the PowerShell ISE. <lang powershell>$Host.UI.RawUI.CursorPosition = New-Object System.Management.Automation.Host.Coordinates 2,5 $Host.UI.Write('Hello')</lang> Alternatively, in any PowerShell host that uses the Windows console, one can directly use the .NET Console class: <lang powershell>[Console]::SetCursorPosition(2,5) [Console]::Write('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>