Terminal control/Cursor positioning: Difference between revisions
m
syntax highlighting fixup automation
m (→{{header|Phix}}: syntax coloured, marked p2js incompatible) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 8:
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
<syntaxhighlight lang="aarch64 assembly">
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program cursorPos64.s */
Line 64:
/* for this file see task include a file in language AArch64 assembly */
.include "../includeARM64.inc"
</syntaxhighlight>
=={{header|Action!}}==
<
Position(3,6)
Print("Hello")
RETURN</
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Cursor_positioning.png Screenshot from Atari 8-bit computer]
Line 75:
=={{header|Ada}}==
<
procedure Cursor_Pos is
Line 83:
Ada.Text_IO.Set_Col(3);
Ada.Text_IO.Put("Hello");
end Cursor_Pos;</
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi}}
<syntaxhighlight lang="arm assembly">
/* ARM assembly Raspberry PI */
Line 155:
bx lr @ return
</syntaxhighlight>
=={{header|Arturo}}==
<
print "Hello"</
=={{header|AutoHotkey}}==
{{works with|AutoHotkey_L}}
Remember that AHK is not built for the console, so we must call the WinAPI directly.
<
hConsole := DllCall( "GetStdHandle", int, STDOUT := -11 )
Line 179:
return out
return 0
}</
=={{header|Axe}}==
Since the rows and columns are zero-indexed, we must subtract 1 from both.
<
=={{header|BaCon}}==
<
GOTOXY 3,6
PRINT "Hello"</
The X Y in <code>GOTOXY</code> is Column Row order.
Line 194:
==={{header|Applesoft BASIC}}===
<
20 PRINT "HELLO"</
==={{header|IS-BASIC}}===
<
==={{header|Locomotive Basic}}===
<
20 PRINT "Hello"</
==={{header|ZX Spectrum Basic}}===
<
20 REM So we subtract one from the coordinates
30 PRINT AT 5,2 "Hello"</
==={{header|BBC BASIC}}===
<
==={{header|Commodore BASIC}}===
<
110 print chr$(14) :rem go to position 1,1
120 print:print:print:print
130 print tab(2) "Hello" </
=={{header|Befunge}}==
Assuming a terminal with support for ANSI escape sequences.
<
=={{header|Blast}}==
<
.begin
cursor 6,3
display "Hello!"
return
# This is the end of the script</
=={{header|C}}/{{header|C++}}==
Using ANSI escape sequence, where ESC[y;xH moves curser to row y, col x:<
int main()
{
printf("\033[6;3HHello\n");
return 0;
}</
The C version of the minesweeper game uses curses.
Line 242:
On Windows, using console API:
<
int main() {
Line 250:
WriteConsole(hConsole, "Hello", 5, NULL, NULL);
return 0;
}</
=={{header|C sharp|C#}}==
{{works with|Mono|1.2}}
{{works with|Visual C sharp|Visual C#|2003}}
<
{
Console.SetCursorPosition(3, 6);
Console.Write("Hello");
}</
=={{header|COBOL}}==
<
PROGRAM-ID. cursor-positioning.
Line 269:
GOBACK
.</
=={{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 nil)
(move scr 5 2)
Line 280:
(refresh scr)
;; wait for keypress
(get-char scr)))</
=={{header|D}}==
Line 291:
puts the cursor at line L and column C.
<syntaxhighlight lang="d">
import std.stdio;
Line 298:
writef("\033[6;3fHello");
}
</syntaxhighlight>
'''Output:'''
Line 314:
=={{header|Elena}}==
ELENA 4.x :
<
{
console.setCursorPosition(3,6).write("Hello")
}</
=={{header|Euphoria}}==
<
puts(1,"Hello")</
=={{header|F_Sharp|F#}}==
<
Console.SetCursorPosition(3, 6)
Console.Write("Hello")</
=={{header|Forth}}==
<
=={{header|Fortran}}==
===Intel Fortran on Windows===
<
use kernel32
implicit none
Line 343:
q = SetConsoleCursorPosition(hConsole, T_COORD(3, 6))
q = WriteConsole(hConsole, loc("Hello"), 5, NULL, NULL)
end program</
=={{header|FreeBASIC}}==
<
Sleep</
=={{header|Go}}==
===External command===
<
import (
Line 368:
cmd.Run()
fmt.Println("Hello")
}</
===ANSI escape codes===
<
import "fmt"
Line 376:
func main() {
fmt.Println("\033[2J\033[6;3HHello")
}</
===Ncurses===
{{libheader|curses}}
<
import (
Line 396:
s.Println("Hello")
s.GetChar()
}</
=={{header|Icon}} and {{header|Unicon}}==
If the OS has older termcap files, CUP is included with <tt>link ansi</tt>
<
writes(CUP(6,3), "Hello")
end
Line 407:
writes("\^[[",i,";",j,"H")
return
end</
=={{header|J}}==
Using terminal positioning verbs of [[Terminal_control/Coloured_text#J]]
<syntaxhighlight lang
=={{header|Julia}}==
<
gotoANSI(x, y) = print("$ESC[$(y);$(x)H")
Line 420:
gotoANSI(3, 6)
println("Hello")
</syntaxhighlight>
=={{header|Kotlin}}==
{{Works with|Ubuntu|14.04}}
<
fun main(args: Array<String>) {
print("\u001Bc") // clear screen first
println("\u001B[6;3HHello")
}</
=={{header|Lasso}}==
<
stdout( #esc + '[6;3HHello')</
=={{header|Liberty BASIC}}==
<
print "Hello"
</
=={{header|Logo}}==
<
type "Hello</
You can also draw positioned text on the turtle graphics window.
<
setxy 20 30 ; alternate way to set position
label "Hello</
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<
Print["Hello"]</
=={{header|Nim}}==
<
setCursorPos(3, 6)
echo "Hello"</
=={{header|NS-HUBASIC}}==
<
20 PRINT "HELLO"</
=={{header|OCaml}}==
Line 466:
Using the library [http://forge.ocamlcore.org/projects/ansiterminal/ ANSITerminal]:
<
#directory "+ANSITerminal"
#load "ANSITerminal.cma"
Line 476:
Trm.set_cursor 3 6;
Trm.print_string [] "Hello";
;;</
=={{header|Pascal}}==
<syntaxhighlight lang="pascal">
program cursor_pos;
uses crt;
Line 486:
write('Hello');
end.
</syntaxhighlight>
=={{header|Perl}}==
Using the Term::Cap module:
<
use Term::Cap;
Line 496:
print $t->Tgoto("cm", 2, 5); # 0-based
print "Hello";
</syntaxhighlight>
=={{header|Phix}}==
<!--<
<span style="color: #008080;">without</span> <span style="color: #008080;">js</span> <span style="color: #000080;font-style:italic;">-- position</span>
<span style="color: #7060A8;">position</span><span style="color: #0000FF;">(</span><span style="color: #000000;">6</span><span style="color: #0000FF;">,</span><span style="color: #000000;">3</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Hello"</span><span style="color: #0000FF;">)</span>
<!--</
=={{header|PHP}}==
<syntaxhighlight lang="php">
echo "\033[".$x.",".$y."H"; // Position line $y and column $x.
echo "\033[".$n."A"; // Up $n lines.
Line 513:
echo "\033[".$n."D"; // Backward $n columns.
echo "\033[2J"; // Clear the screen, move to (0,0).
</syntaxhighlight>
=={{header|PicoLisp}}==
<
(prin "Hello")</
=={{header|PowerShell}}==
The following will only work in the PowerShell console host. Most notably it will not work in the PowerShell ISE.
<
$Host.UI.Write('Hello')</
Alternatively, in any PowerShell host that uses the Windows console, one can directly use the .NET <code>Console</code> class:
<
[Console]::Write('Hello')</
=={{header|PureBasic}}==
<
ConsoleLocate(3,6)
Print("Hello")</
=={{header|Python}}==
Using ANSI escape sequence, where ESC[y;xH moves curser to row y, col x:<
On Windows it needs to import and init the [http://code.google.com/p/colorama/ colorama] module first.
ANSI sequences are not recognized in Windows console, here is a program using Windows API:
<
STD_OUTPUT_HANDLE = -11
Line 554:
windll.kernel32.WriteConsoleA(h, c_char_p(c), len(c), None, None)
print_at(6, 3, "Hello")</
=={{header|Quackery}}==
<
$ 'print("\033[' rot join
char ; join
Line 565:
python ] is cursor-at ( x y --> )
3 6 cursor-at say "Hello"</
=={{header|Racket}}==
<
#lang racket
(require (planet neil/charterm:3:0))
Line 575:
(charterm-cursor 3 6)
(displayln "Hello World"))
</syntaxhighlight>
=={{header|Raku}}==
(formerly Perl 6)
Assuming an ANSI terminal:
<syntaxhighlight lang="raku"
print 'Hello';</
=={{header|Retro}}==
<
: hello 3 6 at-xy "Hello" puts ;</
=={{header|REXX}}==
Line 591:
<br>added the functionality via different methods (such as functions and/or subroutines).
{{works with|PC/REXX, Personal REXX}}
<
call cursor 3,6 /*move the cursor to row 3, column 6. */
Line 601:
call scrwrite 40,60,'Hello.',,,14 /*another method ... in yellow. */
exit 0 /*stick a fork in it, we're all done. */</
=={{header|Ring}}==
<
# Project : Terminal control/Cursor positioning
Line 611:
next
see " Hello"
</syntaxhighlight>
Output:
<pre>
Line 624:
=={{header|Ruby}}==
{{libheader|curses}}
<
Curses.init_screen
Line 634:
ensure
Curses.close_screen
end</
=={{header|Scala}}==
{{Works with|Ubuntu|14.04}}
<
print("\u001Bc") // clear screen first
println("\u001B[6;3HHello")
}</
=={{header|Seed7}}==
Line 648:
''SetPos'' is based on terminfo respectively the Windows console API.
<
include "console.s7i";
Line 662:
# the program waits until Return/Enter is pressed.
readln;
end func;</
=={{header|Tcl}}==
<
puts "Hello"</
=={{header|UNIX Shell}}==
<
# number to obtain correct positioning.
tput cup 5 2</
=={{header|Whitespace}}==
Using ANSI escape sequence, where ESC[y;xH moves curser to row y, col x (see below):
<
Line 710:
</syntaxhighlight>
This solution was generated from the following pseudo-Assembly.
<
push "[6;3H"
push 27 ;ESC
Line 728:
1:
pop ret ;Pop counter and return</
=={{header|XPL0}}==
<
[Cursor(2, 5); \3rd column, 6th row
Text(0, "Hello"); \upper-left corner is coordinate 0, 0
]</
=={{header|Wren}}==
<
System.print("\e[6;3HHello") // move to (6, 3) and print 'Hello'</
=={{header|Z80 Assembly}}==
Uses Amstrad CPC, but other machines with similar terminal functions can do the job. (The BIOS calls will be different however.)
<
call &BB75 ;set text cursor according to HL
Line 760:
call &BB5A ;print accumulator as an ascii char to screen
inc hl ;next char
jr PrintString</
Line 766:
{{trans|C/C++}}
Using ANSI escape sequence, where ESC[y;xH moves curser to row y, col x:
<
{{omit from|ACL2}}
|