Terminal control/Hiding the cursor: Difference between revisions

m
syntax highlighting fixup automation
(Added solution for Action!)
m (syntax highlighting fixup automation)
Line 6:
 
=={{header|Action!}}==
<langsyntaxhighlight Actionlang="action!">PROC Wait(BYTE frames)
BYTE RTCLOK=$14
frames==+RTCLOK
Line 24:
CRSINH=0 PutE() ;put the new line character to force show the cursor
Wait(50)
RETURN</langsyntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Hiding_the_cursor.png Screenshot from Atari 8-bit computer]
Line 30:
=={{header|Ada}}==
{{libheader|ANSIAda}}
<langsyntaxhighlight Adalang="ada">with Ada.Text_Io;
 
with Ansi;
Line 46:
delay 2.000;
New_Line;
end Hiding;</langsyntaxhighlight>
 
=={{header|Arturo}}==
 
<langsyntaxhighlight lang="rebol">cursor false
print "hiding the cursor"
 
Line 56:
 
cursor true
print "showing the cursor"</langsyntaxhighlight>
 
=={{header|AutoHotkey}}==
Keep in mind that AHK is not built for the command line, so we must call the WinAPI directly.
<langsyntaxhighlight AHKlang="ahk">DllCall("AllocConsole") ; Create a console if not launched from one
hConsole := DllCall("GetStdHandle", UInt, STDOUT := -11)
 
Line 75:
 
FileAppend, `nCursor shown, CONOUT$
MsgBox</langsyntaxhighlight>
 
=={{header|BaCon}}==
<langsyntaxhighlight lang="freebasic">' Hiding the cursor for an ANSI compliant terminal
CURSOR OFF
CURSOR ON</langsyntaxhighlight>
 
=={{header|BASIC}}==
Line 86:
{{works with|FreeBASIC}}
 
<langsyntaxhighlight lang="qbasic">'hide the cursor:
LOCATE , , 0
'wait for a keypress...
SLEEP
'show the cursor:
LOCATE , , 1</langsyntaxhighlight>
 
==={{header|Applesoft BASIC}}===
<syntaxhighlight lang ApplesoftBasic="applesoftbasic">WAIT 49152,128</langsyntaxhighlight>
 
=={{header|BBC BASIC}}==
32-bit BBC BASICs:
<langsyntaxhighlight lang="bbcbasic"> OFF : REM Hide the cursor
WAIT 400
ON : REM Show the cursor again</langsyntaxhighlight>
All BBC BASICs:
<langsyntaxhighlight 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</langsyntaxhighlight>
 
=={{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.
<langsyntaxhighlight lang="befunge">"l52?["39*,,,,,, >v
"retnE sserP">:#,_v>
"h52?["39*,,,,,,@ >~</langsyntaxhighlight>
 
=={{header|C}}==
<syntaxhighlight lang="c">
<lang c>
/* Please note that curs_set is terminal dependent. */
 
Line 132:
return 0;
}
</syntaxhighlight>
</lang>
 
=={{header|C sharp|C#}}==
{{works with|Mono|1.2}}
{{works with|Visual C sharp|Visual C#|2003}}
<langsyntaxhighlight 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.");
Line 145:
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);
}</langsyntaxhighlight>
 
=={{header|C++}}==
<langsyntaxhighlight lang="cpp">
#include <Windows.h>
int main()
Line 160:
SetConsoleCursorInfo(out, &cursorInfo); // Apply changes
}
</syntaxhighlight>
</lang>
 
=={{header|Common Lisp}}==
<langsyntaxhighlight lang="lisp">
(defun sh (cmd)
#+clisp (shell cmd)
Line 177:
(show-cursor t)
(sleep 3)
</syntaxhighlight>
</lang>
 
==={{header|ncurses}}===
To interface the ncurses C library from Lisp, the ''croatoan'' library is used.
<langsyntaxhighlight lang="lisp">(defun hide-show-cursor ()
(with-screen (scr :input-echoing nil :input-blocking t)
(setf (cursor-visible-p scr) nil)
Line 191:
(format scr "cursor-visible-p: ~A" (cursor-visible-p scr))
(refresh scr)
(get-char scr)))</langsyntaxhighlight>
 
=={{header|FunL}}==
<langsyntaxhighlight lang="funl">import time.*
import console.*
 
hide()
sleep( 2 Second )
show()</langsyntaxhighlight>
 
=={{header|Furor}}==
Hide:
<syntaxhighlight lang="furor">
<lang Furor>
cursoroff
</syntaxhighlight>
</lang>
Show:
<syntaxhighlight lang="furor">
<lang Furor>
cursoron
</syntaxhighlight>
</lang>
 
=={{header|Go}}==
===External command===
<langsyntaxhighlight lang="go">package main
 
import (
Line 232:
cmd.Stdout = os.Stdout
return cmd.Run()
}</langsyntaxhighlight>
===Escape code===
(Not sure if this is ANSI, but it worked for me.)
<langsyntaxhighlight lang="go">package main
 
import (
Line 247:
fmt.Print("\033[?25h")
time.Sleep(3 * time.Second)
}</langsyntaxhighlight>
===Ncurses===
{{libheader|Curses}}
<langsyntaxhighlight lang="go">package main
 
import (
Line 269:
gc.Cursor(1)
s.GetChar()
}</langsyntaxhighlight>
 
=={{header|J}}==
With the definitions of [[Terminal_control/Coloured_text#J]]
<langsyntaxhighlight Jlang="j">smoutput HIDECURSOR
usleep(4e6) NB. wait 4 seconds
smoutput SHOWCURSOR
</syntaxhighlight>
</lang>
 
=={{header|Julia}}==
{{trans|Perl}}
<langsyntaxhighlight lang="julia">const ESC = "\u001B" # escape code
print("$ESC[?25l") # hide the cursor
print("Enter anything, press RETURN: ") # prompt shown
Line 287:
sleep(3)
println()
</syntaxhighlight>
</lang>
 
=={{header|Kotlin}}==
{{Works with|Ubuntu|14.04}}
<langsyntaxhighlight lang="scala">// version 1.1.2
 
fun main(args: Array<String>) {
Line 298:
print("\u001B[?25h") // display cursor
Thread.sleep(2000) // wait 2 more seconds before exiting
}</langsyntaxhighlight>
 
=={{header|Lasso}}==
<langsyntaxhighlight Lassolang="lasso">#!/usr/bin/lasso9
 
local(
Line 317:
 
// wait for 4 seconds to give time discover the cursor is back
sleep(4000)</langsyntaxhighlight>
 
=={{header|Locomotive Basic}}==
<langsyntaxhighlight lang="locobasic">10 CURSOR 0: REM hide cursor
20 FOR l = 1 TO 2000: REM delay
30 NEXT l
40 CURSOR 1: REM show cursor</langsyntaxhighlight>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">Run["tput civis"] (* Cursor hidden *)
Pause[2]
Run["tput cvvis"] (* Cursor Visible *)</langsyntaxhighlight>
 
=={{header|Nemerle}}==
<langsyntaxhighlight Nemerlelang="nemerle">using System.Console;
using System.Threading.Thread;
 
Line 343:
}
}
}</langsyntaxhighlight>
 
=={{header|Nim}}==
 
<langsyntaxhighlight lang="nim">import terminal
 
echo "Cursor hidden. Press a key to show the cursor and exit."
Line 353:
discard getCh()
stdout.showCursor()
</syntaxhighlight>
</lang>
 
=={{header|Perl}}==
<langsyntaxhighlight 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</langsyntaxhighlight>
 
=={{header|Phix}}==
<!--<langsyntaxhighlight Phixlang="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>
<!--</langsyntaxhighlight>-->
 
=={{header|PicoLisp}}==
<langsyntaxhighlight PicoLisplang="picolisp">(call "tput" "civis") # Invisible
(wait 1000)
(call "tput" "cvvis") # Visible</langsyntaxhighlight>
 
=={{header|PureBasic}}==
<langsyntaxhighlight PureBasiclang="purebasic">#cursorSize = 10 ;use a full sized cursor
 
If OpenConsole()
Line 387:
EndIf
ForEver
EndIf </langsyntaxhighlight>
 
Tested with <b>PB v5.60</b>
 
<langsyntaxhighlight PureBasiclang="purebasic">Procedure HideCursor ()
ConsoleCursor(0)
EndProcedure
Line 414:
ShowCursor(-0.5)
Print("press [Enter] to continue ... ") : Input()
EndIf</langsyntaxhighlight>
 
=={{header|Python}}==
With print:
<langsyntaxhighlight lang="python">print("\x1b[?25l") # hidden
print("\x1b[?25h") # shown
</syntaxhighlight>
</lang>
With curses:
<langsyntaxhighlight lang="python">import curses
import time
 
Line 433:
time.sleep(2)
curses.endwin()
</syntaxhighlight>
</lang>
 
=={{header|Quackery}}==
Line 442:
On some platforms the cursor visibility will not change until the output buffer is flushed by for example a cr/lf.
 
<langsyntaxhighlight Quackerylang="quackery"> [ $ &print("\x1b[?25l",end='')& python ] is hide ( --> )
 
[ $ &print("\x1b[?25h",end='')& python ] is show ( --> )</langsyntaxhighlight>
 
=={{header|R}}==
Line 450:
{{trans|Python}}
 
<langsyntaxhighlight Rlang="r">cat("\x1b[?25l") # Hide
Sys.sleep(2)
cat("\x1b[?25h") # Show</langsyntaxhighlight>
 
=={{header|Racket}}==
<langsyntaxhighlight lang="racket">
#lang racket
(void (system "tput civis")) (sleep 2) (void (system "tput cvvis"))
</syntaxhighlight>
</lang>
 
=={{header|Raku}}==
(formerly Perl 6)
<syntaxhighlight lang="raku" perl6line>say 'Hiding the cursor for 5 seconds...';
run 'tput', 'civis';
sleep 5;
run 'tput', 'cvvis';</langsyntaxhighlight>
 
=={{header|REXX}}==
{{works with|Regina REXX}}
<langsyntaxhighlight lang="rexx">/*REXX pgm calls a function in a shared library (regutil) to hide/show cursor.*/
z=rxfuncadd('sysloadfuncs', "regutil", 'sysloadfuncs') /*add a function lib.*/
if z\==0 then do /*test the return cod*/
Line 488:
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. */</langsyntaxhighlight>
'''output''' &nbsp;
<pre>
Line 497:
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
# Project : Terminal control/Hiding the cursor
 
Line 507:
? "Show Cursor using tput utility"
system("tput cnorm") # Normal
</syntaxhighlight>
</lang>
 
=={{header|Ruby}}==
<langsyntaxhighlight lang="ruby">require "curses"
include Curses
 
Line 523:
ensure
close_screen
end</langsyntaxhighlight>
 
=={{header|Scala}}==
<langsyntaxhighlight 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
}</langsyntaxhighlight>
 
=={{header|Tcl}}==
<langsyntaxhighlight lang="tcl">
proc cursorVisibility {{state normal}} {
switch -- $state {
Line 543:
exec -- >@stdout tput $op
}
</syntaxhighlight>
</lang>
Demo:
<langsyntaxhighlight lang="tcl">
foreach x {visible invisible normal} {
cursorVisibility $x
Line 553:
puts {}
}
</syntaxhighlight>
</lang>
 
=={{header|UNIX Shell}}==
 
<langsyntaxhighlight lang="sh">tput civis # Hide the cursor
sleep 5 # Sleep for 5 seconds
tput cnorm # Show the cursor</langsyntaxhighlight>
 
=={{header|Wren}}==
{{trans|Go}}
<langsyntaxhighlight lang="ecmascript">import "timer" for Timer
 
System.print("\e[?25l")
Timer.sleep(3000)
System.print("\e[?25h")
Timer.sleep(3000)</langsyntaxhighlight>
 
=={{header|XPL0}}==
<langsyntaxhighlight XPL0lang="xpl0">include c:\cxpl\codes; \intrinsic 'code' declarations
 
proc ShowCur(On); \Turn flashing cursor on or off
Line 585:
if ChIn(1) then []; \wait for keystroke
ShowCur(true); \turn on flashing cursor
]</langsyntaxhighlight>
 
=={{header|zkl}}==
{{trans|Go}}
Hide the cursor for three seconds on an ANSI terminal
<langsyntaxhighlight lang="zkl">print("\e[?25l");
Atomic.sleep(3);
print("\e[?25h");</langsyntaxhighlight>
 
{{omit from|ACL2}}
10,333

edits