Skip to content

Update of command references #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 49 commits into from
Dec 22, 2022
Merged
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
921245c
Update 580-file-access.markdown
Joe7M Nov 30, 2022
76d1128
Update 581-data-append.markdown
Joe7M Dec 1, 2022
eed55a2
Update 611-graphics-arc.markdown
Joe7M Dec 1, 2022
ea3d609
Update 1432-data-array.markdown
Joe7M Dec 1, 2022
6eb753d
Update 771-string-asc.markdown
Joe7M Dec 1, 2022
e42e480
Update 521-console-at.markdown
Joe7M Dec 1, 2022
45ea467
Update 663-language-band.markdown
Joe7M Dec 1, 2022
0c96ef1
Update 1428-language-bg.markdown
Joe7M Dec 1, 2022
6638d0a
Update 773-string-bin.markdown
Joe7M Dec 1, 2022
9ca9b7f
Update 664-language-bor.markdown
Joe7M Dec 1, 2022
9bf4bc2
Update 639-language-byref.markdown
Joe7M Dec 3, 2022
828bf74
Update 637-language-call.markdown
Joe7M Dec 3, 2022
9ebf196
Update 1734-system-self.markdown
Joe7M Dec 3, 2022
493ac9c
Update 742-math-polycent.markdown
Joe7M Dec 4, 2022
ce8e782
Update 741-math-polyarea.markdown
Joe7M Dec 4, 2022
8032a37
Merge pull request #1 from Joe7M/patch-1
Joe7M Dec 4, 2022
d4ca8da
Merge pull request #2 from Joe7M/patch-2
Joe7M Dec 4, 2022
4b30050
Update 741-math-polyarea.markdown
Joe7M Dec 4, 2022
3ba7f29
Update 662-language-and.markdown
Joe7M Dec 13, 2022
26cf12e
Update 772-string-bcs.markdown
Joe7M Dec 17, 2022
ba3e59a
Update 774-string-cbs.markdown
Joe7M Dec 17, 2022
51fb41b
Update 602-file-bgetc.markdown
Joe7M Dec 17, 2022
a18465a
Update 583-file-bputc.markdown
Joe7M Dec 17, 2022
a348b73
Update 602-file-bgetc.markdown
Joe7M Dec 17, 2022
da0b24b
Update 655-language-select.markdown
Joe7M Dec 17, 2022
58b571e
Update 640-language-case.markdown
Joe7M Dec 17, 2022
c12903d
Update 538-console-cat.markdown
Joe7M Dec 17, 2022
6e39148
Update 1426-language-catch.markdown
Joe7M Dec 17, 2022
cad2c09
Update 1425-language-try.markdown
Joe7M Dec 17, 2022
1d9aa6c
Update 1439-system-chain.markdown
Joe7M Dec 17, 2022
393c602
Update 612-graphics-chart.markdown
Joe7M Dec 17, 2022
94a7ef5
Update 585-file-chdir.markdown
Joe7M Dec 17, 2022
bc73609
Update 586-file-chmod.markdown
Joe7M Dec 17, 2022
431eb2c
Update 775-string-chop.markdown
Joe7M Dec 18, 2022
2a9d779
Update 776-string-chr.markdown
Joe7M Dec 18, 2022
1acc266
Update 613-graphics-circle.markdown
Joe7M Dec 18, 2022
79eeaf9
Update 594-file-open.markdown
Joe7M Dec 18, 2022
039c839
Update 587-file-close.markdown
Joe7M Dec 18, 2022
0e33778
Update 524-console-cls.markdown
Joe7M Dec 18, 2022
7b9f394
Update 614-graphics-color.markdown
Joe7M Dec 18, 2022
dc68af2
Update 1521-system-command.markdown
Joe7M Dec 18, 2022
cd6fb45
Update 678-language-const.markdown
Joe7M Dec 18, 2022
ceb306f
Update 588-file-copy.markdown
Joe7M Dec 18, 2022
53a8923
Update 1522-system-cwd.markdown
Joe7M Dec 18, 2022
4ff91dc
Update escape.markdown
Joe7M Dec 20, 2022
9b363c5
Update 594-file-open.markdown
Joe7M Dec 20, 2022
171618d
Update guide.markdown
Joe7M Dec 22, 2022
ed30cb6
Update reference.json
Joe7M Dec 22, 2022
2ed2c3c
Create 1800-math-statstd.markdown
Joe7M Dec 22, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 64 additions & 21 deletions _build/pages/escape.markdown
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
# Escape codes

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.
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).

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.

Escape sequences start with the characters ESC (ASCII 27d / 1Bh / 033o ) and [ (left bracket). This sequence is called CSI for "Control Sequence Introducer".

The supported standard codes are:
## The supported standard codes are:

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

Useful non-standard codes include:
## Using the escape codes directly

```
\003 end of text (flush buffer)
\m scroll to the top
\<1 select backscreen 1
\<2 select backscreen 2
\>1 select frontscreen 1
\<2 select frontscreen 2
The instead of "\e" the CHR command is useful for obtaining and printing the escape character (ASCII 27)

```Freebasic
PRINT CHR(27) + "[1mTHIS IS BOLD" + CHR(27) + "[0m"
PRINT CHR(27) + "[3mThis is italic" + CHR(27) + "[0m"
PRINT CHR(27) + "[4mThis is underline"

PRINT "\e[32mGreen text"
PRINT "\e[32m\e[47mGreen text on white background"
PRINT "First line\nSecond Line"
```

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

For example:
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.

Here an example on how to use the unit.

```Freebasic
' SmallBASIC 12.25
' Example for using UNIT "EscapeCodes"
' For more information see: https://smallbasic.github.io/pages/escape.html

import EscapeCodes as esc

print "FORMATING TEXT:"
print
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
print
print "USE COLORS:"
print
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
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
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
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
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
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
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
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
print esc.NORMAL
print "USE COLORS AND FORMATS:"
print
print esc.NORMAL + esc.BOLD + esc.UNDERLINE + esc.GREEN + esc.BG_WHITE + "BOLD + UNDELINE + COLOR" + esc.NORMAL
print
print "CONTROL THE CURSOR:"
print
print esc.MOVE_TO_COLUMN(4) + "MOVE TO COLUMN 4"
print "TABS:" + esc.TB + "ONE TAB" + esc.TB + esc.TB + "TWO MORE TABS"
print "YOU SHOULD NOT READ THIS" + esc.RET + "RETURN TO BEGIN OF LINE "
print "FIRST LINE" + esc.NEXTLINE + "NEXT LINE"
print esc.SAVECURSOR + "YOU SHOULD NOT READ THIS"
print esc.RESTORECURSOR + esc.CLEAR_LINE + "SAVE AND RESTORE THE CURSOR POSITION"
print
print "OTHER:"
print
print esc.QUOTE + "YOU CAN USE QUOTES" + esc.QUOTE
print esc.BP + "A BEEP SHOULD BE AUDIBLE"
```
10 PRINT CHR(27) + "[1mTHIS IS BOLD" + CHR(27) + "[0m"
20 PRINT CHR(27) + "[3mThis is italic" + CHR(27) + "[0m"
30 PRINT CHR(27) + "[4mThis is underline"
```

## Escape codes in SmallBASIC console version

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.


15 changes: 12 additions & 3 deletions _build/pages/guide.markdown
Original file line number Diff line number Diff line change
@@ -103,6 +103,14 @@ Strings may be appended to one another using the + operator.
b = "Hello, " + "world!"
```

```
b = """This is
a string
over several lines
with line breaks"""
```


### Constants {#Constants}

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

~~~
OPTION PREDEF GRMODE 320x320x16
~~~
~~~
OPTION PREDEF GRMODE 320x320x16
~~~

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

### Meta-commands {#Meta}

35 changes: 21 additions & 14 deletions _build/reference.json
Original file line number Diff line number Diff line change
@@ -1322,7 +1322,7 @@
"type": "function"
},
{
"help": "Inverse cosine.",
"help": "Inverse hyperbolic cosine.",
"keyword": "ACOSH",
"nodeID": "708",
"signature": "ACOSH (x)",
@@ -1336,7 +1336,7 @@
"type": "function"
},
{
"help": "Inverse cotangent.",
"help": "Inverse hyperbolic cotangent.",
"keyword": "ACOTH",
"nodeID": "710",
"signature": "ACOTH (x)",
@@ -1350,7 +1350,7 @@
"type": "function"
},
{
"help": "Inverse co secant.",
"help": "Inverse hyperbolic co secant.",
"keyword": "ACSCH",
"nodeID": "712",
"signature": "ACSCH (x)",
@@ -1364,7 +1364,7 @@
"type": "function"
},
{
"help": "Inverse secant.",
"help": "Inverse hyperbolic secant.",
"keyword": "ASECH",
"nodeID": "714",
"signature": "ASECH (x)",
@@ -1378,7 +1378,7 @@
"type": "function"
},
{
"help": "Inverse sine.",
"help": "Inverse hyperbolic sine.",
"keyword": "ASINH",
"nodeID": "716",
"signature": "ASINH (x)",
@@ -1399,7 +1399,7 @@
"type": "function"
},
{
"help": "Inverse tangent.",
"help": "Inverse hyperbolic tangent.",
"keyword": "ATANH",
"nodeID": "719",
"signature": "ATANH (x)",
@@ -1427,7 +1427,7 @@
"type": "function"
},
{
"help": "Cosine.",
"help": "Hyperbolic cosine.",
"keyword": "COSH",
"nodeID": "723",
"signature": "COSH (x)",
@@ -1441,7 +1441,7 @@
"type": "function"
},
{
"help": "Cotangent.",
"help": "Hyperbolic cotangent.",
"keyword": "COTH",
"nodeID": "725",
"signature": "COTH (x)",
@@ -1455,7 +1455,7 @@
"type": "function"
},
{
"help": "Co secant.",
"help": "Hyperbolic co secant.",
"keyword": "CSCH",
"nodeID": "727",
"signature": "CSCH (x)",
@@ -1623,7 +1623,7 @@
"type": "function"
},
{
"help": "Secant.",
"help": "Hyperbolic secant.",
"keyword": "SECH",
"nodeID": "751",
"signature": "SECH (x)",
@@ -1672,7 +1672,7 @@
"type": "function"
},
{
"help": "Sine.",
"help": "Hyperbolic sine.",
"keyword": "SINH",
"nodeID": "758",
"signature": "SINH (x)",
@@ -1693,21 +1693,28 @@
"type": "function"
},
{
"help": "Mean deviation.",
"help": "Standard deviation.",
"keyword": "STATSTD",
"nodeID": "1800",
"signature": "STATSTD (...)",
"type": "function"
},
{
"help": "Mean absolute deviation around arithmetic mean.",
"keyword": "STATMEANDEV",
"nodeID": "761",
"signature": "STATMEANDEV (...)",
"type": "function"
},
{
"help": "Sample spread.",
"help": "Biased sample variance.",
"keyword": "STATSPREADP",
"nodeID": "762",
"signature": "STATSPREADS (...)",
"type": "function"
},
{
"help": "Population spread.",
"help": "Unbiased sample variance.",
"keyword": "STATSPREADS",
"nodeID": "763",
"signature": "STATSPREADP (...)",
45 changes: 39 additions & 6 deletions _build/reference/1425-language-try.markdown
Original file line number Diff line number Diff line change
@@ -2,12 +2,39 @@

> TRY

The TRY statement introduces a TRY/CATCH BLOCK
__TRY__

The TRY statement introduces a TRY/CATCH block.

__CATCH [var | expr]__

Note:
If this demo program crashes... then run it again. It seems that TRY / CATCH block might be unstable within a function or sub... (?)
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.

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.

__END TRY__

The END TRY statement marks the end of a TRY/CATCH block.


### Example 1: Opening a non-existing file for reading

```
try
' DON'T use existing file for demo.
open "try demo.tmp" for input as #1
catch err
print err; " "
' Some error handling could be implemented here
' i.e: if(err = "...") then ...
end try

print "This point is reach, even if opening the file was not possible"
```

### Example 2: Advanced error handling for opening files

~~~

@@ -21,7 +48,7 @@ Func opens(filename, mode)
Case "input" : Open filename For Input As #fn
Case "output": Open filename For Output As #fn
Case "append": Open filename For Append As #fn
Case Else: ? "opens(): Bad open mode at line " + Progline: Pause: Stop
Case Else: ? "opens(): Bad open mode at line " + Progline: Stop
End Select
opens = fn ' file opened, return file-handle (integer 1 to 256)
Catch err
@@ -72,8 +99,14 @@ If fn Then
? lines;
Close #fn
Fi
Pause

~~~

### Example 3: Open COM-Port

```
try
open "com2000:" AS #1
catch err
? "in catch: open failed";err
end try
```
8 changes: 3 additions & 5 deletions _build/reference/1426-language-catch.markdown
Original file line number Diff line number Diff line change
@@ -2,11 +2,9 @@

> CATCH [var | expr]

The CATCH statement is used to CATCH an run-time error.
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.

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.
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.

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.
For more information and examples please see TRY.

8 changes: 7 additions & 1 deletion _build/reference/1428-language-bg.markdown
Original file line number Diff line number Diff line change
@@ -2,7 +2,13 @@

> SOUND frq, dur [, vol] [BG]

Play sound in the background. This prevent the program from blocking while the sound plays.
Play sound in the background. BG prevents the program from blocking while the sound plays.

See SOUND.

```
SOUND 1000, 1000 BG
```



Loading
Oops, something went wrong.