Terminal control/Ringing the terminal bell: Difference between revisions

From Rosetta Code
Content added Content deleted
m (→‎{{header|REXX}}: added notes about ASCII vs. EBCDIC machines, added comments and examples.)
(alarm in BLC)
 
(32 intermediate revisions by 17 users not shown)
Line 10: Line 10:
In most terminals, if the &nbsp; [[wp:Bell character|Bell character]] &nbsp; (ASCII code '''7''', &nbsp; <big><code> \a </code></big> in C) &nbsp; is printed by the program, it will cause the terminal to ring its bell. &nbsp; This is a function of the terminal, and is independent of the programming language of the program, other than the ability to print a particular character to standard out.
In most terminals, if the &nbsp; [[wp:Bell character|Bell character]] &nbsp; (ASCII code '''7''', &nbsp; <big><code> \a </code></big> in C) &nbsp; is printed by the program, it will cause the terminal to ring its bell. &nbsp; This is a function of the terminal, and is independent of the programming language of the program, other than the ability to print a particular character to standard out.
<br><br>
<br><br>

=={{header|11l}}==
<syntaxhighlight lang="11l">print("\a")</syntaxhighlight>


=={{header|6800 Assembly}}==
=={{header|6800 Assembly}}==
<lang m68k> .cr 6800
<syntaxhighlight lang="m68k"> .cr 6800
.tf bel6800.obj,AP1
.tf bel6800.obj,AP1
.lf bel6800
.lf bel6800
Line 34: Line 37:
jsr outeee ; and print it
jsr outeee ; and print it
swi ;Return to the monitor
swi ;Return to the monitor
.en</lang>
.en</syntaxhighlight>


=={{header|Ada}}==
=={{header|8086 Assembly}}==
===Using stdout===
{{trans|X86 Assembly}}
This is how it's ''supposed'' to be done:
<syntaxhighlight lang="asm">.model small
.stack 1024


.data
<lang ada>with Ada.Text_IO; use Ada.Text_IO;

.code

start: mov ah, 02h ;character output
mov dl, 07h ;bell code
int 21h ;call MS-DOS

mov ax, 4C00h ;exit
int 21h ;return to MS-DOS
end start</syntaxhighlight>

But I couldn't hear anything on DOSBox when doing this.

===The hard way===
This version takes direct control over the PC's beeper to produce a tone whenever <code>BEL</code> is passed to <code>PrintChar</code>.
<syntaxhighlight lang="asm">.model small
.stack 1024

.data

.code

start:

mov al,7
call PrintChar

mov ax,4C00h
int 21h ;return to DOS
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
PrintChar: ;Print AL to screen
push cx
push bx
push ax
cmp al,7
jne skipBEL
call RingBell
jmp done_PrintChar
skipBEL:
mov bl,15 ;text color will be white
mov ah,0Eh
int 10h ;prints ascii code stored in AL to the screen (this is a slightly different putc syscall)
done_PrintChar:
pop ax
pop bx
pop cx
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
RingBell:
push ax
push cx
push dx
;if BEL is the argument passed to PrintChar, it will call this function and not actually print anything or advance the cursor
;this uses the built-in beeper to simulate a beep

mov al,10110110b ;select counter 2, 16-bit mode
out 43h, al
mov ax,0C00h ;set pitch of beep - this is somewhat high but isn't too annoying. Feel free to adjust this value
out 42h,al
mov al,ah
out 42h,al


mov al,3
out 61h,al ;enable sound and timer mode

mov cx,0FFFFh
mov dx,0Fh ;set up loop counters
beepdelay: ;delay lasts about half a second
loop beepdelay
mov cx,0FFFFh
dec dx
jnz beepdelay
mov al,0 ;mute
out 61h,al ;cut the sound

; mov bl,15
; mov ax,0E20h ;print a spacebar to the terminal
; int 10h ;uncomment these 3 lines if you want the BEL to "take up space" in the output stream
pop dx
pop cx
pop ax
ret

end start</syntaxhighlight>

=={{header|Action!}}==
<syntaxhighlight lang="action!">PROC Wait(BYTE frames)
BYTE RTCLOK=$14
frames==+RTCLOK
WHILE frames#RTCLOK DO OD
RETURN

PROC Main()
BYTE
i,n=[3],
CH=$02FC ;Internal hardware value for last key pressed

PrintF("Press any key to hear %B bells...",n)
DO UNTIL CH#$FF OD
CH=$FF

FOR i=1 TO n
DO
Put(253) ;buzzer
Wait(20)
OD
Wait(100)
RETURN</syntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Ringing_the_terminal_bell.png Screenshot from Atari 8-bit computer]

=={{header|Ada}}==
<syntaxhighlight lang="ada">with Ada.Text_IO; use Ada.Text_IO;
with Ada.Characters.Latin_1;
with Ada.Characters.Latin_1;


Line 44: Line 169:
begin
begin
Put(Ada.Characters.Latin_1.BEL);
Put(Ada.Characters.Latin_1.BEL);
end Bell;</lang>
end Bell;</syntaxhighlight>


=={{header|Applescript}}==
=={{header|Applescript}}==
<lang applescript>beep</lang>
<syntaxhighlight lang="applescript">beep</syntaxhighlight>

=={{header|Arturo}}==
<syntaxhighlight lang="rebol">print "\a"</syntaxhighlight>


=={{header|Asymptote}}==
=={{header|Asymptote}}==
<lang Asymptote>beep()</lang>
<syntaxhighlight lang="asymptote">beep()</syntaxhighlight>
See [http://asymptote.sourceforge.net/doc/Data-types.html#index-g_t_0040code_007bbeep_007d-287 beep() in the Asymptote manual].
See [http://asymptote.sourceforge.net/doc/Data-types.html#index-g_t_0040code_007bbeep_007d-287 beep() in the Asymptote manual].


=={{header|AutoHotkey}}==
=={{header|AutoHotkey}}==
<syntaxhighlight lang="autohotkey">
<lang AutoHotkey>
fileappend, `a, *
fileappend, `a, *
</syntaxhighlight>
</lang>


This requires that you compile the exe in console mode (see Lexikos script to change this) or pipe the file
This requires that you compile the exe in console mode (see Lexikos script to change this) or pipe the file
Line 62: Line 190:


=={{header|AWK}}==
=={{header|AWK}}==
<syntaxhighlight lang="awk">BEGIN {

<lang awk>BEGIN {
print "\a" # Ring the bell
print "\a" # Ring the bell
}</lang>
}</syntaxhighlight>


=={{header|BASIC}}==
=={{header|BASIC}}==
Line 71: Line 198:
==={{header|Applesoft BASIC}}===
==={{header|Applesoft BASIC}}===


<lang Applesoft BASIC> 10 PRINT CHR$ (7);</lang>
<syntaxhighlight lang="applesoft basic"> 10 PRINT CHR$ (7);</syntaxhighlight>


==={{header|Integer BASIC}}===
==={{header|Integer BASIC}}===


You can't see it, but the bell character (Control G) is embedded in what looks like an empty string on line 10.
You can't see it, but the bell character (Control G) is embedded in what looks like an empty string on line 10.
<lang Integer BASIC> 10 PRINT "";: REM ^G IN QUOTES
<syntaxhighlight lang="integer basic"> 10 PRINT "";: REM ^G IN QUOTES
20 END</lang>
20 END</syntaxhighlight>


==={{header|IS-BASIC}}===
==={{header|IS-BASIC}}===
<lang IS-BASIC>PING</lang>
<syntaxhighlight lang="is-basic">PING</syntaxhighlight>


==={{header|Locomotive Basic}}===
==={{header|Locomotive Basic}}===


<lang locobasic>10 PRINT CHR$(7)</lang>
<syntaxhighlight lang="locobasic">10 PRINT CHR$(7)</syntaxhighlight>


=== {{header|ZX Spectrum Basic}} ===
==={{header|ZX Spectrum Basic}}===


The ZX Spectrum had a speaker, rather than a bell. Here we use middle C as a bell tone, but we could produce a different note by changing the final zero to a different value.
The ZX Spectrum had a speaker, rather than a bell. Here we use middle C as a bell tone, but we could produce a different note by changing the final zero to a different value.


<lang basic>BEEP 0.2,0</lang>
<syntaxhighlight lang="basic">BEEP 0.2,0</syntaxhighlight>


=={{header|Batch File}}==
=={{header|Batch File}}==
Source: [http://www.dostips.com/forum/viewtopic.php?f=3&t=5860 Here]
Source: [http://www.dostips.com/forum/viewtopic.php?f=3&t=5860 Here]
<lang dos>@echo off
<syntaxhighlight lang="dos">@echo off
for /f %%. in ('forfiles /m "%~nx0" /c "cmd /c echo 0x07"') do set bell=%%.
for /f %%. in ('forfiles /m "%~nx0" /c "cmd /c echo 0x07"') do set bell=%%.
echo %bell%</lang>
echo %bell%</syntaxhighlight>


=={{header|BBC BASIC}}==
=={{header|BBC BASIC}}==
Assuming that the platform the program is running on rings the bell when CHR$7 is sent to the VDU driver:
Assuming that the platform the program is running on rings the bell when CHR$7 is sent to the VDU driver:


<lang bbcbasic>VDU 7</lang>
<syntaxhighlight lang="bbcbasic">VDU 7</syntaxhighlight>


=={{header|Bc}}==
=={{header|bc}}==
<lang Bc>print "\a"</lang>
<syntaxhighlight lang="bc">print "\a"</syntaxhighlight>


=={{header|beeswax}}==
=={{header|beeswax}}==
<syntaxhighlight lang="beeswax">_7}</syntaxhighlight>

<lang beeswax>_7}</lang>


=={{header|Befunge}}==
=={{header|Befunge}}==
<lang befunge>7,@</lang>
<syntaxhighlight lang="befunge">7,@</syntaxhighlight>

=={{header|Binary Lambda Calculus}}==

The 2-byte BLC program <code>20 07</code> in hex outputs ASCII code 7.


=={{header|Bracmat}}==
=={{header|Bracmat}}==
Run Bracmat in interactive mode (start Bracmat without command line arguments) and enter the following after the Bracmat prompt <code>{?}</code>:
Run Bracmat in interactive mode (start Bracmat without command line arguments) and enter the following after the Bracmat prompt <code>{?}</code>:
<lang bracmat>\a</lang>
<syntaxhighlight lang="bracmat">\a</syntaxhighlight>
Alternatively, run Bracmat non-interactively. In DOS, you write
Alternatively, run Bracmat non-interactively. In DOS, you write
<pre>bracmat "put$\a"</pre>
<pre>bracmat "put$\a"</pre>
Line 124: Line 254:
Assuming the output stream is connected to a TTY, printing BEL should ring its bell.
Assuming the output stream is connected to a TTY, printing BEL should ring its bell.


<lang brainfuck> I
<syntaxhighlight lang="brainfuck"> I
+
+
+ +
+ +
+++
+++
+-+-+
+-+-+
.</lang>
.</syntaxhighlight>


=={{header|C}}==
=={{header|C}}==
<syntaxhighlight lang="c">#include <stdio.h>

<lang c>#include <stdio.h>
int main() {
int main() {
printf("\a");
printf("\a");
return 0;
return 0;
}</lang>
}</syntaxhighlight>

=={{header|C++}}==
<lang cpp>#include <iostream>

int main() {
std::cout << "\a";
return 0;
}</lang>


=={{header|C sharp|C#}}==
=={{header|C sharp|C#}}==
Inside a function:
Inside a function:
<lang csharp>// the simple version:
<syntaxhighlight lang="csharp">// the simple version:
System.Console.Write("\a"); // will beep
System.Console.Write("\a"); // will beep
System.Threading.Thread.Sleep(1000); // will wait for 1 second
System.Threading.Thread.Sleep(1000); // will wait for 1 second
Line 157: Line 278:
// System.Console.Beep() also accepts (int)hertz and (int)duration in milliseconds:
// System.Console.Beep() also accepts (int)hertz and (int)duration in milliseconds:
System.Console.Beep(440, 2000); // default "concert pitch" for 2 seconds
System.Console.Beep(440, 2000); // default "concert pitch" for 2 seconds
</syntaxhighlight>
</lang>

=={{header|C++}}==
<syntaxhighlight lang="cpp">#include <iostream>

int main() {
std::cout << "\a";
return 0;
}</syntaxhighlight>


=={{header|Clojure}}==
=={{header|Clojure}}==
<lang clojure>(println (char 7))</lang>
<syntaxhighlight lang="clojure">(println (char 7))</syntaxhighlight>


=={{header|COBOL}}==
=={{header|COBOL}}==
Using the standard screen section:
Standard compliant:
{{works with|X/Open COBOL}}
<lang cobol>DISPLAY SPACE WITH BELL</lang>
{{works with|COBOL 2002}}
<syntaxhighlight lang="cobol"> IDENTIFICATION DIVISION.
PROGRAM-ID. ring-terminal-bell.

DATA DIVISION.
SCREEN SECTION.
01 ringer BELL.

PROCEDURE DIVISION.
DISPLAY ringer.
STOP RUN.

END PROGRAM ring-terminal-bell.</syntaxhighlight>

Using the ASCII code directly:
{{works with|COBOL-85}}
<syntaxhighlight lang="cobol"> *> Tectonics: cobc -xj ring-terminal-bell.cob --std=cobol85
IDENTIFICATION DIVISION.
PROGRAM-ID. ring-ascii-bell.

ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
OBJECT-COMPUTER.
PROGRAM COLLATING SEQUENCE IS ASCII.
SPECIAL-NAMES.
ALPHABET ASCII IS STANDARD-1.

PROCEDURE DIVISION.
DISPLAY FUNCTION CHAR(8) WITH NO ADVANCING.
*> COBOL indexes starting from 1.
STOP RUN.

END PROGRAM ring-ascii-bell.</syntaxhighlight>


{{works with|Visual COBOL}}
{{works with|Visual COBOL}}
<lang cobol> IDENTIFICATION DIVISION.
<syntaxhighlight lang="cobol"> IDENTIFICATION DIVISION.
PROGRAM-ID. mf-bell.
PROGRAM-ID. mf-bell.

DATA DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
WORKING-STORAGE SECTION.
01 bell-code PIC X USAGE COMP-X VALUE 22.
01 bell-code PIC X USAGE COMP-X VALUE 22.
01 dummy-param PIC X.
01 dummy-param PIC X.

PROCEDURE DIVISION.
PROCEDURE DIVISION.
CALL X"AF" USING bell-code, dummy-param
CALL X"AF" USING bell-code, dummy-param
GOBACK.

GOBACK
.</lang>
END PROGRAM mf-bell.</syntaxhighlight>


=={{header|Common Lisp}}==
=={{header|Common Lisp}}==
<lang lisp>
<syntaxhighlight lang="lisp">
(format t "~C" (code-char 7))
(format t "~C" (code-char 7))
</syntaxhighlight>
</lang>


=={{header|D}}==
=={{header|D}}==
<lang d>void main() {
<syntaxhighlight lang="d">void main() {
import std.stdio;
import std.stdio;
writeln('\a');
writeln('\a');
}</lang>
}</syntaxhighlight>

=={{header|dc}}==
<syntaxhighlight lang="dc">7P</syntaxhighlight>


=={{header|Delphi}}==
=={{header|Delphi}}==
<lang Delphi>program TerminalBell;
<syntaxhighlight lang="delphi">program TerminalBell;


{$APPTYPE CONSOLE}
{$APPTYPE CONSOLE}
Line 199: Line 364:
begin
begin
Writeln(#7);
Writeln(#7);
end.</lang>
end.</syntaxhighlight>


=={{header|E}}==
=={{header|E}}==
<lang e>print("\u0007")</lang>
<syntaxhighlight lang="e">print("\u0007")</syntaxhighlight>


=={{header|Emacs Lisp}}==
=={{header|Emacs Lisp}}==
<lang lisp>(ding) ;; ring the bell
<syntaxhighlight lang="lisp">(ding) ;; ring the bell
(beep) ;; the same thing</lang>
(beep) ;; the same thing</syntaxhighlight>
On a tty or in <code>-batch</code> mode this emits a BEL character. In a GUI it does whatever suits the window system. Variables <code>visible-bell</code> and <code>ring-bell-function</code> can control the behaviour.
On a tty or in <code>-batch</code> mode this emits a BEL character. In a GUI it does whatever suits the window system. Variables <code>visible-bell</code> and <code>ring-bell-function</code> can control the behaviour.


Line 215: Line 380:


=={{header|F_Sharp|F#}}==
=={{header|F_Sharp|F#}}==
<lang fsharp>open System
<syntaxhighlight lang="fsharp">open System


Console.Beep()</lang>
Console.Beep()</syntaxhighlight>

=={{header|Factor}}==
<syntaxhighlight lang="factor">USE: io

"\u{7}" print</syntaxhighlight>

Or:

<syntaxhighlight lang="factor">USING: io strings ;

7 1string print</syntaxhighlight>


=={{header|Forth}}==
=={{header|Forth}}==
<lang forth>7 emit</lang>
<syntaxhighlight lang="forth">7 emit</syntaxhighlight>


{{works with|GNU Forth}}
{{works with|GNU Forth}}
<syntaxhighlight lang="forth">#bell emit</syntaxhighlight>

<lang forth>#bell emit</lang>


{{works with|iForth}}
{{works with|iForth}}
<syntaxhighlight lang="forth">^G emit</syntaxhighlight>

<lang forth>^G emit</lang>


=={{header|FreeBASIC}}==
=={{header|FreeBASIC}}==
<lang freebasic>' FB 1.05.0 Win64
<syntaxhighlight lang="freebasic">' FB 1.05.0 Win64


Print !"\a"
Print !"\a"
Sleep</lang>
Sleep</syntaxhighlight>


=={{header|gnuplot}}==
=={{header|gnuplot}}==
<lang gnuplot>print "\007"</lang>
<syntaxhighlight lang="gnuplot">print "\007"</syntaxhighlight>


=={{header|Go}}==
=={{header|Go}}==
<lang go>package main
<syntaxhighlight lang="go">package main


import "fmt"
import "fmt"
Line 246: Line 420:
func main() {
func main() {
fmt.Print("\a")
fmt.Print("\a")
}</lang>
}</syntaxhighlight>


=={{header|Groovy}}==
=={{header|Groovy}}==
<lang groovy>println '\7'</lang>
<syntaxhighlight lang="groovy">println '\7'</syntaxhighlight>


=={{header|Haskell}}==
=={{header|Haskell}}==
<lang haskell>main = putStr "\a"</lang>
<syntaxhighlight lang="haskell">main = putStr "\a"</syntaxhighlight>


=={{header|Icon}} and {{header|Unicon}}==
=={{header|Icon}} and {{header|Unicon}}==

Works on both Icon and Unicon.
Works on both Icon and Unicon.


<syntaxhighlight lang="icon">
<lang Icon>
procedure main ()
procedure main ()
write ("\7") # ASCII 7 rings the bell under Bash
write ("\7") # ASCII 7 rings the bell under Bash
end
end
</syntaxhighlight>
</lang>


=={{header|J}}==
=={{header|J}}==
This j sentence reads "Seven from alphabet."
This j sentence reads "Seven from alphabet."
<lang J> 7{a. NB. noun a. is a complete ASCII ordered character vector.</lang>
<syntaxhighlight lang="j"> 7{a. NB. noun a. is a complete ASCII ordered character vector.</syntaxhighlight>


=={{header|Java}}==
=={{header|Java}}==
<lang java>public class Bell{
<syntaxhighlight lang="java">public class Bell{
public static void main(String[] args){
public static void main(String[] args){
java.awt.Toolkit.getDefaultToolkit().beep();
java.awt.Toolkit.getDefaultToolkit().beep();
Line 277: Line 450:
System.out.println((char)7);
System.out.println((char)7);
}
}
}</lang>
}</syntaxhighlight>

=={{header|Joy}}==
<syntaxhighlight lang="joy">7 putch.</syntaxhighlight>


=={{header|Julia}}==
=={{header|Julia}}==
{{works with|Linux}}
{{works with|Linux}}
<syntaxhighlight lang="julia">
<lang Julia>
println("This should ring a bell.\a")
println("This should ring a bell.\a")
</syntaxhighlight>
</lang>


{{out}}
{{out}}
Line 294: Line 470:
=={{header|Kotlin}}==
=={{header|Kotlin}}==
{{works with|Windows|10}}
{{works with|Windows|10}}
<lang scala>// version 1.1.2
<syntaxhighlight lang="scala">// version 1.1.2


fun main(args: Array<String>) {
fun main(args: Array<String>) {
println("\u0007")
println("\u0007")
}</lang>
}</syntaxhighlight>

=={{header|Lang}}==
<syntaxhighlight lang="lang">
fn.println(fn.toChar(7))
</syntaxhighlight>


=={{header|Lasso}}==
=={{header|Lasso}}==
<lang Lasso>stdoutnl('\a')</lang>
<syntaxhighlight lang="lasso">stdoutnl('\a')</syntaxhighlight>


=={{header|Logo}}==
=={{header|Logo}}==
<lang logo>type char 7</lang>
<syntaxhighlight lang="logo">type char 7</syntaxhighlight>


=={{header|Lua}}==
=={{header|Lua}}==
<lang lua>print("\a")</lang>
<syntaxhighlight lang="lua">print("\a")</syntaxhighlight>


=={{header|M2000 Interpreter}}==
=={{header|M2000 Interpreter}}==
Line 314: Line 495:
===Using Windows Bell===
===Using Windows Bell===
Async beep. If another start while beeps (it is a bell), then stop
Async beep. If another start while beeps (it is a bell), then stop
<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
Module CheckIt {
Module CheckIt {
After 300 {beep}
After 300 {beep}
Line 325: Line 506:
}
}
CheckIt
CheckIt
</syntaxhighlight>
</lang>




Line 336: Line 517:
</pre>
</pre>


<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
Module CheckIt {
Module CheckIt {
After 300 {Tone 200}
After 300 {Tone 200}
Line 347: Line 528:
}
}
CheckIt
CheckIt
</syntaxhighlight>
</lang>




Line 358: Line 539:
</pre>
</pre>


<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
Module CheckIt {
Module CheckIt {
After 300 {Tune 300, "C3BC#"}
After 300 {Tune 300, "C3BC#"}
Line 369: Line 550:
}
}
CheckIt
CheckIt
</syntaxhighlight>
</lang>




Line 375: Line 556:
Play a score in each of 16 voices (async, programming internal midi, problem with async in Wine Linux). We can make a piano using keyboard and play/score commands.
Play a score in each of 16 voices (async, programming internal midi, problem with async in Wine Linux). We can make a piano using keyboard and play/score commands.


<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
Module CheckIt {
Module CheckIt {
Score 1, 500, "c@2dc @2ef"
Score 1, 500, "c@2dc @2ef"
Line 389: Line 570:
}
}
CheckIt
CheckIt
</syntaxhighlight>
</lang>


There are other statements like Sound, and Background filename$ to play background music.
There are other statements like Sound, and Background filename$ to play background music.


=={{header|Mathematica}}==
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<lang Mathematica>Print["\007"]</lang>
<syntaxhighlight lang="mathematica">Print["\007"]</syntaxhighlight>


=={{header|MUMPS}}==
<syntaxhighlight lang="mumps">write $char(7)</syntaxhighlight>

=={{header|Nanoquery}}==
<syntaxhighlight lang="nanoquery">print chr(7)</syntaxhighlight>


=={{header|Nemerle}}==
=={{header|Nemerle}}==
<lang Nemerle>using System.Console;
<syntaxhighlight lang="nemerle">using System.Console;


module Beep
module Beep
Line 410: Line 596:
Beep(2600, 1000); // limited OS support
Beep(2600, 1000); // limited OS support
}
}
}</lang>
}</syntaxhighlight>


=={{header|NetRexx}}==
=={{header|NetRexx}}==
<lang NetRexx>/* NetRexx */
<syntaxhighlight lang="netrexx">/* NetRexx */
options replace format comments java crossref symbols binary
options replace format comments java crossref symbols binary


Line 434: Line 620:
end
end
return
return
</syntaxhighlight>
</lang>


=={{header|Nim}}==
=={{header|Nim}}==
<lang nim>echo "\a"</lang>
<syntaxhighlight lang="nim">echo "\a"</syntaxhighlight>


=={{header|Objeck}}==
=={{header|Objeck}}==
<lang objeck>7->As(Char)->PrintLine();</lang>
<syntaxhighlight lang="objeck">7->As(Char)->PrintLine();</syntaxhighlight>

=={{header|OCaml}}==
<syntaxhighlight lang="ocaml">let () = print_string "\x07"</syntaxhighlight>


=={{header|PARI/GP}}==
=={{header|PARI/GP}}==
{{Works with|PARI/GP|2.7.4 and above}}
{{Works with|PARI/GP|2.7.4 and above}}


<lang parigp>\\ Ringing the terminal bell.
<syntaxhighlight lang="parigp">\\ Ringing the terminal bell.
\\ 8/14/2016 aev
\\ 8/14/2016 aev
Strchr(7) \\ press <Enter></lang>
Strchr(7) \\ press <Enter></syntaxhighlight>
;or:
;or:
<lang parigp>print(Strchr(7)); \\ press <Enter></lang>
<syntaxhighlight lang="parigp">print(Strchr(7)); \\ press <Enter></syntaxhighlight>


{{Output}}
{{Output}}
Line 464: Line 653:


=={{header|Perl}}==
=={{header|Perl}}==
<lang perl>print "\a";</lang>
<syntaxhighlight lang="perl">print "\a";</syntaxhighlight>

=={{header|Perl 6}}==
<lang perl6>print 7.chr;</lang>


=={{header|Phix}}==
=={{header|Phix}}==
<!--<syntaxhighlight lang="phix">(phixonline)-->
<lang Phix>puts(1,"\x07")</lang>
<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;">"\x07"</span><span style="color: #0000FF;">)</span>
<!--</syntaxhighlight>-->
Ineffective under pwa/p2js - just displays an unknown character glyph.


=={{header|PHP}}==
=={{header|PHP}}==
<lang php><?php
<syntaxhighlight lang="php"><?php
echo "\007";</lang>
echo "\007";</syntaxhighlight>


=={{header|PicoLisp}}==
=={{header|PicoLisp}}==
<lang PicoLisp>(beep)</lang>
<syntaxhighlight lang="picolisp">(beep)</syntaxhighlight>


=={{header|PL/I}}==
=={{header|PL/I}}==
<lang pli> declare bell character (1);
<syntaxhighlight lang="pli"> declare bell character (1);
unspec (bell) = '00000111'b;
unspec (bell) = '00000111'b;
put edit (bell) (a);</lang>
put edit (bell) (a);</syntaxhighlight>


=={{header|PostScript}}==
=={{header|PostScript}}==
The following will only work in a PostScript interpreter that sends output to a terminal. It will very likely not make a printer beep.
The following will only work in a PostScript interpreter that sends output to a terminal. It will very likely not make a printer beep.
<lang postscript>(\007) print</lang>
<syntaxhighlight lang="postscript">(\007) print</syntaxhighlight>


=={{header|PowerShell}}==
=={{header|PowerShell}}==
One can either use the ASCII <code>BEL</code> character which only works in a console (i.e. not in a graphical PowerShell host such as PowerShell ISE):
One can either use the ASCII <code>BEL</code> character which only works in a console (i.e. not in a graphical PowerShell host such as PowerShell ISE):
<lang powershell>"`a"</lang>
<syntaxhighlight lang="powershell">"`a"</syntaxhighlight>
or use the .NET <code>Console</code> class which works independent of the host application:
or use the .NET <code>Console</code> class which works independent of the host application:
<lang powershell>[Console]::Beep()</lang>
<syntaxhighlight lang="powershell">[Console]::Beep()</syntaxhighlight>


=={{header|PureBasic}}==
=={{header|PureBasic}}==
<lang PureBasic>Print(#BEL$)</lang>
<syntaxhighlight lang="purebasic">Print(#BEL$)</syntaxhighlight>

=={{header|Python}}==
=={{header|Python}}==
In Python 2.7.x:
<lang python>print "\a"</lang>
<syntaxhighlight lang="python">print "\a"</syntaxhighlight>
In Python 3.x:
<syntaxhighlight lang="python">print("\a")</syntaxhighlight>

=={{header|Quackery}}==
On some platforms the bell will not ring until the output buffer is flushed e.g. by a cr/lf.

<syntaxhighlight lang="quackery">ding</syntaxhighlight>


=={{header|R}}==
=={{header|R}}==
<lang R>alarm()</lang>
<syntaxhighlight lang="r">alarm()</syntaxhighlight>


=={{header|Racket}}==
=={{header|Racket}}==
<lang racket>
<syntaxhighlight lang="racket">
#lang racket
#lang racket
(require (planet neil/charterm:3:0))
(require (planet neil/charterm:3:0))
(with-charterm
(with-charterm
(void (charterm-bell)))
(void (charterm-bell)))
</syntaxhighlight>
</lang>

=={{header|Raku}}==
(formerly Perl 6)
<syntaxhighlight lang="raku" line>print 7.chr;</syntaxhighlight>


=={{header|Retro}}==
=={{header|Retro}}==
<lang Retro>7 putc</lang>
<syntaxhighlight lang="retro">7 putc</syntaxhighlight>


=={{header|REXX}}==
=={{header|REXX}}==
Line 517: Line 719:


However, some REXX interpreters have added a non-standard BIF.
However, some REXX interpreters have added a non-standard BIF.
<lang rexx>/*REXX program illustrates methods to ring the terminal bell or use the PC speaker. */
<syntaxhighlight lang="rexx">/*REXX program illustrates methods to ring the terminal bell or use the PC speaker. */
/*╔═══════════════════════════════════════════════════════════════╗
/*╔═══════════════════════════════════════════════════════════════╗
║ ║
║ ║
Line 555: Line 757:
call sound freq, secs /* " " " " 3/10 " */
call sound freq, secs /* " " " " 3/10 " */


/*stick a fork in it, we're done making noises.*/</lang>
/*stick a fork in it, we're done making noises.*/</syntaxhighlight>


=={{header|Ring}}==
=={{header|Ring}}==
<lang ring>
<syntaxhighlight lang="ring">
see char(7)
see char(7)
</syntaxhighlight>
</lang>


=={{header|Ruby}}==
=={{header|Ruby}}==
<lang ruby>print "\a"</lang>
<syntaxhighlight lang="ruby">print "\a"</syntaxhighlight>

=={{header|Rust}}==
<syntaxhighlight lang="rust">fn main() {
print!("\x07");
}</syntaxhighlight>


=={{header|Scala}}==
=={{header|Scala}}==
<lang scala>java.awt.Toolkit.getDefaultToolkit().beep()</lang>
<syntaxhighlight lang="scala">java.awt.Toolkit.getDefaultToolkit().beep()</syntaxhighlight>

=={{header|Seed7}}==
=={{header|Seed7}}==
<lang seed7>$ include "seed7_05.s7i";
<syntaxhighlight lang="seed7">$ include "seed7_05.s7i";


const proc: main is func
const proc: main is func
begin
begin
write("\a");
write("\a");
end func;</lang>
end func;</syntaxhighlight>


=={{header|Sidef}}==
=={{header|Sidef}}==
<lang ruby>print "\a";</lang>
<syntaxhighlight lang="ruby">print "\a";</syntaxhighlight>


=={{header|SNUSP}}==
=={{header|SNUSP}}==
<lang snusp>$+++++++.#</lang>
<syntaxhighlight lang="snusp">$+++++++.#</syntaxhighlight>

=={{header|Standard ML}}==
<syntaxhighlight lang="sml">val () = print "\a"</syntaxhighlight>


=={{header|Tcl}}==
=={{header|Tcl}}==
<lang tcl>puts -nonewline "\a";flush stdout</lang>
<syntaxhighlight lang="tcl">puts -nonewline "\a";flush stdout</syntaxhighlight>


=={{header|UNIX Shell}}==
=={{header|UNIX Shell}}==
{{works with|Bourne Shell}} {{works with|bash}}
{{works with|Bourne Shell}} {{works with|bash}}


<lang sh>#!/bin/sh
<syntaxhighlight lang="sh">#!/bin/sh
# Ring the terminal bell
# Ring the terminal bell
# echo "\a" # does not work in some shells
# echo "\a" # does not work in some shells
tput bel</lang>
tput bel</syntaxhighlight>

=={{header|Wren}}==
<syntaxhighlight lang="wren">System.print("\a")</syntaxhighlight>


=={{header|X86 Assembly}}==
=={{header|X86 Assembly}}==
<lang X86 Assembly>;Assemble with: tasm; tlink /t
<syntaxhighlight lang="x86 assembly">;Assemble with: tasm; tlink /t
.model tiny
.model tiny
.code
.code
Line 601: Line 815:
int 21h ;call MS-DOS
int 21h ;call MS-DOS
ret ;return to MS-DOS
ret ;return to MS-DOS
end start</lang>
end start</syntaxhighlight>


=={{header|XPL0}}==
=={{header|XPL0}}==
<lang XPL0>code ChOut=8;
<syntaxhighlight lang="xpl0">code ChOut=8;
ChOut(0,7)</lang>
ChOut(0,7)</syntaxhighlight>


=={{header|zkl}}==
=={{header|zkl}}==
<lang zkl>print("\x07");</lang>
<syntaxhighlight lang="zkl">print("\x07");</syntaxhighlight>





Latest revision as of 11:07, 1 March 2024

Task
Terminal control/Ringing the terminal bell
You are encouraged to solve this task according to the task description, using any language you may know.


Task

Make the terminal running the program ring its "bell".


On modern terminal emulators, this may be done by playing some other sound which might or might not be configurable, or by flashing the title bar or inverting the colors of the screen, but was classically a physical bell within the terminal.   It is usually used to indicate a problem where a wrong character has been typed.

In most terminals, if the   Bell character   (ASCII code 7,   \a in C)   is printed by the program, it will cause the terminal to ring its bell.   This is a function of the terminal, and is independent of the programming language of the program, other than the ability to print a particular character to standard out.

11l

print("\a")

6800 Assembly

        .cr  6800
        .tf  bel6800.obj,AP1
        .lf  bel6800
;=====================================================;
;         Ring the Bell for the Motorola 6800         ;
;                 by barrym 2013-03-31                ;
;-----------------------------------------------------;
; Rings the bell of an ascii terminal (console)       ;
;   connected to a 1970s vintage SWTPC 6800 system,   ;
;   which is the target device for this assembly.     ;
; Many thanks to:                                     ;
;   swtpc.com for hosting Michael Holley's documents! ;
;   sbprojects.com for a very nice assembler!         ;
;   swtpcemu.com for a very capable emulator!         ;
; reg a holds the ascii char to be output             ;
;-----------------------------------------------------;
outeee   =   $e1d1      ;ROM: console putchar routine
        .or  $0f00
;-----------------------------------------------------;
main    ldaa #7         ;Load the ascii BEL char
        jsr  outeee     ;  and print it
        swi             ;Return to the monitor
        .en

8086 Assembly

Using stdout

Translation of: X86 Assembly

This is how it's supposed to be done:

.model small
.stack 1024

.data

.code

start:  mov     ah, 02h         ;character output
        mov     dl, 07h         ;bell code
        int     21h             ;call MS-DOS

        mov     ax, 4C00h       ;exit 
        int     21h             ;return to MS-DOS
end start

But I couldn't hear anything on DOSBox when doing this.

The hard way

This version takes direct control over the PC's beeper to produce a tone whenever BEL is passed to PrintChar.

.model small
.stack 1024

.data

.code

start:

mov al,7
call PrintChar

mov ax,4C00h
int 21h            ;return to DOS
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
PrintChar:		;Print AL to screen
	push cx
	push bx
	push ax
		cmp al,7
		jne skipBEL
			call RingBell
			jmp done_PrintChar
skipBEL:
		mov bl,15	;text color will be white
		mov ah,0Eh			
		int 10h		;prints ascii code stored in AL to the screen (this is a slightly different putc syscall)	
done_PrintChar:
	pop ax
	pop bx
	pop cx
	ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
RingBell:
	push ax
	push cx
	push dx
        ;if BEL is the argument passed to PrintChar, it will call this function and not actually print anything or advance the cursor
        ;this uses the built-in beeper to simulate a beep

		mov al,10110110b	;select counter 2, 16-bit mode
		out 43h, al
		
		mov ax,0C00h		;set pitch of beep - this is somewhat high but isn't too annoying. Feel free to adjust this value
		out 42h,al
		mov al,ah
		out 42h,al


		mov al,3		
		out 61h,al			;enable sound and timer mode

		mov cx,0FFFFh
		mov dx,0Fh			;set up loop counters
		
beepdelay:					;delay lasts about half a second
		loop beepdelay
		mov cx,0FFFFh
		dec dx
		jnz beepdelay
		
		mov al,0			;mute
		out 61h,al			;cut the sound

                ; mov bl,15
                ; mov ax,0E20h                  ;print a spacebar to the terminal
                ; int 10h                       ;uncomment these 3 lines if you want the BEL to "take up space" in the output stream
	pop dx
	pop cx
	pop ax
	ret

end start

Action!

PROC Wait(BYTE frames)
  BYTE RTCLOK=$14
  frames==+RTCLOK
  WHILE frames#RTCLOK DO OD
RETURN

PROC Main()
  BYTE
    i,n=[3],
    CH=$02FC ;Internal hardware value for last key pressed

  PrintF("Press any key to hear %B bells...",n)
  DO UNTIL CH#$FF OD
  CH=$FF

  FOR i=1 TO n
  DO
    Put(253) ;buzzer
    Wait(20)
  OD
  Wait(100)
RETURN
Output:

Screenshot from Atari 8-bit computer

Ada

with Ada.Text_IO; use Ada.Text_IO;
with Ada.Characters.Latin_1;

procedure Bell is
begin
   Put(Ada.Characters.Latin_1.BEL);
end Bell;

Applescript

beep

Arturo

print "\a"

Asymptote

beep()

See beep() in the Asymptote manual.

AutoHotkey

fileappend, `a, *

This requires that you compile the exe in console mode (see Lexikos script to change this) or pipe the file through more: autohotkey bell.ahk |more

AWK

BEGIN {
print "\a" # Ring the bell
}

BASIC

Applesoft BASIC

 10  PRINT  CHR$ (7);

Integer BASIC

You can't see it, but the bell character (Control G) is embedded in what looks like an empty string on line 10.

  10 PRINT "";: REM ^G IN QUOTES
  20 END

IS-BASIC

PING

Locomotive Basic

10 PRINT CHR$(7)

ZX Spectrum Basic

The ZX Spectrum had a speaker, rather than a bell. Here we use middle C as a bell tone, but we could produce a different note by changing the final zero to a different value.

BEEP 0.2,0

Batch File

Source: Here

@echo off
for /f %%. in ('forfiles /m "%~nx0" /c "cmd /c echo 0x07"') do set bell=%%.
echo %bell%

BBC BASIC

Assuming that the platform the program is running on rings the bell when CHR$7 is sent to the VDU driver:

VDU 7

bc

print "\a"

beeswax

_7}

Befunge

7,@

Binary Lambda Calculus

The 2-byte BLC program 20 07 in hex outputs ASCII code 7.

Bracmat

Run Bracmat in interactive mode (start Bracmat without command line arguments) and enter the following after the Bracmat prompt {?}:

\a

Alternatively, run Bracmat non-interactively. In DOS, you write

bracmat "put$\a"

In Linux, you do

bracmat 'put$\a'

Brainf***

Assuming the output stream is connected to a TTY, printing BEL should ring its bell.

  I
  +
 + +
 +++
+-+-+
  .

C

#include <stdio.h>
int main() {
  printf("\a");
  return 0;
}

C#

Inside a function:

// the simple version:
System.Console.Write("\a"); // will beep
System.Threading.Thread.Sleep(1000); // will wait for 1 second
System.Console.Beep(); // will beep a second time
System.Threading.Thread.Sleep(1000);

// System.Console.Beep() also accepts (int)hertz and (int)duration in milliseconds:
System.Console.Beep(440, 2000); // default "concert pitch" for 2 seconds

C++

#include <iostream>

int main() {
  std::cout << "\a";
  return 0;
}

Clojure

(println (char 7))

COBOL

Using the standard screen section:

Works with: X/Open COBOL
Works with: COBOL 2002
       IDENTIFICATION DIVISION.
       PROGRAM-ID. ring-terminal-bell.

       DATA DIVISION.
       SCREEN SECTION.
       01  ringer BELL.

       PROCEDURE DIVISION.
           DISPLAY ringer.
           STOP RUN.

       END PROGRAM ring-terminal-bell.

Using the ASCII code directly:

Works with: COBOL-85
      *> Tectonics: cobc -xj ring-terminal-bell.cob --std=cobol85
       IDENTIFICATION DIVISION.
       PROGRAM-ID. ring-ascii-bell.

       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       OBJECT-COMPUTER.
           PROGRAM COLLATING SEQUENCE IS ASCII.
       SPECIAL-NAMES.
           ALPHABET ASCII IS STANDARD-1.

       PROCEDURE DIVISION.
           DISPLAY FUNCTION CHAR(8) WITH NO ADVANCING.
      *>   COBOL indexes starting from 1.
           STOP RUN.

       END PROGRAM ring-ascii-bell.
Works with: Visual COBOL
       IDENTIFICATION DIVISION.
       PROGRAM-ID. mf-bell.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  bell-code              PIC X USAGE COMP-X VALUE 22.
       01  dummy-param            PIC X.

       PROCEDURE DIVISION.
           CALL X"AF" USING bell-code, dummy-param
           GOBACK.

       END PROGRAM mf-bell.

Common Lisp

(format t "~C" (code-char 7))

D

void main() {
    import std.stdio;
    writeln('\a');
}

dc

7P

Delphi

program TerminalBell;

{$APPTYPE CONSOLE}

begin
  Writeln(#7);
end.

E

print("\u0007")

Emacs Lisp

(ding)    ;; ring the bell
(beep)    ;; the same thing

On a tty or in -batch mode this emits a BEL character. In a GUI it does whatever suits the window system. Variables visible-bell and ring-bell-function can control the behaviour.

beep was originally called feep, but that changed, recently :-)

Fri Dec 13 00:52:16 1985  Richard M. Stallman  (rms at prep)
	* subr.el: Rename feep to beep, a more traditional name.

F#

open System

Console.Beep()

Factor

USE: io

"\u{7}" print

Or:

USING: io strings ;

7 1string print

Forth

7 emit
Works with: GNU Forth
#bell emit
Works with: iForth
^G emit

FreeBASIC

' FB 1.05.0 Win64

Print !"\a"
Sleep

gnuplot

print "\007"

Go

package main

import "fmt"

func main() {
  fmt.Print("\a")
}

Groovy

println '\7'

Haskell

main = putStr "\a"

Icon and Unicon

Works on both Icon and Unicon.

procedure main ()
  write ("\7") # ASCII 7 rings the bell under Bash
end

J

This j sentence reads "Seven from alphabet."

   7{a.  NB. noun a. is a complete ASCII ordered character vector.

Java

public class Bell{
    public static void main(String[] args){
        java.awt.Toolkit.getDefaultToolkit().beep();

        //or

        System.out.println((char)7);
    }
}

Joy

7 putch.

Julia

Works with: Linux
println("This should ring a bell.\a")
Output:
This should ring a bell.

And it does, provided that the bell is enabled on your terminal.

Kotlin

Works with: Windows version 10
// version 1.1.2

fun main(args: Array<String>) {
    println("\u0007")
}

Lang

fn.println(fn.toChar(7))

Lasso

stdoutnl('\a')

type char 7

Lua

print("\a")

M2000 Interpreter

M2000 Environment has own console (not the one provided from system). Console used for graphics, and has 32 layers for text or and graphics and as sprites too. We can alter the console by code, moving to any monitor, changing font, font size and, line space. Also there is a split function, where the lower part can scroll, and the upper part used as header (we can write/draw in the upper part also, but CLS - clear screen- statement clear only the lower part).

Using Windows Bell

Async beep. If another start while beeps (it is a bell), then stop

Module CheckIt {
      After 300 {beep}
      Print "Begin"
      for i=0 to 100 {
            wait 10
            Print i
      }
      Print "End"
}
CheckIt


Play tone at 1khz or specific hz

Execution stop to play tone

Tone (1khz)
Tone 200 (1 kgz 200 ms)
Tone 200, 5000 (5khz. 200ms)
Module CheckIt {
      After 300 {Tone 200}
      Print "Begin"
      for i=0 to 100 {
            wait 10
            Print i
      }
      Print "End"
}
CheckIt


Play melody with beeper

Execution stop to play tune

Tune melody$
Tune duration_per_note, melody$
Module CheckIt {
      After 300 {Tune 300, "C3BC#"}
      Print "Begin"
      for i=0 to 100 {
            wait 10
            Print i
      }
      Print "End"
}
CheckIt


using midi to send music scores

Play a score in each of 16 voices (async, programming internal midi, problem with async in Wine Linux). We can make a piano using keyboard and play/score commands.

Module CheckIt {
      Score 1, 500, "c@2dc @2ef"
      Play 1, 19  ' attach a music score to an organ
      Print "Begin"
      for i=0 to 100 {
            wait 10
            Print i
      }
      Print "End"
      \\ stop play, remove this and music continue, in console prompt
      Play 0
}
CheckIt

There are other statements like Sound, and Background filename$ to play background music.

Mathematica/Wolfram Language

Print["\007"]

MUMPS

write $char(7)

Nanoquery

print chr(7)

Nemerle

using System.Console;

module Beep
{
    Main() : void
    {
        Write("\a");
        System.Threading.Thread.Sleep(1000);
        Beep();
        System.Threading.Thread.Sleep(1000);
        Beep(2600, 1000); // limited OS support
    }
}

NetRexx

/* NetRexx */
options replace format comments java crossref symbols binary

runSample(arg)
return

-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
method runSample(arg) private static
  do
    BEL = 8x07
    jtk = java.awt.toolkit.getDefaultToolkit()
    say 'Bing!'(Rexx BEL).d2c
    Thread.sleep(500)
    say 'Ding\x07-ding\u0007!'
    Thread.sleep(500)
    say 'Beep!'
    jtk.beep()
  catch ex = Exception
    ex.printStackTrace()
  end
  return

Nim

echo "\a"

Objeck

7->As(Char)->PrintLine();

OCaml

let () = print_string "\x07"

PARI/GP

Works with: PARI/GP version 2.7.4 and above
\\ Ringing the terminal bell.
\\ 8/14/2016 aev
Strchr(7) \\ press <Enter>
or
print(Strchr(7)); \\ press <Enter>
Output:
(11:12) gp > Strchr(7) \\ press <Enter>
%6 = ""
(11:13) gp > print(Strchr(7)); \\ press <Enter>

(11:14) gp >

Pascal

See Delphi

Perl

print "\a";

Phix

puts(1,"\x07")

Ineffective under pwa/p2js - just displays an unknown character glyph.

PHP

<?php
echo "\007";

PicoLisp

(beep)

PL/I

   declare bell character (1);
   unspec (bell) = '00000111'b;
   put edit (bell) (a);

PostScript

The following will only work in a PostScript interpreter that sends output to a terminal. It will very likely not make a printer beep.

(\007) print

PowerShell

One can either use the ASCII BEL character which only works in a console (i.e. not in a graphical PowerShell host such as PowerShell ISE):

"`a"

or use the .NET Console class which works independent of the host application:

[Console]::Beep()

PureBasic

Print(#BEL$)

Python

In Python 2.7.x:

print "\a"

In Python 3.x:

print("\a")

Quackery

On some platforms the bell will not ring until the output buffer is flushed e.g. by a cr/lf.

ding

R

alarm()

Racket

#lang racket
(require (planet neil/charterm:3:0))
(with-charterm
 (void (charterm-bell)))

Raku

(formerly Perl 6)

print 7.chr;

Retro

7 putc

REXX

There is no standard REXX built-in function to handle the sounding of the bell or a PC's speaker.

However, some REXX interpreters have added a non-standard BIF.

/*REXX program illustrates methods to  ring the terminal bell  or  use the PC speaker.  */
                     /*╔═══════════════════════════════════════════════════════════════╗
                       ║                                                               ║
                       ║  Note that the  hexadecimal code  to ring the  terminal bell  ║
                       ║  is different on an ASCII machine than an EBCDIC machine.     ║
                       ║                                                               ║
                       ║  On an  ASCII machine,  it is  (hexadecimal)  '07'x.          ║
                       ║   "  " EBCDIC    "       "  "        "        '2F'x.          ║
                       ║                                                               ║
                       ╚═══════════════════════════════════════════════════════════════╝*/

if 3=='F3'  then bell= '2f'x                     /*we are running on an EBCDIC machine. */
            else bell= '07'x                     /* "  "     "     "  "  ASCII    "     */

say bell                                         /*sound the  bell  on the terminal.    */
say copies(bell, 20)                             /*as above,  but much more annoying.   */

                     /*╔═══════════════════════════════════════════════════════════════╗
                       ║                                                               ║
                       ║  Some REXX interpreters have a  built-in function  (BIF)  to  ║
                       ║  to produce a sound on the PC speaker, the sound is specified ║
                       ║  by frequency  and  an optional  duration.                    ║
                       ║                                                               ║
                       ╚═══════════════════════════════════════════════════════════════╝*/

                                         /* [↓]  supported by Regina REXX:              */
freq= 1200                               /*frequency in  (nearest)  cycles per second.  */
call  beep freq                          /*sounds the PC speaker, duration=  1   second.*/
ms=   500                                /*duration in milliseconds.                    */
call  beep freq, ms                      /*  "     "   "    "         "     1/2     "   */


                                         /* [↓]  supported by PC/REXX  &  Personal REXX:*/
freq= 2000                               /*frequency in  (nearest)  cycles per second.  */
call  sound freq                         /*sounds PC speaker, duration=   .2   second.  */
secs= .333                               /*duration in seconds (round to nearest tenth).*/
call  sound freq, secs                   /*  "     "    "         "      3/10     "     */

                                         /*stick a fork in it, we're done making noises.*/

Ring

see char(7)

Ruby

print "\a"

Rust

fn main() {
    print!("\x07");
}

Scala

java.awt.Toolkit.getDefaultToolkit().beep()

Seed7

$ include "seed7_05.s7i";

const proc: main is func
  begin
    write("\a");
  end func;

Sidef

print "\a";

SNUSP

$+++++++.#

Standard ML

val () = print "\a"

Tcl

puts -nonewline "\a";flush stdout

UNIX Shell

Works with: Bourne Shell
Works with: bash
#!/bin/sh
# Ring the terminal bell
# echo "\a" # does not work in some shells
tput bel

Wren

System.print("\a")

X86 Assembly

;Assemble with: tasm; tlink /t
        .model  tiny
        .code
        org     100h            ;.com files start here
start:  mov     ah, 02h         ;character output
        mov     dl, 07h         ;bell code
        int     21h             ;call MS-DOS
        ret                     ;return to MS-DOS
        end     start

XPL0

code ChOut=8;
ChOut(0,7)

zkl

print("\x07");