Terminal control/Cursor movement: Difference between revisions

m
syntax highlighting fixup automation
m (→‎{{header|Forth}}: fixed </LANG> tag)
m (syntax highlighting fixup automation)
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!}}==
<langsyntaxhighlight Actionlang="action!">PROC Wait(BYTE frames)
BYTE RTCLOK=$14
frames==+RTCLOK
Line 134:
 
Wait(d)
RETURN</langsyntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Cursor_movement.png Screenshot from Atari 8-bit computer]
Line 140:
=={{header|Ada}}==
{{libheader|ANSIAda}}
<langsyntaxhighlight Adalang="ada">with Ada.Text_Io;
 
with Ansi;
Line 176:
delay 2.000;
Put (Ansi.Restore);
end Movement;</langsyntaxhighlight>
 
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi}}
<syntaxhighlight lang="arm assembly">
<lang ARM Assembly>
 
/* ARM assembly Raspberry PI */
Line 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 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 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 386:
' Bottom right
R = ROWS
GOTOXY C,R</langsyntaxhighlight>
 
=={{header|BASIC}}==
Line 392:
{{works with|QBasic}}
 
<langsyntaxhighlight lang="qbasic">10 'move left
20 LOCATE , POS(0) - 1
30 'move right
Line 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 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 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 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 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 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 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 659:
System.Threading.Thread.Sleep(3000);
}
</syntaxhighlight>
</lang>
 
=={{header|Forth}}==
Line 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 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 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|Go}}==
===External commands===
<langsyntaxhighlight lang="go">package main
 
import (
Line 748:
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 771:
fmt.Print("\033[;H") // top left
time.Sleep(1 * time.Second)
}</langsyntaxhighlight>
===Ncurses===
{{libheader|curses}}
<langsyntaxhighlight lang="go">package main
 
import (
Line 833:
s.Refresh()
s.GetChar()
}</langsyntaxhighlight>
 
=={{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 851:
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 877:
Thread.sleep(3000)
println()
}</langsyntaxhighlight>
 
=={{header|Lasso}}==
<langsyntaxhighlight Lassolang="lasso">#!/usr/bin/lasso9
 
local(esc = decode_base64('Gw=='))
Line 925:
// 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 939:
Run["tput hpa "<>WIDTH] (* end of line *)
Run["tput cup "<>HEIGHT<>" "<> WIDTH] (* bottom right corner *)</langsyntaxhighlight>
 
=={{header|Nim}}==
<langsyntaxhighlight Nimlang="nim">import terminal
 
echo "Press the return key to go to next step."
Line 977:
# Move cursor to the bottom right corner.
setCursorPos(width - 1, height - 1)
waitUser()</langsyntaxhighlight>
 
=={{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 993:
 
system "tput cup $rows $cols"; # bottom right corner
sleep 1;</langsyntaxhighlight>
 
=={{header|Phix}}==
<!--<langsyntaxhighlight Phixlang="phix">(notonline)-->
<span style="color: #000080;font-style:italic;">--
-- demo\rosetta\Cursor_movement.exw
Line 1,050:
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<!--</langsyntaxhighlight>-->
 
=={{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 1,060:
(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 1,106:
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,134:
(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,150:
 
shell "tput hpa $cols"; # end of line
shell "tput cup $rows $cols"; # bottom right corner</langsyntaxhighlight>
 
=={{header|REXX}}==
Line 1,157:
 
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,179:
call cursor sd,sw /*move cursor to bot right corner*/
 
/*stick a fork in it, we're done.*/</langsyntaxhighlight>
 
=={{header|Scala}}==
{{Works with|Ubuntu|14.04}}
<langsyntaxhighlight lang="scala">object CursorMovement extends App {
val ESC = "\u001B" // escape code
 
Line 1,201:
}
 
}</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,222:
 
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,238:
 
tput hpa $WIDTH # end of line
tput cup $HEIGHT $WIDTH # bottom right corner</langsyntaxhighlight>
 
=={{header|Wren}}==
<langsyntaxhighlight lang="ecmascript">import "timer" for Timer
import "io" for Stdout
 
Line 1,272:
Stdout.flush()
Timer.sleep(2000)
System.write("\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,299:
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,307:
{{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,318:
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,348:
610 POKE 23688,33-cc
620 POKE 23689,24-cr
630 RETURN</langsyntaxhighlight>
10,333

edits