Terminal control/Cursor movement: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
m (syntax highlighting fixup automation)
m (→‎{{header|Wren}}: Changed to Wren S/H)
 
(3 intermediate revisions by 3 users not shown)
Line 699:
( 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}}==
Line 835 ⟶ 856:
}</syntaxhighlight>
 
=={{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}}
Line 1,181 ⟶ 1,250:
/*stick a fork in it, we're done.*/</syntaxhighlight>
 
=={{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}}
Line 1,241 ⟶ 1,330:
 
=={{header|Wren}}==
<syntaxhighlight lang="ecmascriptwren">import "timer" for Timer
import "io" for Stdout
 
9,482

edits