Terminal control/Cursor movement: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
(add task to aarch64 assembly raspberry pi)
m (→‎{{header|Wren}}: Changed to Wren S/H)
 
(11 intermediate revisions by 10 users not shown)
Line 21:
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
<syntaxhighlight lang="aarch64 assembly">
<lang AArch64 Assembly>
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program cursorMove64.s */
Line 92:
/* for this file see task include a file in language AArch64 assembly */
.include "../includeARM64.inc"
</syntaxhighlight>
</lang>
 
=={{header|Action!}}==
<syntaxhighlight lang="action!">PROC Wait(BYTE frames)
BYTE RTCLOK=$14
frames==+RTCLOK
WHILE frames#RTCLOK DO OD
RETURN
 
PROC Main()
BYTE
d=[50],
CH=$02FC, ;Internal hardware value for last key pressed
ROWCRS=$0054 ;Current cursor row
CARD COLCRS=$0055 ;Current cursor column
 
Graphics(0)
Position(2,2)
Print("Press any key to start demonstration.")
Position(20,10)
Put(28) Put(29) ;trick to show the new cursor pos
DO UNTIL CH#$FF OD
CH=$FF
 
Wait(d) Put(30) ;move cursor left
Wait(d) Put(31) ;move cursor right
Wait(d) Put(28) ;move cursor up
Wait(d) Put(29) ;move cursor down
 
Wait(d) Position(0,ROWCRS) ;move to the beginning of the line
Put(28) Put(29) ;trick to show the new cursor pos
 
Wait(d) Position(39,ROWCRS) ;move to the end of the line
Put(28) Put(29) ;trick to show the new cursor pos
Wait(d) Position(0,0) ;move to the top-left corner
Put(28) Put(29) ;trick to show the new cursor pos
 
Wait(d) Position(39,23) ;move to the bottom-right corner
Put(29) Put(28) ;trick to show the new cursor pos
 
Wait(d)
RETURN</syntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Cursor_movement.png Screenshot from Atari 8-bit computer]
 
=={{header|Ada}}==
{{libheader|ANSIAda}}
<syntaxhighlight lang="ada">with Ada.Text_Io;
 
with Ansi;
 
procedure Movement is
use Ada.Text_Io;
begin
Put (Ansi.Store);
Put (Ansi.Position (Row => 20, Column => 40));
 
for A in 1 .. 15 loop
Put (Ansi.Back);
delay 0.020;
end loop;
 
for A in 1 .. 15 loop
Put (Ansi.Up);
delay 0.050;
end loop;
 
for A in 1 .. 15 loop
Put (Ansi.Forward);
delay 0.020;
end loop;
 
for A in 1 .. 15 loop
Put (Ansi.Down);
delay 0.050;
end loop;
 
delay 1.000;
Put (Ansi.Horizontal (Column => 1));
delay 2.000;
Put (Ansi.Position (1, 1));
delay 2.000;
Put (Ansi.Restore);
end Movement;</syntaxhighlight>
 
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi}}
<syntaxhighlight lang="arm assembly">
<lang ARM Assembly>
 
/* ARM assembly Raspberry PI */
Line 182 ⟶ 267:
bx lr @ return
 
</syntaxhighlight>
</lang>
 
=={{header|AutoHotkey}}==
 
<langsyntaxhighlight lang="autohotkey">DllCall("AllocConsole")
hConsole:=DllCall("GetConsoleWindow","UPtr")
Stdout:=FileOpen(DllCall("GetStdHandle", "int", -11, "ptr"), "h `n")
Line 258 ⟶ 343:
bufferheight:=NumGet(&struct,2,"UShort")
return 1
}</langsyntaxhighlight>
 
=={{header|Axe}}==
Axe does not allow relative movement of the cursor. However, if the current position is known in the X and Y variables, the behavior can be simulated.
<langsyntaxhighlight lang="axe">Output(X-1,Y)
Output(X+1,Y)
Output(X,Y-1)
Line 269 ⟶ 354:
Output(15,Y)
Output(0,0)
Output(15,7)</langsyntaxhighlight>
 
=={{header|BaCon}}==
 
<langsyntaxhighlight lang="freebasic">' ANSI terminal cursor movement
' Default number of positions, if not specified, is 1.
 
Line 301 ⟶ 386:
' Bottom right
R = ROWS
GOTOXY C,R</langsyntaxhighlight>
 
=={{header|BASIC}}==
Line 307 ⟶ 392:
{{works with|QBasic}}
 
<langsyntaxhighlight lang="qbasic">10 'move left
20 LOCATE , POS(0) - 1
30 'move right
Line 322 ⟶ 407:
140 LOCATE 1, 1
150 'bottom right corner; requires knowledge of screen dimensions (80x25 here)
160 LOCATE 25, 80</langsyntaxhighlight>
==={{header|Applesoft BASIC}}===
80-Column Text Card: Applesoft Control Codes
Line 329 ⟶ 414:
Apple II Family Identification
http://www.umich.edu/~archive/apple2/technotes/tn/misc/TN.MISC.007
<langsyntaxhighlight ApplesoftBasiclang="applesoftbasic">REM APPLE II GS ?
100 DATA56,32,31,254,160,0
110 DATA176,1,136,140,13,3,96
Line 386 ⟶ 471:
430 HTAB PEEK(33)
440 GET A$
</syntaxhighlight>
</lang>
 
=={{header|BBC BASIC}}==
<langsyntaxhighlight lang="bbcbasic"> VDU 8 : REM Move one position to the left
VDU 9 : REM Move one position to the right
VDU 11 : REM Move up one line
Line 398 ⟶ 483:
VDU 13,8,10 : REM Move to the end of the line
VDU 30,8 : REM Move to the bottom right corner
VDU 23,16,0;0;0;0; : REM Enable scrolling</langsyntaxhighlight>
 
=={{header|Befunge}}==
Line 437 ⟶ 522:
The conio.h header file in Borland's Turbo C makes keyboard interaction very simple. The following is an interactive program which has been tested with Turbo C, the delay function takes milliseconds and has been used to animate the involved cases.
 
<syntaxhighlight lang="c">
<lang C>
#include<conio.h>
#include<dos.h>
Line 521 ⟶ 606:
return 0;
}
</syntaxhighlight>
</lang>
 
=={{header|Common Lisp}}==
==={{header|ncurses}}===
To interface the ncurses C library from Lisp, the ''croatoan'' library is used.
<langsyntaxhighlight lang="lisp">(defun cursor-movement ()
(with-screen (scr :input-blocking t :input-echoing nil :cursor-visible t)
;; display the screen and wait for a keypress
Line 542 ⟶ 627:
(move scr (1- (height scr)) (1- (width scr))) (refresh scr) (get-char scr)
;; top left corner
(move scr 0 0) (refresh scr) (get-char scr)))</langsyntaxhighlight>
 
=={{header|C sharp|C#}}==
{{works with|Mono|1.2}}
{{works with|Visual C sharp|Visual C#|2003}}
<langsyntaxhighlight lang="csharp">static void Main(string[] args)
{
//There will be a 3 second pause between each cursor movement.
Line 574 ⟶ 659:
System.Threading.Thread.Sleep(3000);
}
</syntaxhighlight>
</lang>
 
=={{header|Forth}}==
Line 580 ⟶ 665:
 
The following example assumes we are using a terminal that accepts ANSI escape codes. It defines the ANSI codes as Forth words with a markup language look. With this code compiled into the Forth system, the commands are used like native Forth commands.
<LANGsyntaxhighlight FORTHlang="forth">( ANSI terminal control lexicon )
DECIMAL
 
Line 603 ⟶ 688:
( Define ANSI Forth names for these functions using our markup words)
: AT-XY ( col row -- ) SWAP <CUP> ;
: PAGE ( -- ) <ED> 1 1 <CUP> ;</LANGsyntaxhighlight>
Rosetta Task
<langsyntaxhighlight lang="forth">( move the cursor one position to the left) 1 <CUB>
( move the cursor one position to the right) 1 <CUF>
( move the cursor up one line ) 1 <CUU>
Line 613 ⟶ 698:
( move the cursor to the top left corner of the screen) 1 1 <CUP>
( move the cursor to the bottom right corner of the screen) 80 24 <CUP>
</syntaxhighlight>
</LANG>
 
=={{header|FreeBASIC}}==
<syntaxhighlight lang="vb">Dim As Integer w, h
 
Screeninfo w, h
'move left
Locate , Pos(0) - 1
'move right
Locate , Pos(0) + 1
'move up
Locate Csrlin - 1
'move down
Locate Csrlin + 1
'beginning of line
Locate , 1
'end of line
Locate , h
'top left corner
Locate 1, 1
'bottom right corner
Locate w, h</syntaxhighlight>
 
=={{header|Go}}==
===External commands===
<langsyntaxhighlight lang="go">package main
 
import (
Line 663 ⟶ 769:
cmd.Stdout = os.Stdout
return cmd.Run()
}</langsyntaxhighlight>
===ANSI escape codes===
Not meeting all task requirements. Some of the movements are awkward with ANSI escape codes alone and are best done with one of the other techniques shown.
<langsyntaxhighlight lang="go">package main
 
import (
Line 686 ⟶ 792:
fmt.Print("\033[;H") // top left
time.Sleep(1 * time.Second)
}</langsyntaxhighlight>
===Ncurses===
{{libheader|curses}}
<langsyntaxhighlight lang="go">package main
 
import (
Line 748 ⟶ 854:
s.Refresh()
s.GetChar()
}</langsyntaxhighlight>
 
=={{header|jq}}==
'''Adapted from [[#Wren|Wren]]'''
{{works with|jq}}
'''Also works with gojq, the Go implementation of jq, and with fq'''
 
The following relies on the ANSI terminal control codes. Unfortunately, as best I can tell,
horizontal cursor positioning via ANSI codes does not work in Terminal.app on a Mac.
 
Invocation: jq -nr --unbuffered -f cursor-movement.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";
def s: sleep(2) | empty;
"\(ESC)[2J", # clear terminal
"\(ESC)[12;40H", # move to (12, 40)
s,
"\(ESC)[D", # move left
s,
"\(ESC)[C", # move right
s,
"\(ESC)[A", # move up
s,
"\(ESC)[B", # move down
s,
"\(ESC)[G", # move to beginning of line
s,
"\(ESC)[79C", # move to end of line (assuming 80 column terminal)
s,
"\(ESC)[1;1H", # move to top left corner
s,
"\(ESC)[24;80H", # move to bottom right corner (assuming 80 x 24 terminal)
s,
"\(ESC)[1;1H" # home cursor again before quitting
;
 
demo
</syntaxhighlight>
=={{header|Julia}}==
{{trans|Kotlin}}
<langsyntaxhighlight lang="julia">const ESC = "\u001B" # escape code
const moves = Dict( "left" => "[1D", "right" => "[1C", "up" => "[1A", "down" => "[1B",
"linestart" => "[9D", "topleft" => "[H", "bottomright" => "[24;79H")
Line 766 ⟶ 920:
println()
println()
</syntaxhighlight>
</lang>
 
=={{header|Kotlin}}==
{{Works with|Ubuntu|14.04}}
<langsyntaxhighlight lang="scala">// version 1.1.2
 
const val ESC = "\u001B" // escape code
Line 792 ⟶ 946:
Thread.sleep(3000)
println()
}</langsyntaxhighlight>
 
=={{header|Lasso}}==
<langsyntaxhighlight Lassolang="lasso">#!/usr/bin/lasso9
 
local(esc = decode_base64('Gw=='))
Line 840 ⟶ 994:
// move the cursor to the bottom right corner of the screen
stdout(#esc + '[500;500H')
sleep(2000)</langsyntaxhighlight>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">Run["tput cub1"] (* one position to the left *)
Run["tput cuf1" ] (* one position to the right *)
Run["tput cuu1" ] (* up one line *)
Line 849 ⟶ 1,003:
Run["tput cr"] (* beginning of line *)
Run["tput home"] (* top left corner *)
 
WIDTH=RunThrough["tput cols", ""];
Line 855 ⟶ 1,008:
Run["tput hpa "<>WIDTH] (* end of line *)
Run["tput cup "<>HEIGHT<>" "<> WIDTH] (* bottom right corner *)</langsyntaxhighlight>
 
=={{header|Nim}}==
<syntaxhighlight lang="nim">import terminal
 
echo "Press the return key to go to next step."
echo "Starting in the middle of last line."
 
template waitUser() =
while getch() != '\r': discard
 
let (width, height) = terminalSize()
# Start by positionning the cursor in the middle of the line.
setCursorXPos(width div 2)
waitUser()
# Move one character backward.
cursorBackward(1)
waitUser()
# Move one character forward.
cursorForward(1)
waitUser()
# Move one character up.
cursorUp(1)
waitUser()
# Move one character down.
cursorDown(1)
waitUser()
# Move at beginning of line.
setCursorXPos(0)
waitUser()
# Move at end of line.
setCursorXPos(width - 1)
waitUser()
# Move cursor to the top left corner.
setCursorPos(0, 0)
waitUser()
# Move cursor to the bottom right corner.
setCursorPos(width - 1, height - 1)
waitUser()</syntaxhighlight>
 
=={{header|Perl}}==
{{trans|Raku}}
<langsyntaxhighlight lang="perl">system "tput cub1"; sleep 1; # one position to the left
system "tput cuf1"; sleep 1; # one position to the right
system "tput cuu1"; sleep 1; # up one line
Line 871 ⟶ 1,062:
 
system "tput cup $rows $cols"; # bottom right corner
sleep 1;</langsyntaxhighlight>
 
=={{header|Phix}}==
<!--<syntaxhighlight lang="phix">(notonline)-->
<lang Phix>--
<span style="color: #000080;font-style:italic;">--
-- demo\rosetta\Cursor_movement.exw
-- demo\rosetta\Cursor_movement.exw
-- ================================
-- ================================
--
--
-- These may vary by platform/hardware... (this program is ideal for sorting such things out)
-- These may vary by platform/hardware... (this program is ideal for sorting such things out)
--
--</span>
constant HOME = 327,
<span style="color: #008080;">constant</span> <span style="color: #000000;">HOME</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">327</span><span style="color: #0000FF;">,</span>
END = 335,
<span style="color: #000000;">END</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">335</span><span style="color: #0000FF;">,</span>
UP = 328,
<span style="color: #000000;">UP</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">328</span><span style="color: #0000FF;">,</span>
DOWN = 336,
<span style="color: #000000;">DOWN</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">336</span><span style="color: #0000FF;">,</span>
LEFT = 331,
<span style="color: #000000;">LEFT</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">331</span><span style="color: #0000FF;">,</span>
RIGHT = 333,
<span style="color: #000000;">RIGHT</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">333</span><span style="color: #0000FF;">,</span>
PGUP = 329, -- (goto top left)
<span style="color: #000000;">PGUP</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">329</span><span style="color: #0000FF;">,</span> <span style="color: #000080;font-style:italic;">-- (goto top left)</span>
PGDN = 337 -- (goto bottom right)
<span style="color: #000000;">PGDN</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">337</span> <span style="color: #000080;font-style:italic;">-- (goto bottom right)</span>
 
constant {maxl,maxc} = video_config()[VC_SCRNLINES..VC_SCRNCOLS]
<span style="color: #008080;">constant</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">maxl</span><span style="color: #0000FF;">,</span><span style="color: #000000;">maxc</span><span style="color: #0000FF;">}</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">video_config</span><span style="color: #0000FF;">()[</span><span style="color: #004600;">VC_SCRNLINES</span><span style="color: #0000FF;">..</span><span style="color: #000000;">VC_SCRNCOLS</span><span style="color: #0000FF;">]</span>
 
procedure move_cursor(integer dy, integer dx)
<span style="color: #008080;">procedure</span> <span style="color: #000000;">move_cursor</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">dy</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">integer</span> <span style="color: #000000;">dx</span><span style="color: #0000FF;">)</span>
integer {l,c} = sq_add(get_position(),{dy,dx})
<span style="color: #004080;">integer</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">l</span><span style="color: #0000FF;">,</span><span style="color: #000000;">c</span><span style="color: #0000FF;">}</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">sq_add</span><span style="color: #0000FF;">(</span><span style="color: #000000;">get_position</span><span style="color: #0000FF;">(),{</span><span style="color: #000000;">dy</span><span style="color: #0000FF;">,</span><span style="color: #000000;">dx</span><span style="color: #0000FF;">})</span>
if l>=1 and l<=maxl
<span style="color: #008080;">if</span> <span style="color: #000000;">l</span><span style="color: #0000FF;">>=</span><span style="color: #000000;">1</span> <span style="color: #008080;">and</span> <span style="color: #000000;">l</span><span style="color: #0000FF;"><=</span><span style="color: #000000;">maxl</span>
and c>=1 and c<=maxc then
<span style="color: #008080;">and</span> <span style="color: #000000;">c</span><span style="color: #0000FF;">>=</span><span style="color: #000000;">1</span> <span style="color: #008080;">and</span> <span style="color: #000000;">c</span><span style="color: #0000FF;"><=</span><span style="color: #000000;">maxc</span> <span style="color: #008080;">then</span>
position(l,c)
<span style="color: #7060A8;">position</span><span style="color: #0000FF;">(</span><span style="color: #000000;">l</span><span style="color: #0000FF;">,</span><span style="color: #000000;">c</span><span style="color: #0000FF;">)</span>
end if
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
end procedure
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
 
procedure move_to(integer ny=-1, integer nx=-1)
<span style="color: #008080;">procedure</span> <span style="color: #000000;">move_to</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">ny</span><span style="color: #0000FF;">=-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">integer</span> <span style="color: #000000;">nx</span><span style="color: #0000FF;">=-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">)</span>
integer {l,c} = get_position()
<span style="color: #004080;">integer</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">l</span><span style="color: #0000FF;">,</span><span style="color: #000000;">c</span><span style="color: #0000FF;">}</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">get_position</span><span style="color: #0000FF;">()</span>
if ny!=-1 then l = ny end if
<span style="color: #008080;">if</span> <span style="color: #000000;">ny</span><span style="color: #0000FF;">!=-</span><span style="color: #000000;">1</span> <span style="color: #008080;">then</span> <span style="color: #000000;">l</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">ny</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
if nx!=-1 then c = nx end if
<span style="color: #008080;">if</span> <span style="color: #000000;">nx</span><span style="color: #0000FF;">!=-</span><span style="color: #000000;">1</span> <span style="color: #008080;">then</span> <span style="color: #000000;">c</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">nx</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
position(l,c)
<span style="color: #7060A8;">position</span><span style="color: #0000FF;">(</span><span style="color: #000000;">l</span><span style="color: #0000FF;">,</span><span style="color: #000000;">c</span><span style="color: #0000FF;">)</span>
end procedure
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
 
procedure showkey(integer key)
<span style="color: #008080;">procedure</span> <span style="color: #000000;">showkey</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">key</span><span style="color: #0000FF;">)</span>
integer {l,c} = get_position()
<span style="color: #004080;">integer</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">l</span><span style="color: #0000FF;">,</span><span style="color: #000000;">c</span><span style="color: #0000FF;">}</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">get_position</span><span style="color: #0000FF;">()</span>
position(2,maxc-5)
<span style="color: #7060A8;">position</span><span style="color: #0000FF;">(</span><span style="color: #000000;">2</span><span style="color: #0000FF;">,</span><span style="color: #000000;">maxc</span><span style="color: #0000FF;">-</span><span style="color: #000000;">5</span><span style="color: #0000FF;">)</span>
?key
<span style="color: #0000FF;">?</span><span style="color: #000000;">key</span>
position(l,c)
<span style="color: #7060A8;">position</span><span style="color: #0000FF;">(</span><span style="color: #000000;">l</span><span style="color: #0000FF;">,</span><span style="color: #000000;">c</span><span style="color: #0000FF;">)</span>
end procedure
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
 
while 1 do
<span style="color: #008080;">while</span> <span style="color: #000000;">1</span> <span style="color: #008080;">do</span>
integer key = wait_key()
<span style="color: #004080;">integer</span> <span style="color: #000000;">key</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">wait_key</span><span style="color: #0000FF;">()</span>
if key=#1B then exit end if -- escape quits
<span style="color: #008080;">if</span> <span style="color: #000000;">key</span><span style="color: #0000FF;">=</span><span style="color: #000000;">#1B</span> <span style="color: #008080;">then</span> <span style="color: #008080;">exit</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span> <span style="color: #000080;font-style:italic;">-- escape quits</span>
showkey(key)
<span style="color: #000000;">showkey</span><span style="color: #0000FF;">(</span><span style="color: #000000;">key</span><span style="color: #0000FF;">)</span>
if key=HOME then move_to(nx:=1) -- home
<span style="color: #008080;">if</span> <span style="color: #000000;">key</span><span style="color: #0000FF;">=</span><span style="color: #000000;">HOME</span> <span style="color: #008080;">then</span> <span style="color: #000000;">move_to</span><span style="color: #0000FF;">(</span><span style="color: #000000;">nx</span><span style="color: #0000FF;">:=</span><span style="color: #000000;">1</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- home</span>
elsif key=END then move_to(nx:=maxc) -- end
<span style="color: #008080;">elsif</span> <span style="color: #000000;">key</span><span style="color: #0000FF;">=</span><span style="color: #000000;">END</span> <span style="color: #008080;">then</span> <span style="color: #000000;">move_to</span><span style="color: #0000FF;">(</span><span style="color: #000000;">nx</span><span style="color: #0000FF;">:=</span><span style="color: #000000;">maxc</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- end</span>
elsif key=UP then move_cursor(-1, 0) -- up
<span style="color: #008080;">elsif</span> <span style="color: #000000;">key</span><span style="color: #0000FF;">=</span><span style="color: #000000;">UP</span> <span style="color: #008080;">then</span> <span style="color: #000000;">move_cursor</span><span style="color: #0000FF;">(-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- up</span>
elsif key=DOWN then move_cursor(+1, 0) -- down
<span style="color: #008080;">elsif</span> <span style="color: #000000;">key</span><span style="color: #0000FF;">=</span><span style="color: #000000;">DOWN</span> <span style="color: #008080;">then</span> <span style="color: #000000;">move_cursor</span><span style="color: #0000FF;">(+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- down</span>
elsif key=LEFT then move_cursor( 0,-1) -- left
<span style="color: #008080;">elsif</span> <span style="color: #000000;">key</span><span style="color: #0000FF;">=</span><span style="color: #000000;">LEFT</span> <span style="color: #008080;">then</span> <span style="color: #000000;">move_cursor</span><span style="color: #0000FF;">(</span> <span style="color: #000000;">0</span><span style="color: #0000FF;">,-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- left</span>
elsif key=RIGHT then move_cursor( 0,+1) -- right
<span style="color: #008080;">elsif</span> <span style="color: #000000;">key</span><span style="color: #0000FF;">=</span><span style="color: #000000;">RIGHT</span> <span style="color: #008080;">then</span> <span style="color: #000000;">move_cursor</span><span style="color: #0000FF;">(</span> <span style="color: #000000;">0</span><span style="color: #0000FF;">,+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- right</span>
elsif key=PGUP then move_to(1,1) -- page_up
<span style="color: #008080;">elsif</span> <span style="color: #000000;">key</span><span style="color: #0000FF;">=</span><span style="color: #000000;">PGUP</span> <span style="color: #008080;">then</span> <span style="color: #000000;">move_to</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- page_up</span>
elsif key=PGDN then move_to(maxl,maxc) -- page_down
<span style="color: #008080;">elsif</span> <span style="color: #000000;">key</span><span style="color: #0000FF;">=</span><span style="color: #000000;">PGDN</span> <span style="color: #008080;">then</span> <span style="color: #000000;">move_to</span><span style="color: #0000FF;">(</span><span style="color: #000000;">maxl</span><span style="color: #0000FF;">,</span><span style="color: #000000;">maxc</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- page_down</span>
end if
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
end while</lang>
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<!--</syntaxhighlight>-->
 
=={{header|PicoLisp}}==
<langsyntaxhighlight PicoLisplang="picolisp">(call 'tput "cub1") # one position to the left
(call 'tput "cuf1") # one position to the right
(call 'tput "cuu1") # up one line
Line 936 ⟶ 1,129:
(call 'tput "hpa" (sys "COLUMNS")) # end of the line
(call 'tput "home") # top left corner
(call 'tput "cup" (sys "LINES") (sys "COLUMNS")) # bottom right corner</langsyntaxhighlight>
 
=={{header|Python}}==
{{libheader|curses}}
<langsyntaxhighlight Pythonlang="python">import curses
 
scr = curses.initscr()
Line 982 ⟶ 1,175:
y,x = scr.getmaxyx()
curses.move(y,x)
</syntaxhighlight>
</lang>
 
=={{header|Racket}}==
<langsyntaxhighlight lang="racket">
#lang racket
(require (planet neil/charterm:3:0))
Line 1,010 ⟶ 1,203:
(when continue?
(loop (on-key (charterm-read-key))))))
</syntaxhighlight>
</lang>
 
=={{header|Raku}}==
(formerly Perl 6)
<syntaxhighlight lang="raku" perl6line>shell "tput cub1"; # one position to the left
shell "tput cuf1"; # one position to the right
shell "tput cuu1"; # up one line
Line 1,026 ⟶ 1,219:
 
shell "tput hpa $cols"; # end of line
shell "tput cup $rows $cols"; # bottom right corner</langsyntaxhighlight>
 
=={{header|REXX}}==
Line 1,033 ⟶ 1,226:
 
This version &nbsp; ''only'' &nbsp; works with PC/REXX or Personal REXX.
<langsyntaxhighlight lang="rexx">/*REXX pgm demonstrates how to achieve movement of the terminal cursor. */
 
parse value scrsize() with sd sw /*find the display screen size. */
Line 1,055 ⟶ 1,248:
call cursor sd,sw /*move cursor to bot right corner*/
 
/*stick a fork in it, we're done.*/</langsyntaxhighlight>
 
=={{header|Ruby}}==
{{Works with|Ubuntu|22.04}}
<syntaxhighlight lang="ruby">require 'io/console'
 
def c (method, *args) # to avoid repeating sleeps
STDOUT.send(method, *args)
sleep 1
end
 
x, y = STDOUT.winsize
c(:clear_screen)
c(:cursor_right, 1)
c(:cursor_down, 1)
c(:cursor_left, 1)
c(:cursor_up, 1)
c(:goto_column, y)
c(:goto_column, 0)
c(:goto, 0, y)
c(:goto, x, 0)
</syntaxhighlight>
=={{header|Scala}}==
{{Works with|Ubuntu|14.04}}
<langsyntaxhighlight lang="scala">object CursorMovement extends App {
val ESC = "\u001B" // escape code
 
Line 1,077 ⟶ 1,290:
}
 
}</langsyntaxhighlight>
 
=={{header|Tcl}}==
{{trans|UNIX Shell}}
<langsyntaxhighlight lang="tcl"># Simplification wrapper for when we're actually affecting the terminal
proc tput args {
exec tput {*}$args >@stdout <@stdin
Line 1,098 ⟶ 1,311:
 
tput hpa $width; # end of line
tput cpu $height $width; # bottom right corner</langsyntaxhighlight>
 
=={{header|UNIX Shell}}==
<langsyntaxhighlight lang="bash">tput cub1 # one position to the left
tput cuf1 # one position to the right
tput cuu1 # up one line
Line 1,114 ⟶ 1,327:
 
tput hpa $WIDTH # end of line
tput cup $HEIGHT $WIDTH # bottom right corner</langsyntaxhighlight>
 
=={{header|Wren}}==
<langsyntaxhighlight ecmascriptlang="wren">import "timer" for Timer
import "io" for Stdout
 
System.write("\e[2J") // clear terminal
var esc = "\x1b"
System.write("\e[12;40H") // move to (12, 40)
 
System.write("%(esc)[2J") // clear terminal
System.write("%(esc)[12;40H") // move to (12, 40)
Stdout.flush()
Timer.sleep(2000)
System.write("%(esc)\e[D") // move left
Stdout.flush()
Timer.sleep(2000)
System.write("%(esc)\e[C") // move right
Stdout.flush()
Timer.sleep(2000)
System.write("%(esc)\e[A") // move up
Stdout.flush()
Timer.sleep(2000)
System.write("%(esc)\e[B") // move down
Stdout.flush()
Timer.sleep(2000)
System.write("%(esc)\e[G") // move to beginning of line
Stdout.flush()
Timer.sleep(2000)
System.write("%(esc)\e[79C") // move to end of line (assuming 80 column terminal)
Stdout.flush()
Timer.sleep(2000)
System.write("%(esc)\e[1;1H") // move to top left corner
Stdout.flush()
Timer.sleep(2000)
System.write("%(esc)\e[24;80H") // move to bottom right corner (assuming 80 x 24 terminal)
Stdout.flush()
Timer.sleep(2000)
System.write("%(esc)\e[1;1H") // home cursor again before quitting</langsyntaxhighlight>
 
=={{header|XPL0}}==
<langsyntaxhighlight XPL0lang="xpl0">include c:\cxpl\codes; \intrinsic 'code' declarations
int I, X, Y, W, H;
[Cursor(10, 13); \set cursor to arbitrary location on screen
Line 1,177 ⟶ 1,388:
Cursor(W-1, H-1); \move to bottom right corner
I:= ChIn(1);
]</langsyntaxhighlight>
 
Moving the cursor position beyond the terminal boundaries simply makes
Line 1,185 ⟶ 1,396:
{{trans|Go}}
zkl doesn't know anything about terminals but can print Ansi terminal codes:
<langsyntaxhighlight lang="zkl">print("\e[2J\e[6;3H"); // clear screen, move to an initial position
Atomic.sleep(1); // pause to let cursor blink
print("\e[D"); // left
Line 1,196 ⟶ 1,407:
Atomic.sleep(1);
print("\e[;H"); // top left
Atomic.sleep(1);</langsyntaxhighlight>
 
=={{header|ZX Spectrum Basic}}==
 
<langsyntaxhighlight lang="zxbasic">10 PRINT CHR$(8);:REM cursor one position left
20 PRINT CHR$(9);:REM cursor one position right
30 GO SUB 500: REM get cursor position
Line 1,226 ⟶ 1,437:
610 POKE 23688,33-cc
620 POKE 23689,24-cr
630 RETURN</langsyntaxhighlight>
9,476

edits