Skip to content

Commit 4a0fbea

Browse files
authored
Merge pull request #15 from Joe7M/master
Update of command references
2 parents 15257b7 + 2ed2c3c commit 4a0fbea

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+981
-835
lines changed

_build/pages/escape.markdown

Lines changed: 64 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
# Escape codes
22

3-
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.
3+
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 [ANSI Codes](http://en.wikipedia.org/wiki/ANSI_escape_code).
44

5-
The escape codes are based on [ANSI Codes](http://en.wikipedia.org/wiki/ANSI_escape_code). SmallBASIC also support a number of additional codes which are not part of the standard.
6-
7-
Escape sequences start with the characters ESC (ASCII 27d / 1Bh / 033o ) and [ (left bracket). This sequence is called CSI for "Control Sequence Introducer".
8-
9-
The supported standard codes are:
5+
## The supported standard codes are:
106

117
```
128
\a beep
139
\t tab (20 px)
1410
\r return
1511
\n next line
16-
\xC clear screen (new page)
12+
\" quote "
13+
\\ Backslash \
1714
\e[K clear to end of line
1815
\e[nG move to column n
1916
\e[s save cursor position
@@ -30,23 +27,69 @@ The supported standard codes are:
3027
\e[nm n colors - 30..37 foreground, 40..47 background
3128
```
3229

33-
Useful non-standard codes include:
30+
## Using the escape codes directly
3431

35-
```
36-
\003 end of text (flush buffer)
37-
\m scroll to the top
38-
\<1 select backscreen 1
39-
\<2 select backscreen 2
40-
\>1 select frontscreen 1
41-
\<2 select frontscreen 2
32+
The instead of "\e" the CHR command is useful for obtaining and printing the escape character (ASCII 27)
33+
34+
```Freebasic
35+
PRINT CHR(27) + "[1mTHIS IS BOLD" + CHR(27) + "[0m"
36+
PRINT CHR(27) + "[3mThis is italic" + CHR(27) + "[0m"
37+
PRINT CHR(27) + "[4mThis is underline"
38+
39+
PRINT "\e[32mGreen text"
40+
PRINT "\e[32m\e[47mGreen text on white background"
41+
PRINT "First line\nSecond Line"
4242
```
4343

44-
The CHR command is useful for obtaining and printing the escape character (ASCII 27)
44+
## Using the EscapeCode Unit
4545

46-
For example:
46+
The EscapeCode Unit makes it easier to use the escape codes and to deal with the different colors for foreground and background. The uint can be downloaded or copy pasted from the [SmallBASIC Github website](https://github.com/smallbasic/smallbasic.plugins/blob/master/units/EscapeCodes.bas). Please save the unit in the same directory as you basic file.
4747

48+
Here an example on how to use the unit.
49+
50+
```Freebasic
51+
' SmallBASIC 12.25
52+
' Example for using UNIT "EscapeCodes"
53+
' For more information see: https://smallbasic.github.io/pages/escape.html
54+
55+
import EscapeCodes as esc
56+
57+
print "FORMATING TEXT:"
58+
print
59+
print esc.NORMAL + "WITHOUT ANY FORMAT " + esc.ITALIC + "ITALIC " + esc.ITALIC_OFF + esc.BOLD + "BOLD " + esc.BOLD_OFF + esc.UNDERLINE + "UNDERLINE " + esc.UNDERLINE_OFF + esc.REVERSE + "REVERSE" + esc.REVERSE_OFF
60+
print
61+
print "USE COLORS:"
62+
print
63+
print esc.BG_BLACK + esc.BLACK + " BLACK " + esc.RED + " RED " + esc.GREEN + " GREEN " + esc.YELLOW + " YELLOW " + esc.BLUE + " BLUE " + esc.MAGENTA + " MAGENTA " + esc.CYAN + " CYAN " + esc.WHITE + " WHITE " + esc.NORMAL
64+
print esc.BG_RED + esc.BLACK + " BLACK " + esc.RED + " RED " + esc.GREEN + " GREEN " + esc.YELLOW + " YELLOW " + esc.BLUE + " BLUE " + esc.MAGENTA + " MAGENTA " + esc.CYAN + " CYAN " + esc.WHITE + " WHITE " + esc.NORMAL
65+
print esc.BG_GREEN + esc.BLACK + " BLACK " + esc.RED + " RED " + esc.GREEN + " GREEN " + esc.YELLOW + " YELLOW " + esc.BLUE + " BLUE " + esc.MAGENTA + " MAGENTA " + esc.CYAN + " CYAN " + esc.WHITE + " WHITE " + esc.NORMAL
66+
print esc.BG_YELLOW + esc.BLACK + " BLACK " + esc.RED + " RED " + esc.GREEN + " GREEN " + esc.YELLOW + " YELLOW " + esc.BLUE + " BLUE " + esc.MAGENTA + " MAGENTA " + esc.CYAN + " CYAN " + esc.WHITE + " WHITE " + esc.NORMAL
67+
print esc.BG_BLUE + esc.BLACK + " BLACK " + esc.RED + " RED " + esc.GREEN + " GREEN " + esc.YELLOW + " YELLOW " + esc.BLUE + " BLUE " + esc.MAGENTA + " MAGENTA " + esc.CYAN + " CYAN " + esc.WHITE + " WHITE " + esc.NORMAL
68+
print esc.BG_MAGENTA + esc.BLACK + " BLACK " + esc.RED + " RED " + esc.GREEN + " GREEN " + esc.YELLOW + " YELLOW " + esc.BLUE + " BLUE " + esc.MAGENTA + " MAGENTA " + esc.CYAN + " CYAN " + esc.WHITE + " WHITE " + esc.NORMAL
69+
print esc.BG_CYAN + esc.BLACK + " BLACK " + esc.RED + " RED " + esc.GREEN + " GREEN " + esc.YELLOW + " YELLOW " + esc.BLUE + " BLUE " + esc.MAGENTA + " MAGENTA " + esc.CYAN + " CYAN " + esc.WHITE + " WHITE " + esc.NORMAL
70+
print esc.BG_WHITE + esc.BLACK + " BLACK " + esc.RED + " RED " + esc.GREEN + " GREEN " + esc.YELLOW + " YELLOW " + esc.BLUE + " BLUE " + esc.MAGENTA + " MAGENTA " + esc.CYAN + " CYAN " + esc.WHITE + " WHITE " + esc.NORMAL
71+
print esc.NORMAL
72+
print "USE COLORS AND FORMATS:"
73+
print
74+
print esc.NORMAL + esc.BOLD + esc.UNDERLINE + esc.GREEN + esc.BG_WHITE + "BOLD + UNDELINE + COLOR" + esc.NORMAL
75+
print
76+
print "CONTROL THE CURSOR:"
77+
print
78+
print esc.MOVE_TO_COLUMN(4) + "MOVE TO COLUMN 4"
79+
print "TABS:" + esc.TB + "ONE TAB" + esc.TB + esc.TB + "TWO MORE TABS"
80+
print "YOU SHOULD NOT READ THIS" + esc.RET + "RETURN TO BEGIN OF LINE "
81+
print "FIRST LINE" + esc.NEXTLINE + "NEXT LINE"
82+
print esc.SAVECURSOR + "YOU SHOULD NOT READ THIS"
83+
print esc.RESTORECURSOR + esc.CLEAR_LINE + "SAVE AND RESTORE THE CURSOR POSITION"
84+
print
85+
print "OTHER:"
86+
print
87+
print esc.QUOTE + "YOU CAN USE QUOTES" + esc.QUOTE
88+
print esc.BP + "A BEEP SHOULD BE AUDIBLE"
4889
```
49-
10 PRINT CHR(27) + "[1mTHIS IS BOLD" + CHR(27) + "[0m"
50-
20 PRINT CHR(27) + "[3mThis is italic" + CHR(27) + "[0m"
51-
30 PRINT CHR(27) + "[4mThis is underline"
52-
```
90+
91+
## Escape codes in SmallBASIC console version
92+
93+
In the console version of SmallBASIC (sbasic.exe or sbasic) most of the escape codes, for example [ANSI Codes at wikipedia](http://en.wikipedia.org/wiki/ANSI_escape_code), can be used in version 12.25 or later. The support of the escape codes depends on the operating system and the terminal you are using.
94+
95+

_build/pages/guide.markdown

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,14 @@ Strings may be appended to one another using the + operator.
103103
b = "Hello, " + "world!"
104104
```
105105

106+
```
107+
b = """This is
108+
a string
109+
over several lines
110+
with line breaks"""
111+
```
112+
113+
106114
### Constants {#Constants}
107115

108116
Constant variables can be declared by using the keyword CONST.
@@ -204,12 +212,13 @@ Sets parameters of the compiler. Where [parameter]{.code}
204212
* COMMAND cmdstr Sets the [COMMAND$]{.code} string to [var]{.code} (useful for debug reasons)
205213
* GRMODE [widthxheight[xbpp]] Sets the graphics mode flag (-g option) or sets the preferred screen resolution. Example: (Clie HiRes)
206214

207-
~~~
208-
OPTION PREDEF GRMODE 320x320x16
209-
~~~
215+
~~~
216+
OPTION PREDEF GRMODE 320x320x16
217+
~~~
210218

211219
* TEXTMODE Sets the text mode flag (-g- option)
212220
* CSTR Sets as default string style the C-style special character encoding ('\\')
221+
* ANTIALIAS off : Disable anti-aliasing for drawing commands like CIRCEL or LINE
213222

214223
### Meta-commands {#Meta}
215224

_build/reference.json

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,7 +1322,7 @@
13221322
"type": "function"
13231323
},
13241324
{
1325-
"help": "Inverse cosine.",
1325+
"help": "Inverse hyperbolic cosine.",
13261326
"keyword": "ACOSH",
13271327
"nodeID": "708",
13281328
"signature": "ACOSH (x)",
@@ -1336,7 +1336,7 @@
13361336
"type": "function"
13371337
},
13381338
{
1339-
"help": "Inverse cotangent.",
1339+
"help": "Inverse hyperbolic cotangent.",
13401340
"keyword": "ACOTH",
13411341
"nodeID": "710",
13421342
"signature": "ACOTH (x)",
@@ -1350,7 +1350,7 @@
13501350
"type": "function"
13511351
},
13521352
{
1353-
"help": "Inverse co secant.",
1353+
"help": "Inverse hyperbolic co secant.",
13541354
"keyword": "ACSCH",
13551355
"nodeID": "712",
13561356
"signature": "ACSCH (x)",
@@ -1364,7 +1364,7 @@
13641364
"type": "function"
13651365
},
13661366
{
1367-
"help": "Inverse secant.",
1367+
"help": "Inverse hyperbolic secant.",
13681368
"keyword": "ASECH",
13691369
"nodeID": "714",
13701370
"signature": "ASECH (x)",
@@ -1378,7 +1378,7 @@
13781378
"type": "function"
13791379
},
13801380
{
1381-
"help": "Inverse sine.",
1381+
"help": "Inverse hyperbolic sine.",
13821382
"keyword": "ASINH",
13831383
"nodeID": "716",
13841384
"signature": "ASINH (x)",
@@ -1399,7 +1399,7 @@
13991399
"type": "function"
14001400
},
14011401
{
1402-
"help": "Inverse tangent.",
1402+
"help": "Inverse hyperbolic tangent.",
14031403
"keyword": "ATANH",
14041404
"nodeID": "719",
14051405
"signature": "ATANH (x)",
@@ -1427,7 +1427,7 @@
14271427
"type": "function"
14281428
},
14291429
{
1430-
"help": "Cosine.",
1430+
"help": "Hyperbolic cosine.",
14311431
"keyword": "COSH",
14321432
"nodeID": "723",
14331433
"signature": "COSH (x)",
@@ -1441,7 +1441,7 @@
14411441
"type": "function"
14421442
},
14431443
{
1444-
"help": "Cotangent.",
1444+
"help": "Hyperbolic cotangent.",
14451445
"keyword": "COTH",
14461446
"nodeID": "725",
14471447
"signature": "COTH (x)",
@@ -1455,7 +1455,7 @@
14551455
"type": "function"
14561456
},
14571457
{
1458-
"help": "Co secant.",
1458+
"help": "Hyperbolic co secant.",
14591459
"keyword": "CSCH",
14601460
"nodeID": "727",
14611461
"signature": "CSCH (x)",
@@ -1623,7 +1623,7 @@
16231623
"type": "function"
16241624
},
16251625
{
1626-
"help": "Secant.",
1626+
"help": "Hyperbolic secant.",
16271627
"keyword": "SECH",
16281628
"nodeID": "751",
16291629
"signature": "SECH (x)",
@@ -1672,7 +1672,7 @@
16721672
"type": "function"
16731673
},
16741674
{
1675-
"help": "Sine.",
1675+
"help": "Hyperbolic sine.",
16761676
"keyword": "SINH",
16771677
"nodeID": "758",
16781678
"signature": "SINH (x)",
@@ -1693,21 +1693,28 @@
16931693
"type": "function"
16941694
},
16951695
{
1696-
"help": "Mean deviation.",
1696+
"help": "Standard deviation.",
1697+
"keyword": "STATSTD",
1698+
"nodeID": "1800",
1699+
"signature": "STATSTD (...)",
1700+
"type": "function"
1701+
},
1702+
{
1703+
"help": "Mean absolute deviation around arithmetic mean.",
16971704
"keyword": "STATMEANDEV",
16981705
"nodeID": "761",
16991706
"signature": "STATMEANDEV (...)",
17001707
"type": "function"
17011708
},
17021709
{
1703-
"help": "Sample spread.",
1710+
"help": "Biased sample variance.",
17041711
"keyword": "STATSPREADP",
17051712
"nodeID": "762",
17061713
"signature": "STATSPREADS (...)",
17071714
"type": "function"
17081715
},
17091716
{
1710-
"help": "Population spread.",
1717+
"help": "Unbiased sample variance.",
17111718
"keyword": "STATSPREADS",
17121719
"nodeID": "763",
17131720
"signature": "STATSPREADP (...)",

_build/reference/1425-language-try.markdown

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,39 @@
22

33
> TRY
44
5-
The TRY statement introduces a TRY/CATCH BLOCK
5+
__TRY__
66

7+
The TRY statement introduces a TRY/CATCH block.
78

9+
__CATCH [var | expr]__
810

9-
Note:
10-
If this demo program crashes... then run it again. It seems that TRY / CATCH block might be unstable within a function or sub... (?)
11+
The CATCH statement is used to CATCH an run-time error. This is typically used with errors raised when calling a file system command that cannot be completed, for example attempting to open a non-existent file.
12+
13+
The CATCH statement has two modes. You can supply a variable argument to store the error string. Alternatively you can supply an expression. When the raised error matches the (String) expression, the error will be caught.
14+
15+
When using the expression mode, you can supply a succession of CATCH statements to handle various error messages separately.
16+
17+
__END TRY__
18+
19+
The END TRY statement marks the end of a TRY/CATCH block.
20+
21+
22+
### Example 1: Opening a non-existing file for reading
23+
24+
```
25+
try
26+
' DON'T use existing file for demo.
27+
open "try demo.tmp" for input as #1
28+
catch err
29+
print err; " "
30+
' Some error handling could be implemented here
31+
' i.e: if(err = "...") then ...
32+
end try
33+
34+
print "This point is reach, even if opening the file was not possible"
35+
```
36+
37+
### Example 2: Advanced error handling for opening files
1138

1239
~~~
1340
@@ -21,7 +48,7 @@ Func opens(filename, mode)
2148
Case "input" : Open filename For Input As #fn
2249
Case "output": Open filename For Output As #fn
2350
Case "append": Open filename For Append As #fn
24-
Case Else: ? "opens(): Bad open mode at line " + Progline: Pause: Stop
51+
Case Else: ? "opens(): Bad open mode at line " + Progline: Stop
2552
End Select
2653
opens = fn ' file opened, return file-handle (integer 1 to 256)
2754
Catch err
@@ -72,8 +99,14 @@ If fn Then
7299
? lines;
73100
Close #fn
74101
Fi
75-
Pause
76-
77102
~~~
78103

104+
### Example 3: Open COM-Port
79105

106+
```
107+
try
108+
open "com2000:" AS #1
109+
catch err
110+
? "in catch: open failed";err
111+
end try
112+
```

_build/reference/1426-language-catch.markdown

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22

33
> CATCH [var | expr]
44
5-
The CATCH statement is used to CATCH an run-time error.
5+
The CATCH statement is used to CATCH a run-time error. This is typically used with errors raised when calling a file system command that cannot be completed, for example attempting to open a non-existent file.
66

7-
This is typically used with errors raised when calling a file system command that cannot be completed, for example attempting to open a non-existent file.
7+
The CATCH statement has two modes. You can supply a variable argument to store the error string. Alternatively you can supply an expression. When the raised error matches the (String) expression, the error will be caught. When using the expression mode, you can supply a succession of CATCH statements to handle various error messages separately.
88

9-
The CATCH statement has two modes. You can supply a variable argument to store the error string. Alternatively you can supply an expression.
10-
11-
When the raised error matches the (String) expression, the error will be caught. When using the expression mode, you can supply a succession of CATCH statements to handle various error messages separately.
9+
For more information and examples please see TRY.
1210

_build/reference/1428-language-bg.markdown

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22

33
> SOUND frq, dur [, vol] [BG]
44
5-
Play sound in the background. This prevent the program from blocking while the sound plays.
5+
Play sound in the background. BG prevents the program from blocking while the sound plays.
6+
7+
See SOUND.
8+
9+
```
10+
SOUND 1000, 1000 BG
11+
```
612

713

814

0 commit comments

Comments
 (0)