Terminal control/Cursor movement: Difference between revisions

(→‎{{header|Kotlin}}: Updated example see https://github.com/dkandalov/rosettacode-kotlin for details)
Line 564:
shell "tput hpa $cols"; # end of line
shell "tput cup $rows $cols"; # bottom right corner</lang>
 
=={{header|Phix}}==
<lang Phix>--
-- demo\rosetta\Cursor_movement.exw
-- ================================
--
-- These may vary by platform/hardware... (this program is ideal for sorting such things out)
--
constant HOME = 327,
END = 335,
UP = 328,
DOWN = 336,
LEFT = 331,
RIGHT = 333,
PGUP = 329, -- (goto top left)
PGDN = 337 -- (goto bottom right)
 
constant {maxl,maxc} = video_config()[VC_SCRNLINES..VC_SCRNCOLS]
 
procedure move_cursor(integer dy, integer dx)
integer {l,c} = sq_add(get_position(),{dy,dx})
if l>=1 and l<=maxl
and c>=1 and c<=maxc then
position(l,c)
end if
end procedure
 
procedure move_to(integer ny=-1, integer nx=-1)
integer {l,c} = get_position()
if ny!=-1 then l = ny end if
if nx!=-1 then c = nx end if
position(l,c)
end procedure
 
procedure showkey(integer key)
integer {l,c} = get_position()
position(2,maxc-5)
?key
position(l,c)
end procedure
 
while 1 do
integer key = wait_key()
if key=#1B then exit end if -- escape quits
showkey(key)
if key=HOME then move_to(nx:=1) -- home
elsif key=END then move_to(nx:=maxc) -- end
elsif key=UP then move_cursor(-1, 0) -- up
elsif key=DOWN then move_cursor(+1, 0) -- down
elsif key=LEFT then move_cursor( 0,-1) -- left
elsif key=RIGHT then move_cursor( 0,+1) -- right
elsif key=PGUP then move_to(1,1) -- page_up
elsif key=PGDN then move_to(maxl,maxc) -- page_down
end if
end while</lang>
 
=={{header|PicoLisp}}==
Line 574 ⟶ 629:
(call 'tput "home") # top left corner
(call 'tput "cup" (sys "LINES") (sys "COLUMNS")) # bottom right corner</lang>
 
 
=={{header|Python}}==
7,806

edits