Terminal control/Cursor movement: Difference between revisions
Terminal control/Cursor movement (view source)
Revision as of 11:47, 13 February 2024
, 3 months ago→{{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">
/* 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>
=={{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">
/* ARM assembly Raspberry PI */
Line 182 ⟶ 267:
bx lr @ return
</syntaxhighlight>
=={{header|AutoHotkey}}==
<
hConsole:=DllCall("GetConsoleWindow","UPtr")
Stdout:=FileOpen(DllCall("GetStdHandle", "int", -11, "ptr"), "h `n")
Line 258 ⟶ 343:
bufferheight:=NumGet(&struct,2,"UShort")
return 1
}</
=={{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.
<
Output(X+1,Y)
Output(X,Y-1)
Line 269 ⟶ 354:
Output(15,Y)
Output(0,0)
Output(15,7)</
=={{header|BaCon}}==
<
' Default number of positions, if not specified, is 1.
Line 301 ⟶ 386:
' Bottom right
R = ROWS
GOTOXY C,R</
=={{header|BASIC}}==
Line 307 ⟶ 392:
{{works with|QBasic}}
<
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</
==={{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
<
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>
=={{header|BBC BASIC}}==
<
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</
=={{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">
#include<conio.h>
#include<dos.h>
Line 521 ⟶ 606:
return 0;
}
</syntaxhighlight>
=={{header|Common Lisp}}==
==={{header|ncurses}}===
To interface the ncurses C library from Lisp, the ''croatoan'' library is used.
<
(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)))</
=={{header|C sharp|C#}}==
{{works with|Mono|1.2}}
{{works with|Visual C sharp|Visual C#|2003}}
<
{
//There will be a 3 second pause between each cursor movement.
Line 574 ⟶ 659:
System.Threading.Thread.Sleep(3000);
}
</syntaxhighlight>
=={{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.
<
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> ;</
Rosetta Task
<
( 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>
=={{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===
<
import (
Line 663 ⟶ 769:
cmd.Stdout = os.Stdout
return cmd.Run()
}</
===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.
<
import (
Line 686 ⟶ 792:
fmt.Print("\033[;H") // top left
time.Sleep(1 * time.Second)
}</
===Ncurses===
{{libheader|curses}}
<
import (
Line 748 ⟶ 854:
s.Refresh()
s.GetChar()
}</
=={{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}}
<
const moves = Dict( "left" => "[1D", "right" => "[1C", "up" => "[1A", "down" => "[1B",
"linestart" => "[9D", "topleft" => "[H", "bottomright" => "[24;79H")
Line 766 ⟶ 920:
println()
println()
</syntaxhighlight>
=={{header|Kotlin}}==
{{Works with|Ubuntu|14.04}}
<
const val ESC = "\u001B" // escape code
Line 792 ⟶ 946:
Thread.sleep(3000)
println()
}</
=={{header|Lasso}}==
<
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)</
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<
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 *)</
=={{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}}
<
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;</
=={{header|Phix}}==
<!--<syntaxhighlight lang="phix">(notonline)-->
<span style="color: #000080;font-style:italic;">--
-- demo\rosetta\Cursor_movement.exw
-- ================================
--
-- These may vary by platform/hardware... (this program is ideal for sorting such things out)
--</span>
<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>
<span style="color: #000000;">END</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">335</span><span style="color: #0000FF;">,</span>
<span style="color: #000000;">UP</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">328</span><span style="color: #0000FF;">,</span>
<span style="color: #000000;">DOWN</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">336</span><span style="color: #0000FF;">,</span>
<span style="color: #000000;">LEFT</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">331</span><span style="color: #0000FF;">,</span>
<span style="color: #000000;">RIGHT</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">333</span><span style="color: #0000FF;">,</span>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
<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>
<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>
<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>
<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>
<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>
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
<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>
<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>
<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>
<span style="color: #0000FF;">?</span><span style="color: #000000;">key</span>
<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>
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
<span style="color: #008080;">while</span> <span style="color: #000000;">1</span> <span style="color: #008080;">do</span>
<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>
<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>
<span style="color: #000000;">showkey</span><span style="color: #0000FF;">(</span><span style="color: #000000;">key</span><span style="color: #0000FF;">)</span>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<!--</syntaxhighlight>-->
=={{header|PicoLisp}}==
<
(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</
=={{header|Python}}==
{{libheader|curses}}
<
scr = curses.initscr()
Line 982 ⟶ 1,175:
y,x = scr.getmaxyx()
curses.move(y,x)
</syntaxhighlight>
=={{header|Racket}}==
<
#lang racket
(require (planet neil/charterm:3:0))
Line 1,010 ⟶ 1,203:
(when continue?
(loop (on-key (charterm-read-key))))))
</syntaxhighlight>
=={{header|Raku}}==
(formerly Perl 6)
<syntaxhighlight lang="raku"
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</
=={{header|REXX}}==
Line 1,033 ⟶ 1,226:
This version ''only'' works with PC/REXX or Personal REXX.
<
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.*/</
=={{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}}
<
val ESC = "\u001B" // escape code
Line 1,077 ⟶ 1,290:
}
}</
=={{header|Tcl}}==
{{trans|UNIX Shell}}
<
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</
=={{header|UNIX Shell}}==
<
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</
=={{header|Wren}}==
<
import "io" for Stdout
System.write("\e[2J") // clear terminal
System.write("\e[12;40H") // move to (12, 40)
Stdout.flush()
Timer.sleep(2000)
System.write("
Stdout.flush()
Timer.sleep(2000)
System.write("
Stdout.flush()
Timer.sleep(2000)
System.write("
Stdout.flush()
Timer.sleep(2000)
System.write("
Stdout.flush()
Timer.sleep(2000)
System.write("
Stdout.flush()
Timer.sleep(2000)
System.write("
Stdout.flush()
Timer.sleep(2000)
System.write("
Stdout.flush()
Timer.sleep(2000)
System.write("
Stdout.flush()
Timer.sleep(2000)
System.write("
=={{header|XPL0}}==
<
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);
]</
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:
<
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);</
=={{header|ZX Spectrum Basic}}==
<
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</
|