- Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathescape.html
144 lines (144 loc) · 15.4 KB
/
escape.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<!DOCTYPE html>
<htmllang="en">
<head>
<metacharset="utf-8">
<metahttp-equiv="X-UA-Compatible" content="IE=edge">
<metaname="viewport" content="width=device-width, initial-scale=1">
<title>SmallBASIC | escape</title>
<metaname="description" content="SmallBASIC | One more basic">
<linkrel="canonical" href="/escape.html">
<linkrel="keywords" href="escape">
<linkrel="stylesheet" href="/css/style.css">
<linkrel="icon" type="image/png" href="/images/sb-desktop-32x32.png">
<scriptsrc="/clipboard.js"></script>
</head>
<body>
<buttononclick="topFunction()" id="BackToTopBtn" title="Go to top">⯅</button>
<scriptsrc="/backtotop.js"></script>
<divclass="wrapAll clearfix">
<navclass="navigation">
<divclass="logo">
<ahref="/"><imgsrc='/images/sb-logo.png?v=2' alt="logo"></a>
</div>
<divclass="navlinks">
<ahref="/pages/download.html">Download</a>
<ahref="/pages/news.html">News</a>
<ahref="/pages/community.html">Community</a>
<aclass='active' href="/pages/articles.html">Resources</a>
<ahref="/pages/reference.html">Language Reference</a>
<ahref="/pages/guide.html">SmallBASIC Manual</a>
</div>
</nav>
<divclass="mainsection">
<divclass="tabs clearfix">
<divclass="tabsRight">
<atarget="_github" href="https://github.com/smallbasic/smallbasic.github.io/blob/master/_build/pages/escape.markdown">Edit</a>
<atarget="_github" href="https://github.com/smallbasic/smallbasic.github.io/commits/master/_build/pages/escape.markdown">History</a>
</div>
</div>
<divclass="article">
<h1id="escape-codes">Escape codes</h1>
<p>SmallBASIC supports a number of escape codes for controlling the
display. The codes allow you to set foreground and background colors,
change the font and also set underline and inverse text display. The
escape codes are based on <a
href="http://en.wikipedia.org/wiki/ANSI_escape_code">ANSI Codes</a>.</p>
<h2id="supported-standard-codes">Supported standard codes</h2>
<pre><code> \a beep
\t tab (20 px)
\r return
\n next line
\" quote "
\\ Backslash \
\e[K clear to end of line
\e[nG move to column n
\e[s save cursor position
\e[u restore cursor position
\e[0m reset all attributes to their defaults
\e[1m set bold on
\e[3m set italic on
\e[4m set underline on
\e[7m reverse video
\e[21m set bold off
\e[21m set italic off
\e[24m set underline off
\e[27m set reverse off
\e[nm n colors - 30..37 foreground, 40..47 background</code></pre>
<h2id="using-escape-codes-directly">Using escape codes directly</h2>
<p>Instead of <code>\e</code> the command CHR(27) is useful for
obtaining and printing the escape character.</p>
<divclass="sourceCode" id="cb2"><pre
class="sourceCode smallbasic"><codeclass="sourceCode smallbasic"><spanid="cb2-1"><ahref="#cb2-1" aria-hidden="true" tabindex="-1"></a><spanclass="kw">PRINT</span><spanclass="fu">CHR</span>(<spanclass="dv">27</span>) + <spanclass="st">"[1mTHIS IS BOLD"</span> + <spanclass="fu">CHR</span>(<spanclass="dv">27</span>) + <spanclass="st">"[0m"</span></span>
<spanid="cb2-2"><ahref="#cb2-2" aria-hidden="true" tabindex="-1"></a><spanclass="kw">PRINT</span><spanclass="fu">CHR</span>(<spanclass="dv">27</span>) + <spanclass="st">"[3mThis is italic"</span> + <spanclass="fu">CHR</span>(<spanclass="dv">27</span>) + <spanclass="st">"[0m"</span></span>
<spanid="cb2-3"><ahref="#cb2-3" aria-hidden="true" tabindex="-1"></a><spanclass="kw">PRINT</span><spanclass="fu">CHR</span>(<spanclass="dv">27</span>) + <spanclass="st">"[4mThis is underline"</span></span>
<spanid="cb2-4"><ahref="#cb2-4" aria-hidden="true" tabindex="-1"></a></span>
<spanid="cb2-5"><ahref="#cb2-5" aria-hidden="true" tabindex="-1"></a><spanclass="kw">PRINT</span><spanclass="st">"\e[32mGreen text"</span></span>
<spanid="cb2-6"><ahref="#cb2-6" aria-hidden="true" tabindex="-1"></a><spanclass="kw">PRINT</span><spanclass="st">"\e[32m\e[47mGreen text on white background"</span></span>
<spanid="cb2-7"><ahref="#cb2-7" aria-hidden="true" tabindex="-1"></a><spanclass="kw">PRINT</span><spanclass="st">"First line\nSecond Line"</span></span></code></pre></div>
<h2id="using-the-escapecode-unit">Using the EscapeCode Unit</h2>
<p>The EscapeCode Unit makes it easier to use escape codes and to deal
with different colors for foreground and background. The unit can be
downloaded or copy pasted from the <a
href="https://github.com/smallbasic/smallbasic.plugins/blob/master/units/EscapeCodes.bas">SmallBASIC
Github website</a>. Please save the unit in the same directory as your
basic file.</p>
<p>Here an example on how to use the unit:</p>
<divclass="sourceCode" id="cb3"><pre
class="sourceCode smallbasic"><codeclass="sourceCode smallbasic"><spanid="cb3-1"><ahref="#cb3-1" aria-hidden="true" tabindex="-1"></a><spanclass="co">' SmallBASIC 12.25</span></span>
<spanid="cb3-2"><ahref="#cb3-2" aria-hidden="true" tabindex="-1"></a><spanclass="co">' Example for using UNIT "EscapeCodes"</span></span>
<spanid="cb3-3"><ahref="#cb3-3" aria-hidden="true" tabindex="-1"></a><spanclass="co">' For more information see: https://smallbasic.github.io/pages/escape.html</span></span>
<spanid="cb3-4"><ahref="#cb3-4" aria-hidden="true" tabindex="-1"></a></span>
<spanid="cb3-5"><ahref="#cb3-5" aria-hidden="true" tabindex="-1"></a><spanclass="pp">import</span> EscapeCodes <spanclass="kw">as</span> esc</span>
<spanid="cb3-6"><ahref="#cb3-6" aria-hidden="true" tabindex="-1"></a></span>
<spanid="cb3-7"><ahref="#cb3-7" aria-hidden="true" tabindex="-1"></a><spanclass="kw">print</span><spanclass="st">"FORMATING TEXT:"</span></span>
<spanid="cb3-8"><ahref="#cb3-8" aria-hidden="true" tabindex="-1"></a><spanclass="kw">print</span></span>
<spanid="cb3-9"><ahref="#cb3-9" aria-hidden="true" tabindex="-1"></a><spanclass="kw">print</span> esc.NORMAL + <spanclass="st">"WITHOUT ANY FORMAT "</span> + esc.ITALIC + <spanclass="st">"ITALIC "</span> + esc.ITALIC_OFF + esc.BOLD + <spanclass="st">"BOLD "</span> + esc.BOLD_OFF + esc.UNDERLINE + <spanclass="st">"UNDERLINE "</span> + esc.UNDERLINE_OFF + esc.REVERSE + <spanclass="st">"REVERSE"</span> + esc.REVERSE_OFF</span>
<spanid="cb3-10"><ahref="#cb3-10" aria-hidden="true" tabindex="-1"></a><spanclass="kw">print</span></span>
<spanid="cb3-11"><ahref="#cb3-11" aria-hidden="true" tabindex="-1"></a><spanclass="kw">print</span><spanclass="st">"USE COLORS:"</span></span>
<spanid="cb3-12"><ahref="#cb3-12" aria-hidden="true" tabindex="-1"></a><spanclass="kw">print</span></span>
<spanid="cb3-13"><ahref="#cb3-13" aria-hidden="true" tabindex="-1"></a><spanclass="kw">print</span> esc.BG_BLACK + esc.BLACK + <spanclass="st">" BLACK "</span> + esc.RED + <spanclass="st">" RED "</span> + esc.GREEN + <spanclass="st">" GREEN "</span> + esc.YELLOW + <spanclass="st">" YELLOW "</span> + esc.BLUE + <spanclass="st">" BLUE "</span> + esc.MAGENTA + <spanclass="st">" MAGENTA "</span> + esc.CYAN + <spanclass="st">" CYAN "</span> + esc.WHITE + <spanclass="st">" WHITE "</span> + esc.NORMAL</span>
<spanid="cb3-14"><ahref="#cb3-14" aria-hidden="true" tabindex="-1"></a><spanclass="kw">print</span> esc.BG_RED + esc.BLACK + <spanclass="st">" BLACK "</span> + esc.RED + <spanclass="st">" RED "</span> + esc.GREEN + <spanclass="st">" GREEN "</span> + esc.YELLOW + <spanclass="st">" YELLOW "</span> + esc.BLUE + <spanclass="st">" BLUE "</span> + esc.MAGENTA + <spanclass="st">" MAGENTA "</span> + esc.CYAN + <spanclass="st">" CYAN "</span> + esc.WHITE + <spanclass="st">" WHITE "</span> + esc.NORMAL</span>
<spanid="cb3-15"><ahref="#cb3-15" aria-hidden="true" tabindex="-1"></a><spanclass="kw">print</span> esc.BG_GREEN + esc.BLACK + <spanclass="st">" BLACK "</span> + esc.RED + <spanclass="st">" RED "</span> + esc.GREEN + <spanclass="st">" GREEN "</span> + esc.YELLOW + <spanclass="st">" YELLOW "</span> + esc.BLUE + <spanclass="st">" BLUE "</span> + esc.MAGENTA + <spanclass="st">" MAGENTA "</span> + esc.CYAN + <spanclass="st">" CYAN "</span> + esc.WHITE + <spanclass="st">" WHITE "</span> + esc.NORMAL</span>
<spanid="cb3-16"><ahref="#cb3-16" aria-hidden="true" tabindex="-1"></a><spanclass="kw">print</span> esc.BG_YELLOW + esc.BLACK + <spanclass="st">" BLACK "</span> + esc.RED + <spanclass="st">" RED "</span> + esc.GREEN + <spanclass="st">" GREEN "</span> + esc.YELLOW + <spanclass="st">" YELLOW "</span> + esc.BLUE + <spanclass="st">" BLUE "</span> + esc.MAGENTA + <spanclass="st">" MAGENTA "</span> + esc.CYAN + <spanclass="st">" CYAN "</span> + esc.WHITE + <spanclass="st">" WHITE "</span> + esc.NORMAL</span>
<spanid="cb3-17"><ahref="#cb3-17" aria-hidden="true" tabindex="-1"></a><spanclass="kw">print</span> esc.BG_BLUE + esc.BLACK + <spanclass="st">" BLACK "</span> + esc.RED + <spanclass="st">" RED "</span> + esc.GREEN + <spanclass="st">" GREEN "</span> + esc.YELLOW + <spanclass="st">" YELLOW "</span> + esc.BLUE + <spanclass="st">" BLUE "</span> + esc.MAGENTA + <spanclass="st">" MAGENTA "</span> + esc.CYAN + <spanclass="st">" CYAN "</span> + esc.WHITE + <spanclass="st">" WHITE "</span> + esc.NORMAL</span>
<spanid="cb3-18"><ahref="#cb3-18" aria-hidden="true" tabindex="-1"></a><spanclass="kw">print</span> esc.BG_MAGENTA + esc.BLACK + <spanclass="st">" BLACK "</span> + esc.RED + <spanclass="st">" RED "</span> + esc.GREEN + <spanclass="st">" GREEN "</span> + esc.YELLOW + <spanclass="st">" YELLOW "</span> + esc.BLUE + <spanclass="st">" BLUE "</span> + esc.MAGENTA + <spanclass="st">" MAGENTA "</span> + esc.CYAN + <spanclass="st">" CYAN "</span> + esc.WHITE + <spanclass="st">" WHITE "</span> + esc.NORMAL</span>
<spanid="cb3-19"><ahref="#cb3-19" aria-hidden="true" tabindex="-1"></a><spanclass="kw">print</span> esc.BG_CYAN + esc.BLACK + <spanclass="st">" BLACK "</span> + esc.RED + <spanclass="st">" RED "</span> + esc.GREEN + <spanclass="st">" GREEN "</span> + esc.YELLOW + <spanclass="st">" YELLOW "</span> + esc.BLUE + <spanclass="st">" BLUE "</span> + esc.MAGENTA + <spanclass="st">" MAGENTA "</span> + esc.CYAN + <spanclass="st">" CYAN "</span> + esc.WHITE + <spanclass="st">" WHITE "</span> + esc.NORMAL</span>
<spanid="cb3-20"><ahref="#cb3-20" aria-hidden="true" tabindex="-1"></a><spanclass="kw">print</span> esc.BG_WHITE + esc.BLACK + <spanclass="st">" BLACK "</span> + esc.RED + <spanclass="st">" RED "</span> + esc.GREEN + <spanclass="st">" GREEN "</span> + esc.YELLOW + <spanclass="st">" YELLOW "</span> + esc.BLUE + <spanclass="st">" BLUE "</span> + esc.MAGENTA + <spanclass="st">" MAGENTA "</span> + esc.CYAN + <spanclass="st">" CYAN "</span> + esc.WHITE + <spanclass="st">" WHITE "</span> + esc.NORMAL</span>
<spanid="cb3-21"><ahref="#cb3-21" aria-hidden="true" tabindex="-1"></a><spanclass="kw">print</span> esc.NORMAL</span>
<spanid="cb3-22"><ahref="#cb3-22" aria-hidden="true" tabindex="-1"></a><spanclass="kw">print</span><spanclass="st">"USE COLORS AND FORMATS:"</span></span>
<spanid="cb3-23"><ahref="#cb3-23" aria-hidden="true" tabindex="-1"></a><spanclass="kw">print</span></span>
<spanid="cb3-24"><ahref="#cb3-24" aria-hidden="true" tabindex="-1"></a><spanclass="kw">print</span> esc.NORMAL + esc.BOLD + esc.UNDERLINE + esc.GREEN + esc.BG_WHITE + <spanclass="st">"BOLD + UNDELINE + COLOR"</span> + esc.NORMAL</span>
<spanid="cb3-25"><ahref="#cb3-25" aria-hidden="true" tabindex="-1"></a><spanclass="kw">print</span></span>
<spanid="cb3-26"><ahref="#cb3-26" aria-hidden="true" tabindex="-1"></a><spanclass="kw">print</span><spanclass="st">"CONTROL THE CURSOR:"</span></span>
<spanid="cb3-27"><ahref="#cb3-27" aria-hidden="true" tabindex="-1"></a><spanclass="kw">print</span></span>
<spanid="cb3-28"><ahref="#cb3-28" aria-hidden="true" tabindex="-1"></a><spanclass="kw">print</span> esc.MOVE_TO_COLUMN(<spanclass="dv">4</span>) + <spanclass="st">"MOVE TO COLUMN 4"</span></span>
<spanid="cb3-29"><ahref="#cb3-29" aria-hidden="true" tabindex="-1"></a><spanclass="kw">print</span><spanclass="st">"TABS:"</span> + esc.TB + <spanclass="st">"ONE TAB"</span> + esc.TB + esc.TB + <spanclass="st">"TWO MORE TABS"</span></span>
<spanid="cb3-30"><ahref="#cb3-30" aria-hidden="true" tabindex="-1"></a><spanclass="kw">print</span><spanclass="st">"YOU SHOULD NOT READ THIS"</span> + esc.RET + <spanclass="st">"RETURN TO BEGIN OF LINE "</span></span>
<spanid="cb3-31"><ahref="#cb3-31" aria-hidden="true" tabindex="-1"></a><spanclass="kw">print</span><spanclass="st">"FIRST LINE"</span> + esc.NEXTLINE + <spanclass="st">"NEXT LINE"</span></span>
<spanid="cb3-32"><ahref="#cb3-32" aria-hidden="true" tabindex="-1"></a><spanclass="kw">print</span> esc.SAVECURSOR + <spanclass="st">"YOU SHOULD NOT READ THIS"</span></span>
<spanid="cb3-33"><ahref="#cb3-33" aria-hidden="true" tabindex="-1"></a><spanclass="kw">print</span> esc.RESTORECURSOR + esc.CLEAR_LINE + <spanclass="st">"SAVE AND RESTORE THE CURSOR POSITION"</span></span>
<spanid="cb3-34"><ahref="#cb3-34" aria-hidden="true" tabindex="-1"></a><spanclass="kw">print</span></span>
<spanid="cb3-35"><ahref="#cb3-35" aria-hidden="true" tabindex="-1"></a><spanclass="kw">print</span><spanclass="st">"OTHER:"</span></span>
<spanid="cb3-36"><ahref="#cb3-36" aria-hidden="true" tabindex="-1"></a><spanclass="kw">print</span></span>
<spanid="cb3-37"><ahref="#cb3-37" aria-hidden="true" tabindex="-1"></a><spanclass="kw">print</span> esc.QUOTE + <spanclass="st">"YOU CAN USE QUOTES"</span> + esc.QUOTE</span>
<spanid="cb3-38"><ahref="#cb3-38" aria-hidden="true" tabindex="-1"></a><spanclass="kw">print</span> esc.BP + <spanclass="st">"A BEEP SHOULD BE AUDIBLE"</span></span></code></pre></div>
<h2id="escape-codes-in-smallbasic-console-version">Escape codes in
SmallBASIC console version</h2>
<p>In the console version of SmallBASIC (sbasic.exe or sbasic) most of
the escape codes, for example <a
href="http://en.wikipedia.org/wiki/ANSI_escape_code">ANSI Codes at
wikipedia</a>, can be used in version 12.25 or later. Support of escape
codes depends on the operating system and the terminal you are
using.</p>
</div>
<divclass="pagefooter">
This page was last edited on Sat, 9 Sep 2023 22:31:16 +0200
|
<ahref="https://en.wikipedia.org/wiki/Markdown" target="_blank" rel="nofollow">Markdown</a>
processed with
<ahref="https://pandoc.org/MANUAL.html#pandocs-markdown" target="_blank" rel="nofollow">pandoc 3.1.12.1</a>
</div>
</div>
</div>
</body>
</html>