-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathescape.html
More file actions
144 lines (144 loc) · 15.4 KB
/
Copy pathescape.html
File metadata and controls
144 lines (144 loc) · 15.4 KB
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>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>SmallBASIC | escape</title>
<meta name="description" content="SmallBASIC | One more basic">
<link rel="canonical" href="/escape.html">
<link rel="keywords" href="escape">
<link rel="stylesheet" href="/css/style.css">
<link rel="icon" type="image/png" href="/images/sb-desktop-32x32.png">
<script src="/clipboard.js"></script>
</head>
<body>
<button onclick="topFunction()" id="BackToTopBtn" title="Go to top">⯅</button>
<script src="/backtotop.js"></script>
<div class="wrapAll clearfix">
<nav class="navigation">
<div class="logo">
<a href="/"><img src='/images/sb-logo.png?v=2' alt="logo"></a>
</div>
<div class="navlinks">
<a href="/pages/download.html">Download</a>
<a href="/pages/news.html">News</a>
<a href="/pages/community.html">Community</a>
<a class='active' href="/pages/articles.html">Resources</a>
<a href="/pages/reference.html">Language Reference</a>
<a href="/pages/guide.html">SmallBASIC Manual</a>
</div>
</nav>
<div class="mainsection">
<div class="tabs clearfix">
<div class="tabsRight">
<a target="_github" href="https://github.com/smallbasic/smallbasic.github.io/blob/master/_build/pages/escape.markdown">Edit</a>
<a target="_github" href="https://github.com/smallbasic/smallbasic.github.io/commits/master/_build/pages/escape.markdown">History</a>
</div>
</div>
<div class="article">
<h1 id="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>
<h2 id="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>
<h2 id="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>
<div class="sourceCode" id="cb2"><pre
class="sourceCode smallbasic"><code class="sourceCode smallbasic"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="kw">PRINT</span> <span class="fu">CHR</span>(<span class="dv">27</span>) + <span class="st">"[1mTHIS IS BOLD"</span> + <span class="fu">CHR</span>(<span class="dv">27</span>) + <span class="st">"[0m"</span></span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a><span class="kw">PRINT</span> <span class="fu">CHR</span>(<span class="dv">27</span>) + <span class="st">"[3mThis is italic"</span> + <span class="fu">CHR</span>(<span class="dv">27</span>) + <span class="st">"[0m"</span></span>
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a><span class="kw">PRINT</span> <span class="fu">CHR</span>(<span class="dv">27</span>) + <span class="st">"[4mThis is underline"</span></span>
<span id="cb2-4"><a href="#cb2-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-5"><a href="#cb2-5" aria-hidden="true" tabindex="-1"></a><span class="kw">PRINT</span> <span class="st">"\e[32mGreen text"</span></span>
<span id="cb2-6"><a href="#cb2-6" aria-hidden="true" tabindex="-1"></a><span class="kw">PRINT</span> <span class="st">"\e[32m\e[47mGreen text on white background"</span></span>
<span id="cb2-7"><a href="#cb2-7" aria-hidden="true" tabindex="-1"></a><span class="kw">PRINT</span> <span class="st">"First line\nSecond Line"</span></span></code></pre></div>
<h2 id="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>
<div class="sourceCode" id="cb3"><pre
class="sourceCode smallbasic"><code class="sourceCode smallbasic"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="co">' SmallBASIC 12.25</span></span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a><span class="co">' Example for using UNIT "EscapeCodes"</span></span>
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a><span class="co">' For more information see: https://smallbasic.github.io/pages/escape.html</span></span>
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-5"><a href="#cb3-5" aria-hidden="true" tabindex="-1"></a><span class="pp">import</span> EscapeCodes <span class="kw">as</span> esc</span>
<span id="cb3-6"><a href="#cb3-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-7"><a href="#cb3-7" aria-hidden="true" tabindex="-1"></a><span class="kw">print</span> <span class="st">"FORMATING TEXT:"</span></span>
<span id="cb3-8"><a href="#cb3-8" aria-hidden="true" tabindex="-1"></a><span class="kw">print</span></span>
<span id="cb3-9"><a href="#cb3-9" aria-hidden="true" tabindex="-1"></a><span class="kw">print</span> esc.NORMAL + <span class="st">"WITHOUT ANY FORMAT "</span> + esc.ITALIC + <span class="st">"ITALIC "</span> + esc.ITALIC_OFF + esc.BOLD + <span class="st">"BOLD "</span> + esc.BOLD_OFF + esc.UNDERLINE + <span class="st">"UNDERLINE "</span> + esc.UNDERLINE_OFF + esc.REVERSE + <span class="st">"REVERSE"</span> + esc.REVERSE_OFF</span>
<span id="cb3-10"><a href="#cb3-10" aria-hidden="true" tabindex="-1"></a><span class="kw">print</span></span>
<span id="cb3-11"><a href="#cb3-11" aria-hidden="true" tabindex="-1"></a><span class="kw">print</span> <span class="st">"USE COLORS:"</span></span>
<span id="cb3-12"><a href="#cb3-12" aria-hidden="true" tabindex="-1"></a><span class="kw">print</span></span>
<span id="cb3-13"><a href="#cb3-13" aria-hidden="true" tabindex="-1"></a><span class="kw">print</span> esc.BG_BLACK + esc.BLACK + <span class="st">" BLACK "</span> + esc.RED + <span class="st">" RED "</span> + esc.GREEN + <span class="st">" GREEN "</span> + esc.YELLOW + <span class="st">" YELLOW "</span> + esc.BLUE + <span class="st">" BLUE "</span> + esc.MAGENTA + <span class="st">" MAGENTA "</span> + esc.CYAN + <span class="st">" CYAN "</span> + esc.WHITE + <span class="st">" WHITE "</span> + esc.NORMAL</span>
<span id="cb3-14"><a href="#cb3-14" aria-hidden="true" tabindex="-1"></a><span class="kw">print</span> esc.BG_RED + esc.BLACK + <span class="st">" BLACK "</span> + esc.RED + <span class="st">" RED "</span> + esc.GREEN + <span class="st">" GREEN "</span> + esc.YELLOW + <span class="st">" YELLOW "</span> + esc.BLUE + <span class="st">" BLUE "</span> + esc.MAGENTA + <span class="st">" MAGENTA "</span> + esc.CYAN + <span class="st">" CYAN "</span> + esc.WHITE + <span class="st">" WHITE "</span> + esc.NORMAL</span>
<span id="cb3-15"><a href="#cb3-15" aria-hidden="true" tabindex="-1"></a><span class="kw">print</span> esc.BG_GREEN + esc.BLACK + <span class="st">" BLACK "</span> + esc.RED + <span class="st">" RED "</span> + esc.GREEN + <span class="st">" GREEN "</span> + esc.YELLOW + <span class="st">" YELLOW "</span> + esc.BLUE + <span class="st">" BLUE "</span> + esc.MAGENTA + <span class="st">" MAGENTA "</span> + esc.CYAN + <span class="st">" CYAN "</span> + esc.WHITE + <span class="st">" WHITE "</span> + esc.NORMAL</span>
<span id="cb3-16"><a href="#cb3-16" aria-hidden="true" tabindex="-1"></a><span class="kw">print</span> esc.BG_YELLOW + esc.BLACK + <span class="st">" BLACK "</span> + esc.RED + <span class="st">" RED "</span> + esc.GREEN + <span class="st">" GREEN "</span> + esc.YELLOW + <span class="st">" YELLOW "</span> + esc.BLUE + <span class="st">" BLUE "</span> + esc.MAGENTA + <span class="st">" MAGENTA "</span> + esc.CYAN + <span class="st">" CYAN "</span> + esc.WHITE + <span class="st">" WHITE "</span> + esc.NORMAL</span>
<span id="cb3-17"><a href="#cb3-17" aria-hidden="true" tabindex="-1"></a><span class="kw">print</span> esc.BG_BLUE + esc.BLACK + <span class="st">" BLACK "</span> + esc.RED + <span class="st">" RED "</span> + esc.GREEN + <span class="st">" GREEN "</span> + esc.YELLOW + <span class="st">" YELLOW "</span> + esc.BLUE + <span class="st">" BLUE "</span> + esc.MAGENTA + <span class="st">" MAGENTA "</span> + esc.CYAN + <span class="st">" CYAN "</span> + esc.WHITE + <span class="st">" WHITE "</span> + esc.NORMAL</span>
<span id="cb3-18"><a href="#cb3-18" aria-hidden="true" tabindex="-1"></a><span class="kw">print</span> esc.BG_MAGENTA + esc.BLACK + <span class="st">" BLACK "</span> + esc.RED + <span class="st">" RED "</span> + esc.GREEN + <span class="st">" GREEN "</span> + esc.YELLOW + <span class="st">" YELLOW "</span> + esc.BLUE + <span class="st">" BLUE "</span> + esc.MAGENTA + <span class="st">" MAGENTA "</span> + esc.CYAN + <span class="st">" CYAN "</span> + esc.WHITE + <span class="st">" WHITE "</span> + esc.NORMAL</span>
<span id="cb3-19"><a href="#cb3-19" aria-hidden="true" tabindex="-1"></a><span class="kw">print</span> esc.BG_CYAN + esc.BLACK + <span class="st">" BLACK "</span> + esc.RED + <span class="st">" RED "</span> + esc.GREEN + <span class="st">" GREEN "</span> + esc.YELLOW + <span class="st">" YELLOW "</span> + esc.BLUE + <span class="st">" BLUE "</span> + esc.MAGENTA + <span class="st">" MAGENTA "</span> + esc.CYAN + <span class="st">" CYAN "</span> + esc.WHITE + <span class="st">" WHITE "</span> + esc.NORMAL</span>
<span id="cb3-20"><a href="#cb3-20" aria-hidden="true" tabindex="-1"></a><span class="kw">print</span> esc.BG_WHITE + esc.BLACK + <span class="st">" BLACK "</span> + esc.RED + <span class="st">" RED "</span> + esc.GREEN + <span class="st">" GREEN "</span> + esc.YELLOW + <span class="st">" YELLOW "</span> + esc.BLUE + <span class="st">" BLUE "</span> + esc.MAGENTA + <span class="st">" MAGENTA "</span> + esc.CYAN + <span class="st">" CYAN "</span> + esc.WHITE + <span class="st">" WHITE "</span> + esc.NORMAL</span>
<span id="cb3-21"><a href="#cb3-21" aria-hidden="true" tabindex="-1"></a><span class="kw">print</span> esc.NORMAL</span>
<span id="cb3-22"><a href="#cb3-22" aria-hidden="true" tabindex="-1"></a><span class="kw">print</span> <span class="st">"USE COLORS AND FORMATS:"</span></span>
<span id="cb3-23"><a href="#cb3-23" aria-hidden="true" tabindex="-1"></a><span class="kw">print</span></span>
<span id="cb3-24"><a href="#cb3-24" aria-hidden="true" tabindex="-1"></a><span class="kw">print</span> esc.NORMAL + esc.BOLD + esc.UNDERLINE + esc.GREEN + esc.BG_WHITE + <span class="st">"BOLD + UNDELINE + COLOR"</span> + esc.NORMAL</span>
<span id="cb3-25"><a href="#cb3-25" aria-hidden="true" tabindex="-1"></a><span class="kw">print</span></span>
<span id="cb3-26"><a href="#cb3-26" aria-hidden="true" tabindex="-1"></a><span class="kw">print</span> <span class="st">"CONTROL THE CURSOR:"</span></span>
<span id="cb3-27"><a href="#cb3-27" aria-hidden="true" tabindex="-1"></a><span class="kw">print</span></span>
<span id="cb3-28"><a href="#cb3-28" aria-hidden="true" tabindex="-1"></a><span class="kw">print</span> esc.MOVE_TO_COLUMN(<span class="dv">4</span>) + <span class="st">"MOVE TO COLUMN 4"</span></span>
<span id="cb3-29"><a href="#cb3-29" aria-hidden="true" tabindex="-1"></a><span class="kw">print</span> <span class="st">"TABS:"</span> + esc.TB + <span class="st">"ONE TAB"</span> + esc.TB + esc.TB + <span class="st">"TWO MORE TABS"</span></span>
<span id="cb3-30"><a href="#cb3-30" aria-hidden="true" tabindex="-1"></a><span class="kw">print</span> <span class="st">"YOU SHOULD NOT READ THIS"</span> + esc.RET + <span class="st">"RETURN TO BEGIN OF LINE "</span></span>
<span id="cb3-31"><a href="#cb3-31" aria-hidden="true" tabindex="-1"></a><span class="kw">print</span> <span class="st">"FIRST LINE"</span> + esc.NEXTLINE + <span class="st">"NEXT LINE"</span></span>
<span id="cb3-32"><a href="#cb3-32" aria-hidden="true" tabindex="-1"></a><span class="kw">print</span> esc.SAVECURSOR + <span class="st">"YOU SHOULD NOT READ THIS"</span> </span>
<span id="cb3-33"><a href="#cb3-33" aria-hidden="true" tabindex="-1"></a><span class="kw">print</span> esc.RESTORECURSOR + esc.CLEAR_LINE + <span class="st">"SAVE AND RESTORE THE CURSOR POSITION"</span></span>
<span id="cb3-34"><a href="#cb3-34" aria-hidden="true" tabindex="-1"></a><span class="kw">print</span></span>
<span id="cb3-35"><a href="#cb3-35" aria-hidden="true" tabindex="-1"></a><span class="kw">print</span> <span class="st">"OTHER:"</span></span>
<span id="cb3-36"><a href="#cb3-36" aria-hidden="true" tabindex="-1"></a><span class="kw">print</span></span>
<span id="cb3-37"><a href="#cb3-37" aria-hidden="true" tabindex="-1"></a><span class="kw">print</span> esc.QUOTE + <span class="st">"YOU CAN USE QUOTES"</span> + esc.QUOTE</span>
<span id="cb3-38"><a href="#cb3-38" aria-hidden="true" tabindex="-1"></a><span class="kw">print</span> esc.BP + <span class="st">"A BEEP SHOULD BE AUDIBLE"</span></span></code></pre></div>
<h2 id="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>
<div class="pagefooter">
This page was last edited on Sat, 9 Sep 2023 22:31:16 +0200
|
<a href="https://en.wikipedia.org/wiki/Markdown" target="_blank" rel="nofollow">Markdown</a>
processed with
<a href="https://pandoc.org/MANUAL.html#pandocs-markdown" target="_blank" rel="nofollow">pandoc 3.1.12.1</a>
</div>
</div>
</div>
</body>
</html>