Terminal control/Ringing the terminal bell: Difference between revisions
→{{header|D}}: added D |
|||
Line 143: | Line 143: | ||
GOBACK |
GOBACK |
||
.</lang> |
.</lang> |
||
=={{header|D}}== |
|||
<lang d>void main() { |
|||
import std.stdio; |
|||
writeln('\a'); |
|||
}</lang> |
|||
=={{header|Delphi}}== |
=={{header|Delphi}}== |
||
Line 152: | Line 158: | ||
Writeln(#7); |
Writeln(#7); |
||
end.</lang> |
end.</lang> |
||
=={{header|E}}== |
=={{header|E}}== |
Revision as of 02:35, 19 November 2013
You are encouraged to solve this task according to the task description, using any language you may know.
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.
6800 Assembly
<lang m68k> .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</lang>
Ada
<lang 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;</lang>
Asymptote
<lang Asymptote>beep()</lang> See beep() in the Asymptote manual.
AutoHotkey
<lang AutoHotkey> fileappend, `a, * </lang>
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
<lang awk>BEGIN { print "\a" # Ring the bell }</lang>
BASIC
Applesoft BASIC
<lang Applesoft BASIC> 10 PRINT CHR$ (7);</lang>
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. <lang Integer BASIC> 10 PRINT "";: REM ^G IN QUOTES
20 END</lang>
Locomotive Basic
<lang locobasic>10 PRINT CHR$(7)</lang>
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.
<lang basic>BEEP 0.2,0</lang>
BBC BASIC
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>
Befunge
<lang befunge>7,@</lang>
Bracmat
Run Bracmat in interactive mode (start Bracmat without command line arguments) and enter the following after the Bracmat prompt {?}
:
<lang bracmat>\a</lang>
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.
<lang brainfuck> I
+ + + +++
+-+-+
.</lang>
C
<lang c>#include <stdio.h> int main() {
printf("\a"); return 0;
}</lang>
C#
Inside a function: <lang csharp>// 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 </lang>
COBOL
Standard compliant: <lang cobol>DISPLAY SPACE WITH BELL</lang>
<lang 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 .</lang>
D
<lang d>void main() {
import std.stdio; writeln('\a');
}</lang>
Delphi
<lang Delphi>program TerminalBell;
{$APPTYPE CONSOLE}
begin
Writeln(#7);
end.</lang>
E
<lang e>print("\u0007")</lang>
Emacs Lisp
<lang lisp>(ding) ;; ring the bell
(beep) ;; the same thing</lang>
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.
Forth
<lang forth>7 emit</lang>
<lang forth>#bell emit</lang>
<lang forth>^G emit</lang>
gnuplot
<lang gnuplot>print "\007"</lang>
Go
<lang go>package main
import "fmt"
func main() {
fmt.Print("\a")
}</lang>
Groovy
<lang groovy>println '\7'</lang>
Haskell
<lang haskell>main = putStr "\a"</lang>
Icon and Unicon
Works on both Icon and Unicon.
<lang Icon> procedure main ()
write ("\7") # ASCII 7 rings the bell under Bash
end </lang>
J
This j sentence reads "Seven from alphabet." <lang J> 7{a. NB. noun a. is a complete ASCII ordered character vector.</lang>
Java
<lang java>public class Bell{
public static void main(String[] args){ java.awt.Toolkit.getDefaultToolkit().beep();
//or
System.out.println((char)7); }
}</lang>
Lasso
<lang Lasso>stdoutnl('\a')</lang>
Logo
<lang logo>type char 7</lang>
Mathematica
<lang Mathematica>Print["\007"]</lang>
Nemerle
<lang 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 }
}</lang>
Objeck
<lang objeck>7->As(Char)->PrintLine();</lang>
Pascal
See Delphi
Perl
<lang perl>print "\a";</lang>
Perl 6
<lang perl6>print 7.chr;</lang>
PicoLisp
<lang PicoLisp>(beep)</lang>
PL/I
<lang pli> declare bell character (1);
unspec (bell) = '00000111'b; put edit (bell) (a);</lang>
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. <lang postscript>(\007) print</lang>
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):
<lang powershell>"`a"</lang>
or use the .NET Console
class which works independent of the host application:
<lang powershell>[Console]::Beep()</lang>
PureBasic
<lang PureBasic>Print(#BEL$)</lang>
Python
<lang python>print "\a"</lang>
R
<lang R>alarm()</lang>
Racket
<lang racket>
- lang racket
(require (planet neil/charterm:3:0)) (with-charterm
(void (charterm-bell)))
</lang>
Retro
<lang Retro>7 putc</lang>
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-stardard BIF. <lang rexx>call beep(freq [,duration]) /*supported (kinda) by Regina. */
call sound(freq [,duration ]) /*supported by PC/REXX. */
say '07'x /*works under the Windows DOS shell.*/
say copies('07'x,100) /*as above, but much more annoying. */</lang>
Ruby
<lang ruby>print "\a"</lang>
Scala
<lang scala>java.awt.Toolkit.getDefaultToolkit().beep()</lang>
Seed7
<lang seed7>$ include "seed7_05.s7i";
const proc: main is func
begin write("\a"); end func;</lang>
SNUSP
<lang snusp>$+++++++.#</lang>
Tcl
<lang tcl>puts -nonewline "\a";flush stdout</lang>
UNIX Shell
<lang sh>#!/bin/sh
- Ring the terminal bell
- echo "\a" # does not work in some shells
tput bel</lang>
X86 Assembly
<lang 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</lang>
XPL0
<lang XPL0>code ChOut=8; ChOut(0,7)</lang>
- Programming Tasks
- Terminal control
- 6800 Assembly
- Ada
- Asymptote
- AutoHotkey
- AWK
- BASIC
- Applesoft BASIC
- Integer BASIC
- Locomotive Basic
- ZX Spectrum Basic
- BBC BASIC
- Befunge
- Bracmat
- Brainf***
- C
- C sharp
- COBOL
- D
- Delphi
- E
- Emacs Lisp
- Forth
- Gnuplot
- Go
- Groovy
- Haskell
- Icon
- Unicon
- J
- Java
- Lasso
- Logo
- Mathematica
- Nemerle
- Objeck
- Pascal
- Perl
- Perl 6
- PicoLisp
- PL/I
- PostScript
- PowerShell
- PureBasic
- Python
- R
- Racket
- Retro
- REXX
- Ruby
- Scala
- Seed7
- SNUSP
- Tcl
- UNIX Shell
- X86 Assembly
- XPL0
- ACL2/Omit
- Maxima/Omit
- PARI/GP/Omit
- Inform 7/Omit