Terminal control/Hiding the cursor: Difference between revisions
Terminal control/Hiding the cursor (view source)
Revision as of 12:00, 13 February 2024
, 4 months ago→{{header|Wren}}: Changed to Wren S/H
m (→{{header|Wren}}: Changed to Wren S/H) |
|||
(37 intermediate revisions by 28 users not shown) | |||
Line 1:
{{task|Terminal control}}
[[Category:Terminal control]]
The task is to hide the cursor and show it again.
<br><br>
=={{header|Action!}}==
<syntaxhighlight lang="action!">PROC Wait(BYTE frames)
BYTE RTCLOK=$14
frames==+RTCLOK
WHILE frames#RTCLOK DO OD
RETURN
PROC Main()
BYTE CRSINH=$02F0 ;Controls visibility of cursor
Print("Hiding the cursor...")
Wait(50)
CRSINH=1 PutE() ;put the new line character to force hide the cursor
Wait(50)
Print("Showing the cursor...")
Wait(50)
CRSINH=0 PutE() ;put the new line character to force show the cursor
Wait(50)
RETURN</syntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Hiding_the_cursor.png Screenshot from Atari 8-bit computer]
=={{header|Ada}}==
{{libheader|ANSIAda}}
<syntaxhighlight lang="ada">with Ada.Text_Io;
with Ansi;
procedure Hiding is
use Ada.Text_Io;
begin
Put ("Hiding the cursor for 2.0 seconds...");
delay 0.500;
Put (Ansi.Hide);
delay 2.000;
Put ("And showing again.");
delay 0.500;
Put (Ansi.Show);
delay 2.000;
New_Line;
end Hiding;</syntaxhighlight>
=={{header|Arturo}}==
<syntaxhighlight lang="rebol">cursor false
print "hiding the cursor"
pause 2000
cursor true
print "showing the cursor"</syntaxhighlight>
=={{header|AutoHotkey}}==
Keep in mind that AHK is not built for the command line, so we must call the WinAPI directly.
<
hConsole := DllCall("GetStdHandle", UInt, STDOUT := -11)
Line 20 ⟶ 75:
FileAppend, `nCursor shown, CONOUT$
MsgBox</
=={{header|BaCon}}==
<syntaxhighlight lang="freebasic">' Hiding the cursor for an ANSI compliant terminal
CURSOR OFF
CURSOR ON</syntaxhighlight>
=={{header|BASIC}}==
{{works with|QBasic}}
{{works with|FreeBASIC}}
<
LOCATE , , 0
'wait for a keypress...
SLEEP
'show the cursor:
LOCATE , , 1</
==={{header|Applesoft BASIC}}===
<syntaxhighlight lang
=={{header|BBC BASIC}}==
32-bit BBC BASICs:
<syntaxhighlight lang="bbcbasic"> OFF : REM Hide the cursor
WAIT 400
ON : REM Show the cursor again</
All BBC BASICs:
<syntaxhighlight lang="bbcbasic"> VDU 23,1,0;0;0;0; : REM Hide the cursor
T%=TIME+400:REPEAT UNTIL TIME>T%
VDU 23,1,1;0;0;0; : REM Show the cursor again</syntaxhighlight>
==={{header|True BASIC}}===
<syntaxhighlight lang="qbasic">SET CURSOR "off"
PAUSE 2 !Pause 2 seconds
SET CURSOR "on"
END</syntaxhighlight>
=={{header|Befunge}}==
Assuming a terminal with support for ANSI escape sequences, this hides the cursor, waits for the user to press ''Enter'', and then shows the cursor again.
<
"retnE sserP">:#,_v>
"h52?["39*,,,,,,@ >~</
=={{header|C}}==
<syntaxhighlight lang="c">
/* Please note that curs_set is terminal dependent. */
#include<curses.h>
Line 69 ⟶ 138:
return 0;
}
</syntaxhighlight>
=={{header|C sharp|C#}}==
{{works with|Mono|1.2}}
{{works with|Visual C sharp|Visual C#|2003}}
<syntaxhighlight lang="csharp">static void Main(string[] args)
{
Console.Write("At the end of this line you will see the cursor, process will sleep for 5 seconds.");
System.Threading.Thread.Sleep(5000);
Console.CursorVisible = false;
Console.WriteLine();
Console.Write("At the end of this line you will not see the cursor, process will sleep for 5 seconds.");
System.Threading.Thread.Sleep(5000);
}</syntaxhighlight>
=={{header|C++}}==
<
#include <Windows.h>
int main()
Line 84 ⟶ 166:
SetConsoleCursorInfo(out, &cursorInfo); // Apply changes
}
</syntaxhighlight>
=={{header|Common Lisp}}==
<
(defun sh (cmd)
#+clisp (shell cmd)
Line 114 ⟶ 183:
(show-cursor t)
(sleep 3)
</syntaxhighlight>
==={{header|ncurses}}===
To interface the ncurses C library from Lisp, the ''croatoan'' library is used.
<syntaxhighlight lang="lisp">(defun hide-show-cursor ()
(with-screen (scr :input-echoing nil :input-blocking t)
(setf (cursor-visible-p scr) nil)
(format scr "cursor-visible-p: ~A~%" (cursor-visible-p scr))
(refresh scr)
;; wait for a keypress
(get-char scr)
(setf (cursor-visible-p scr) t)
(format scr "cursor-visible-p: ~A" (cursor-visible-p scr))
(refresh scr)
(get-char scr)))</syntaxhighlight>
=={{header|FunL}}==
<
import console.*
hide()
sleep( 2 Second )
show()</
=={{header|Furor}}==
Hide:
<syntaxhighlight lang="furor">
cursoroff
</syntaxhighlight>
Show:
<syntaxhighlight lang="furor">
cursoron
</syntaxhighlight>
=={{header|Peri}}==
Hide:
<syntaxhighlight lang="peri">
###sysinclude system.uh
cursoroff
</syntaxhighlight>
Show:
<syntaxhighlight lang="peri">
###sysinclude system.uh
cursoron
</syntaxhighlight>
=={{header|FreeBASIC}}==
<syntaxhighlight lang="vb">Locate , , 0 'Hide the cursor
Sleep 500 'waiting half second or a keypress...
Locate , , 1 'Show the cursor again
Sleep</syntaxhighlight>
=={{header|Go}}==
===External command===
<
import (
Line 146 ⟶ 259:
cmd.Stdout = os.Stdout
return cmd.Run()
}</
===Escape code===
(Not sure if this is ANSI, but it worked for me.)
<
import (
Line 161 ⟶ 274:
fmt.Print("\033[?25h")
time.Sleep(3 * time.Second)
}</
===Ncurses===
{{libheader|Curses}}
<
import (
Line 183 ⟶ 296:
gc.Cursor(1)
s.GetChar()
}</
=={{header|J}}==
With the definitions of [[Terminal_control/Coloured_text#J]]
<
usleep(4e6) NB. wait 4 seconds
smoutput SHOWCURSOR
</syntaxhighlight>
=={{header|jq}}==
{{works with|jq}}
Also works with gojq, the Go implementation.
'''Invocation''': jq -nrR -f hiding-the-cursor.jq
<syntaxhighlight lang="jq">
# Be busy for at least the given number of seconds,
# and emit the actual number of seconds that have elapsed.
def sleep($seconds):
now
| . as $now
| until( . - $now >= $seconds; now)
| . - $now ;
def demo:
def ESC: "\u001B";
def reset: "\(ESC)[0H\(ESC)[0J\(ESC)[?25h";
reset,
"Now you see it ...",
(sleep(2) | empty),
"\(ESC)[?25l", # hide the cursor
"... now you don't.",
"Press RETURN to reset the screen and cursor.",
(first(inputs) | empty),
reset;
demo
</syntaxhighlight>
=={{header|Julia}}==
{{trans|Perl}}
<syntaxhighlight lang="julia">const ESC = "\u001B" # escape code
print("$ESC[?25l") # hide the cursor
print("Enter anything, press RETURN: ") # prompt shown
input = readline() # but no cursor
print("$ESC[0H$ESC[0J$ESC[?25h") # reset, visible again
sleep(3)
println()
</syntaxhighlight>
=={{header|Kotlin}}==
{{Works with|Ubuntu|14.04}}
<syntaxhighlight lang
fun main(args: Array<String>) {
Line 201 ⟶ 355:
print("\u001B[?25h") // display cursor
Thread.sleep(2000) // wait 2 more seconds before exiting
}</
=={{header|Lasso}}==
<
local(
Line 220 ⟶ 374:
// wait for 4 seconds to give time discover the cursor is back
sleep(4000)</
=={{header|Locomotive Basic}}==
<
20 FOR l = 1 TO 2000: REM delay
30 NEXT l
40 CURSOR 1: REM show cursor</
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<
Pause[2]
Run["tput cvvis"] (* Cursor Visible *)</
=={{header|Nemerle}}==
<
using System.Threading.Thread;
Line 245 ⟶ 400:
}
}
}</
=={{header|
<syntaxhighlight lang="nim">import terminal
echo "Cursor hidden. Press a key to show the cursor and exit."
stdout.hideCursor()
discard getCh()
stdout.showCursor()
</syntaxhighlight>
=={{header|Perl}}==
<syntaxhighlight lang="perl">print "\e[?25l"; # hide the cursor
print "Enter anything, press RETURN: "; # prompt shown
$input = <>; # but no cursor
print "\e[0H\e[0J\e[?25h"; # reset, visible again</syntaxhighlight>
=={{header|Phix}}==
<!--<syntaxhighlight lang="phix">(notonline)-->
<span style="color: #7060A8;">cursor</span><span style="color: #0000FF;">(</span><span style="color: #004600;">NO_CURSOR</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">sleep</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">cursor</span><span style="color: #0000FF;">(</span><span style="color: #000000;">UNDERLINE_CURSOR</span><span style="color: #0000FF;">)</span>
<!--</syntaxhighlight>-->
=={{header|PHP}}==
<syntaxhighlight lang="php">#!/usr/bin/php
<?php
echo "\e[?25l"; // Cursor hide escape sequence
sleep(5);
echo "\e[?25h"; // Cursor show escape sequence
sleep(5);</syntaxhighlight>
=={{header|PicoLisp}}==
<
(wait 1000)
(call "tput" "cvvis") # Visible</
=={{header|PureBasic}}==
<
If OpenConsole()
Line 276 ⟶ 452:
EndIf
ForEver
EndIf </
Tested with <b>PB v5.60</b>
<
ConsoleCursor(0)
EndProcedure
Procedure ShowCursor (CursorHeight.b = 1)
If
If CursorHeight < 1 : CursorHeight = 1 : EndIf
ConsoleCursor(CursorHeight)
Line 303 ⟶ 479:
ShowCursor(-0.5)
Print("press [Enter] to continue ... ") : Input()
EndIf</
=={{header|Python}}==
With print:
<syntaxhighlight lang="python">print("\x1b[?25l") # hidden
print("\x1b[?25h") # shown
</syntaxhighlight>
With curses:
<syntaxhighlight lang="python">import curses
import time
stdscr = curses.initscr()
curses.curs_set(1) # visible
time.sleep(2)
curses.curs_set(0) # invisible
time.sleep(2)
curses.curs_set(1) # visible
time.sleep(2)
curses.endwin()
</syntaxhighlight>
=={{header|Quackery}}==
{{trans|Python}}
On some platforms the cursor visibility will not change until the output buffer is flushed by for example a cr/lf.
<syntaxhighlight lang="quackery"> [ $ &print("\x1b[?25l",end='')& python ] is hide ( --> )
[ $ &print("\x1b[?25h",end='')& python ] is show ( --> )</syntaxhighlight>
=={{header|R}}==
{{trans|Python}}
<syntaxhighlight lang="r">cat("\x1b[?25l") # Hide
Sys.sleep(2)
cat("\x1b[?25h") # Show</syntaxhighlight>
=={{header|Racket}}==
<syntaxhighlight lang="racket">
#lang racket
(void (system "tput civis")) (sleep 2) (void (system "tput cvvis"))
</syntaxhighlight>
=={{header|Raku}}==
(formerly Perl 6)
<syntaxhighlight lang="raku" line>say 'Hiding the cursor for 5 seconds...';
run 'tput', 'civis';
sleep 5;
run 'tput', 'cvvis';</syntaxhighlight>
=={{header|REXX}}==
{{works with|Regina REXX}}
<
z=rxfuncadd('sysloadfuncs', "regutil", 'sysloadfuncs') /*add a function lib.*/
if z\==0 then do /*test the return cod*/
Line 326 ⟶ 553:
call syscurstate 'on' /*(unhide) the displaying of the cursor*/
say 'showing of the cursor is now on' /*inform that the cursor is now showing*/
/*stick a fork in it, we're all done. */</
'''output'''
<pre>
Line 333 ⟶ 560:
showing of the cursor is now on
</pre>
=={{header|Ring}}==
<syntaxhighlight lang="ring">
# Project : Terminal control/Hiding the cursor
load "stdlib.ring"
# Linux
? "Hide Cursor using tput utility"
system("tput civis") # Invisible
sleep(10)
? "Show Cursor using tput utility"
system("tput cnorm") # Normal
</syntaxhighlight>
=={{header|Ruby}}==
<
include Curses
Line 348 ⟶ 588:
ensure
close_screen
end</
=={{header|Scala}}==
<syntaxhighlight lang="scala">object Main extends App {
print("\u001B[?25l") // hide cursor
Thread.sleep(2000) // wait 2 seconds before redisplaying cursor
print("\u001B[?25h") // display cursor
Thread.sleep(2000) // wait 2 more seconds before exiting
}</syntaxhighlight>
=={{header|Tcl}}==
<syntaxhighlight lang="tcl">
proc cursorVisibility {{state normal}} {
switch -- $state {
}
exec -- >@stdout tput $op
}
</syntaxhighlight>
Demo:
<syntaxhighlight lang
foreach x {visible invisible normal} {
cursorVisibility $x
puts -nonewline "$x cursor -> "
flush stdout
after 3000
puts {}
}
</syntaxhighlight>
=={{header|UNIX Shell}}==
<
sleep 5 # Sleep for 5 seconds
tput cnorm # Show the cursor</
=={{header|Wren}}==
{{trans|Go}}
<syntaxhighlight lang="wren">import "timer" for Timer
System.print("\e[?25l")
Timer.sleep(3000)
System.print("\e[?25h")
Timer.sleep(3000)</syntaxhighlight>
=={{header|XPL0}}==
<
proc ShowCur(On); \Turn flashing cursor on or off
Line 395 ⟶ 650:
if ChIn(1) then []; \wait for keystroke
ShowCur(true); \turn on flashing cursor
]</
=={{header|zkl}}==
{{trans|Go}}
Hide the cursor for three seconds on an ANSI terminal
<
Atomic.sleep(3);
print("\e[?25h");</
{{omit from|ACL2}}
|