hBasic > hManual > Commands > Console

hBasic Manual
Console command changes


BACKSPACE
Delete character of last row
PRINT.AT
PRINT.IMG
Print at a screen location
Print an image at screen location
CONSOLE.BACKIMG Set a console background image.
CONSOLE.GOTO
Puts a console row into view.
CONSOLE.SET


Set console attributes.

Column Based
Line Based
Console Based
VOIDCOLOR
LINECOLOR
DIVIDERS
SCROLL
STACK
TITLE (deprecated since v4.30)
.CS Shortcut Shortcut command for CONSOLE.SET
CONSOLE.SCREEN Get width or/and height as characters
CONSOLE.TITLE
CONSOLE.SUBTITLE
Title and Colors
Subtitle and Colors
CONSOLE.TAPPED Return information about a tap
CONSOLE.ORIENT Change orientation and preference
CONSOLE.EXIT Exit the console without exiting the editor
TGET and TGET.S/N/I/P
Overhauled
CLR
Clear till end of line

BACKSPACE

BACKSPACE  { <count_nexp> }

Deletes the last character(s) of the last console row and puts PRINT into append mode.

Rules;
    1. count must be greater than 0. If count is not given, 1 character is deleted.
    2. If count is greater than the length of the last line, all characters will be deleted leaving an empty line.
    3. Any PRINT following BACKSPACE is appended to the end of the line.
   

Examples
BACKSPACE             %  deletes 1 character backward.
BACKSPACE 5          %  deletes 5 characters backward.

PRINT.AT

PRINT.AT  <line_nexp> , <column_nexp>; {<exp> {, | ;}}

Print at screen location Line,Column;

Rules

1. <exp> is the same as the regular PRINT command.
2. line and column coordinates start from 1 (not 0).  Line 1 is at the top and Column 1 is at the left.
  
3. line = 0 will append after the last line
4. column =0 will append after the end of line

5. line < 0 will count upwards from bottom (-1=last line)
6. column < 0 will count backwards from end of line (-1 = last char)

7. If line > last_line then extra lines are added for padding.
8. If column > last_char_of_line then extra spaces are added for padding.

9. Any other lines or columns out-of-range (i.e above or left of screen) are ignored
        and the command has not effect.

10.  Although PRINT.AT does not obey PRINT's append mode, it will still
preserve any previous append mode (since v4.67).
i.e If a previous PRINT was in append mode ( ";" as last character), then the next PRINT will  append after the last line of the console, ( even if PRINT.AT created that line ).


Examples
PRINT.AT      2, 11; "print this at line 2, column 11"
PRINT.AT      0, 11;  "append after the last line at column 11"
PRINT.AT      2, 0;  "append after the end of  line 2"
PRINT.AT      -1, 11;  "print on last line at column 11"
PRINT.AT      -2, 11;  "print above last line at column 11"
PRINT.AT      2, -1;  "print over the last char of line 2"
PRINT.AT      3, -2;  "print from last two chars of line 3"


Notes:
PRINT.AT only works well with monospaced fonts.
PRINT.AT usually works well with "CONSOLE.SET WRAP OFF".
PRINT.AT will use the current (CONSOLE.SET) styles for it's content.
Some of these styles will affect the whole console,
others will affect only the content being printed.

PRINT.IMG

PRINT.IMG  <line_nexp>, <column_nexp> , <tag_sexp>, <file_name_sexp> {, <align_nexp>}{,scale_nexp> <}

e.g PRINT.IMG  5 , 5 , "mytag", "picture.png"

Print an image at the screen location Line,Column with a tag.
The purpose of this command is to be able to print small images on the console.

coordinates (not optional)

The coordinates line, column behave the same as PRINT.AT.

e.g to print after the last line, use PRINT.IMG 0,0, ..
        to print at the next position  PRINT.IMG -1,0, ..

Note that unlike PRINT.AT,
PRINT.IMG uses a comma after the coordinates instead of a semicolon.

tag
(not optional)

PRINT.IMG prints the image in place of a 'tag' string.
The tag is invisible but still occupies the columns of the string. 
Only the image will take up space.
You must supply a tag which is ideally just one word.

file_name (not optional)

The filename of the image. The default path is <base_dir>/data/
Accepted formats are jpg, png, bmp, gif.
align (optional)

The vertical alignment between the image and the surrounding text.
value
Name Description
0
Bottom
Aligns image to the bottom of text.
default
-1
Baseline
Aligns image to the baseline of text.
-2
Mid
Aligns image between Bottom and Baseline.

1 to 100
percent Aligns text to a percentage of the image height.
This affects text for the whole line.
other

All other values is the same as default 0.

bottom baseline mid
Bottom, Baseline, Mid

scale
(optional)
The image will be scaled to the value.

e.g 2 will enlarge to twice the size and 0.5 will reduce to half the size.
Negative values will invert the image.

Becareful with this parameter, as values too large may crash the program.


Tap detection

When used in conjunction with CONSOLE.TAPPED, and the image is tapped, the word in the invisible tag string under the image will be returned.
If this tag is not separated from other words, all words stuck to it will be returned as one.
Example

PRINT "Cartman"
PRINT.IMG -1,0,"Tagged","cartman.png"    % append to last line
do : pause 200 : until 0
end

OnConsoleTouch:
  Console.Tapped ,,w$
  print w$
ConsoleTouch.Resume

A tap on the image returns the word under the image which is "CartmanTagged"

Use a space if you wish to separate "Cartman" from "Tagged";
        PRINT "Cartman "


About Tags

Be wary when re-printing over a tag , as the tag length and it's columns are still valid.

If you PRINT.AT or PRINT.IMG over an existing tag column,

The existing image is always removed.
The existing tag becomes normal text and is shown on the console.
Any new string or tag is overlaid on top of the old tag.
Any new image occupies only it's own tag length.

It is not advisable to put spaces inside tags, otherwise  the word returned by console.tapped is unpredicatable.

Notes:
Internally, a new bitmap is created for each call.
It is not advisable to loop large animations on the console as it is not designed for speed and memory.

All console bitmaps will be cleared with CLS.

PRINT.IMG preserves any previous print append mode.

CONSOLE.BACKIMG

CONSOLE.BACKIMG  file_name_sexp {,fit_type_nexp}{,smooth_lexp}
Sets a background image for the console

The image file_name_sexp is relative to <base_dir>/data/.
Accepted formats are jpg, png, bmp, gif.
If  file_name is empty (""), then any previous image is removed.

Images
The loaded image always replaces the console VOIDCOLOR. So you will not not see the void color while the image is on. Also images with transparency do not work.

Fitting
The image is fitted to the screen depending on an optional fit_type_nexp which is by default 0.
fit_type
Name Description Notes
0
Fill
Fills entire screen
default.
scaled to either width or height, which ever will fill the screen.
1
Width
Fit to width of screen
possible hole at bottom.
2
Height
Fit to height of screen
possible hole  at right.
3
Shortest Fit to the shortest side of screen
possible hole.
4
Longest
Fit to the longest side of screen possible hole.
5
Paste
Just paste at 0,0
no scaling.
possible holes.
If the fit scales the image larger than the screen on any side, then the image is cropped.
If you wish to use a flag other than 0, make sure your image is appropriately proportioned to fit your target screen, otherwise there is a possible hole leftover.

Smoothing
Any scaling will smooth the image by default. To scale without smoothing, set the optional smooth flag to zero.

Orientation Changes
The ratio is always maintained. But if the orientation is later changed, the image will be streched.
To maintain the same image ratio, be sure to call CONSOLE.BACKIMG again if the orientation has changed.
You can detect for orientation changed with the OnORIENT interrupt block.
e.g

CONSOLE.BACKIMG "image.jpg"
do: pause 100: until 0
END

OnORIENT:
CONSOLE.BACKIMG "image.jpg"    % reload the background
PRINT "Now is " + DEVICE$("Orient_Simple")
ORIENT.Resume

Replacing the Text background color with image
You can let the image show through behind the text by setting the text background color to transparent.
e.g
.CS "BACKCOLOR #00000000"    % let image show through

CONSOLE.GOTO

CONSOLE.GOTO  <line_nexp>

Position a row of the console given by <line_nexp> into visible view.

This is only useful if the line is not visible on the console (e. scrolled out of view).

After execution, the line is usually displayed at the top of the console window,
the exception is if the line is part of the last page of the console, in which case it could appear anywhere within the last page but still in view.

Rules
    1. The first line of the console starts at 1
    2. if line is out of range, it will be forced to the last line;
            if line <= 0 OR  line > last_line then it will goto to the last_line.
 
Example
FOR i = 1 TO 500
    PRINT i
NEXT

CONSOLE.GOTO 200          %  positions line 200 into view

CONSOLE.SET

CONSOLE.SET  <pair_sexp> {,..}

e.g CONSOLE.SET "TEXTCOLOR #FF112233"

where <pair_sexp> = "<keyword>[ |= ]<value> {,..} "
   note :  the pair is a string expression.
(the '=' is optional but there must be a space if it is not used)

Sets console attributes.

The Keyword Value Pairs accepted are;

"TEXTCOLOR <color>"  e.g "TEXTCOLOR #FF112233" % Text
"BACKCOLOR <color>"  e.g "BACKCOLOR=#112233"   % Text Background

"LINECOLOR <color>"  e.g "LINECOLOR =Aqua"     % Divider Line
"VOIDCOLOR <color>"  e.g "VOIDCOLOR  #000000"  % Empty Console Area


Sets the color of various attributes.

The VOIDCOLOR is the area where there is no text.

VOIDCOLOR and LINECOLOR apply to the whole console.
TEXTCOLOR and BACKCOLOR apply for future printing.
Colors
<color> may either be
hex #AARRGGBB as alpha, red, green, blue
or
hex #RRGGBB as red, green, blue (alpha assumed to be solid)

or
any one of the 564 HTML colors listed  here or original website here.

Any color string starting with an underscore ( ' _' ) will have that underscore ignored.
(this is to accomodate underscored names from other environments).


Alpha channels for color Names

A color name can be post-fixed with an alpha-channel value e.g
CONSOLE.SET "TEXTCOLOR darkcoffee.169"
is the same as
CONSOLE.SET "TEXTCOLOR darkcoffee#A9"
is the same as
CONSOLE.SET "TEXTCOLOR #A93B2F2F
"

#hh    A 'H'ash ( # ) begins the alpha value as Hex.
.ddd   A 'dot'     ( '.' ) begins the alpha value as Decimal.


"SPACING = <number>"     e.g CONSOLE.SET "SPACING = 8"
Line Spacing
(padding above & below text measured as dp)
-ve size will use Basic's default size (5dp)

Applies for future printing.

"WRAP   <on | off>"  e.g CONSOLE.SET "WRAP  off"
Set whether text on one line should wrap if there's not enough room to display.

Note that wrapped text still sits on 'one' line, even though it looks likes there are two or more. Set the dividers 'on' to see which line the text sits on.

Applies for future printing.


"TEXTSIZE   <number>"  e.g CONSOLE.SET "TEXTSIZE = 16"    %(16 point dp)
Set the font size of the text

+ve
size means dp (device independent pixels)
-ve size means sp (scaled pixels, adhering to android user prefs)
0 size will default to Basic's preferences.

Applies for future printing.

"FONT <number|family>" e.g CONSOLE.SET "FONT = 2"          % use loaded font 2
e.g CONSOLE.SET "FONT = sans-serif" % use family font

Use a loaded font or font-family-style
where
<number>
uses a loaded font from the FONT.LOAD command
or
<family>    uses an android family font

This command is similar to Gr.text.setfont.

A font number or family name can be post-fixed with a style after a dot '.'
Normal | Bold | Italic | Bold_Italic

e.g CONSOLE.SET "FONT sans-serif.BOLD"
e.g CONSOLE.SET "FONT 3.BOLD"


(any unrecognised style will default to NORMAL).

An example of loading a font is found here.

Applies for future printing.

"ANTIALIAS   <on | off>"  e.g CONSOLE.SET "AntiAlias  off"
Set Anti-Alias for text rendering.
The default setting is ON. It is recommended to leave this on unless you are using unicode block graphic characters and need to have adjacent lines to look flush.

Applies for future printing.

"UNDERLINE   <on | off>"  e.g CONSOLE.SET "UnderLine  on"
Underline text
The default setting is OFF.

Applies for future printing.

"STRIKE   <on | off>"  e.g CONSOLE.SET "Strike  ON"
Apply strike-through effect on text.
The default setting is OFF.

Applies for future printing.

"DIVIDERS  <on | off>"   e.g CONSOLE.SET "DIVIDERS off"     
turns ON or OFF line dividers

Applies to the whole console.

"SCROLL  <FASTON | FASTOFF"   e.g CONSOLE.SET "SCROLL Faston"

Set scroll attributes.

FastOn - 
fast scroll scrollbar drag if list is 4x screenheight or more.
FastOff - turns off fast scroll.

Applies to the whole console.

"STACK  <FROMBASE | FROMTOP"   e.g CONSOLE.SET "Stack FromTop"
Set stack attributes.

FromTop
    - stack new lines from the top of screen (default).
FromBase - stack new lines from the bottom of screen.

Applies to the whole console.


Rules;
    1. A keyword value pair is a string expression. e.g "keyword = value" or MyString$.

    2. "keyword value" pairs can be separated with commas within the string
.
e.g CONSOLE.SET "TEXTCOLOR #FF112233 , BACKCOLOR=WHITE"

    3. "keyword value" pairs can also be separated with commas outside each string
.
e.g CONSOLE.SET "TEXTCOLOR #FF112233" , "BACKCOLOR=WHITE"
and
The command can also be continued on the next line using "~"
e.g
CONSOLE.SET "TEXTCOLOR #FF112233" , ~
"BACKCOLOR=WHITE"
notes:
A comma is still required to separate them.
Each string itself cannot be split with the "~" continuation character.

    4. Within each string, a keyword can be separated from it's value with either whitespace and/or "=".

e.g "TEXTCOLOR #FF112233"
or
e.g "TEXTCOLOR = #FF112233"

     5. All strings are case-insensitive.

Examples
CONSOLE.SET "BACKCOLOR=BLUE"

CONSOLE.SET "TEXTCOLOR LIGHTGREY, LINECOLOR = YELLOW",~
"SPACING 0", "DIVIDERS=OFF" + ",TEXTSIZE -30"

MyStyle$ = "SPACING 10, DIVIDERS=ON" + ",TEXTSIZE 16"
CONSOLE.SET MyStyle$

dot CS Shortcut

.CS  <pair_sexp> {,..}

is the same as CONSOLE.SET  <pair_sexp> {,..}

i.e .CS is a shortcut for CONSOLE.SET.
CONSOLE.SCREEN

CONSOLE.SCREEN  {<width_nvar>} {, <height_nvar> }

Guess the dimensions of the console as number of characters.

This command only works well with the MONOSPACE font.
Other fonts will give unpredicatble results.

width or height is optional, but the comma is needed for height.

Note that the returned values may have a fractional part, .eg 32.2


CONSOLE.TAPPED
CONSOLE.TAPPED {row_nvar} {,column_nvar} {,word$_svar} {,longPressed_lvar}

This is an alternative to CONSOLE.LINE.TOUCHED. It operates the same way, i.e when a touch/tap occurs, the ONCONSOLETOUCH - -  CONSOLETOUCH.RESUME block triggers and you can get your information with either CONSOLE.LINE.TOUCHED or CONSOLE.TAPPED.

You can get the row, column or word that was last tapped.

row    returns the row index of the console (1..n)
0 means the app has not received a first tap on a line.
column  returns the column index of the tapped line (1..n)
If the app has not received a first tap, it will return 0.
If the tapped column is greater than the length of the string on the line, then this will return 0.
(You will have to fill your strings with spaces if you want to detect columns on the right hand side.)
word$    This is the word under the tap.
If there is no word found, a an empty string is returned.
longPressed    0 if the tap was a normal tap. 1 if the tap was a long tap.

This command only works well if the line does not wrap. You can ensure non-wrapping with
.CS "WRAP OFF"

CONSOLE.ORIENT
CONSOLE.ORIENT orientation_nexp
Sets the Screen Orientation of the console.

Where orientation is

-1 = Orientation depends upon the sensors.
0 = Orientation is forced to Landscape.
1 = Orientation is forced to Portrait.
2 = Orientation is forced to Reverse Landscape.
3 = Orientation is forced to Reverse Portrait.
The new orientation is effective immediately.

In Standard mode (with Editor), If this command is unused, the default setting is the same as Editor's Preferences but does not affect it.

In APK mode (StandAlone), If this command is unused , the default setting is based on sensors (auto-rotate).

(Since v4.91+ This setting no longer affects the Editor Preferences orientation value.)
CONSOLE.EXIT

CONSOLE.EXIT

Exits the console without exiting the Editor.
This is an immediate exit. The console screen will not be held.
For Standard mode, it will exit to the Editor.
For APK mode the Standalone app will exit to the caller.

TGET

TGET  result$_svar, {,prompt$_sexp} {,title$_sexp} {,backKey_nvar}

Get text Input from the last line of the console.

where
<result$> is the return string   ( not optional)
<prompt> sets the prompt (optional)
<title> sets the window title (optional)
<backKey> is a variable to hold the backKey flag (optional)

0 => backKey was not pressed to exit TGET
1 => backKey was pressed to exit TGET

Commas are needed to seperate parameters, even if they are omitted.

TGET now closely resembles the output console.
Any style changes to the console will do the same to TGET.

After input from the user, TGET prints both the prompt and user input.

The exception is if the user presses 'Stop' from the console menu, in which case 'Stopped by user' is printed instead, and the program execution is stopped or exited.


Examples
TGET r$, "cmd >", "Enter Command"

TGET r$, "Input your password >", "Security Check", bkey
IF bkey THEN PRINT "Do you want to Quit ?"

(see sample program h05_shell.bas for a demo of a terminal emulator)

TGET Sub commands
These sub-commnds are designed to quickly get input without obscuring the console.
Typically, they are used on the last page of the screen because TGET is always on the last row.
TGET.S result$_svar, {,prompt$_sexp} {,title$_sexp} {,backKey_nvar}
TGET.N result$_svar, {,prompt$_sexp} {,title$_sexp} {,backKey_nvar}
TGET.I  result$_svar, {,prompt$_sexp} {,title$_sexp} {,backKey_nvar}
TGET.P result$_svar, {,prompt$_sexp} {,title$_sexp} {,backKey_nvar}

The main differences between TGET and the new subcommands are that ;

All subcommands do not print the prompt+result after they finish.

All subcommands have the prompt above the input unless the prompt is empty or omitted.
The prompt (if shown) will be in reverse colors.

TGET.S    Same as TGET except that it will not print out the result.
TGET.N    Brings up a NUMERIC keyboard - restricts input as a real number.
TGET.I      Brings up a NUMERIC keyboard - restricts input as an integer.
TGET.P    Same as TGET.S except that it hides the input like a password.

Both N and I subcommands will still accept a negative number.
Both N and I subcommands will still return a number as a string.
Both N and I subcommands have no error checking.
             i.e you can default the input with a string, but the keyboard will only let you type a number.
CLR

CLR row_nexp {,column_nexp}

Clears a console line by deleting characters, optionally from a start position.

    The row itself is not deleted, even if empty.

If the row becomes completely empty, the row's default styling is replaced with the current console style (this is useful for padding Print.ATs at a later stage).

row    The row to clear (1..n). This is not optional.
    If row is zero no action is taken.
    If row is negative, the row will count backwards (-1 = last line).
    If row is out of range, (no row exists), no action is taken.

column    A starting column (1..n)
    If omitted, the start column is 1.
    Characters will be deleted until end of line.
    If column is out of range, (no column exists), no action is taken.



Leading Cloud Surveillance, Recording and Storage service; IP camera live viewing

Leading Enterprise Cloud IT Service; cloud file server, FTP Hosting, Online Storage, Backup and Sharing

Powered by FirstCloudIT.com, a division of DriveHQ, the leading Cloud IT and Cloud Surveillance Service provider since 2003.