-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
361 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
'' | ||
' QB64_GJ_LIB | ||
' GRYMMJACK'S CONSOLE LIB | ||
' | ||
' CONSOLE object with debugging example | ||
' | ||
' USAGE: | ||
' Insert '$INCLUDE:'path_to_GJ_LIB/CONSOLE/CONSOLE.BI' at the top of file | ||
' Insert '$INCLUDE:'path_to_GJ_LIB/CONSOLE/CONSOLE.BM' at the bottom of file | ||
' | ||
' @author Rick Christy <grymmjack@gmail.com> | ||
' | ||
$IF GJ_LIB_UNIFIED_TESTING = DEFINED AND GJ_LIB_INC_BI = UNDEFINED THEN | ||
'$INCLUDE:'../_GJ_LIB.BI' | ||
$END IF | ||
|
||
_TITLE "QB64_GJ_LIB CONSOLE OBJECT EXAMPLE" | ||
|
||
PRINT "This example outputs only this message to the program window." | ||
PRINT "To see the purpose and output look at the terminal window." | ||
|
||
'$INCLUDE:'CONSOLE.BI' | ||
CONSOLE.log "This is a CONSOLE.log message." | ||
|
||
'If you are used to using console.log() you might want to use CALL to use ()'s | ||
CALL CONSOLE.log("This is another CONSOLE.log message.") | ||
|
||
CONSOLE.info "This is a CONSOLE.info message." | ||
CONSOLE.warn "This is a CONSOLE.warn message." | ||
CONSOLE.error "This is a CONSOLE.error message." | ||
|
||
'CONSOLE.banner and CONSOLE.box take a color code argument to draw in that color | ||
CONSOLE.banner "This is a CONSOLE.banner message.", 13 | ||
CONSOLE.box "This is a CONSOLE.box message.", 5 | ||
|
||
'$INCLUDE:'CONSOLE.BM' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
'' | ||
' QB64_GJ_LIB | ||
' GRYMMJACK'S CONSOLE LIB | ||
' | ||
' CONSOLE object with debugging. | ||
' | ||
' USAGE: | ||
' Insert '$INCLUDE:'path_to_GJ_LIB/CONSOLE/CONSOLE.BI' at the top of file | ||
' Insert '$INCLUDE:'path_to_GJ_LIB/CONSOLE/CONSOLE.BM' at the bottom of file | ||
' | ||
' @depends STRINGS/STRINGS.BI | ||
' @author Rick Christy <grymmjack@gmail.com> | ||
' | ||
$LET GJ_LIB_CONSOLE_INC_BI = 1 | ||
$IF DEBUGGING = UNDEFINED THEN | ||
$LET DEBUGGING = TRUE | ||
$END IF | ||
$IF DEBUGGING = TRUE THEN | ||
$CONSOLE | ||
$ASSERTS:CONSOLE | ||
_CONSOLE ON | ||
$END IF | ||
|
||
'Maps ANSI colors to CGA colors | ||
DIM SHARED ANSI_COLOR(0 TO 15) AS INTEGER | ||
ANSI_COLOR%(0) = 0 | ||
ANSI_COLOR%(1) = 4 | ||
ANSI_COLOR%(2) = 2 | ||
ANSI_COLOR%(3) = 6 | ||
ANSI_COLOR%(4) = 1 | ||
ANSI_COLOR%(5) = 5 | ||
ANSI_COLOR%(6) = 3 | ||
ANSI_COLOR%(7) = 7 | ||
ANSI_COLOR%(8) = 0 | ||
ANSI_COLOR%(9) = 4 | ||
ANSI_COLOR%(10) = 2 | ||
ANSI_COLOR%(11) = 6 | ||
ANSI_COLOR%(12) = 1 | ||
ANSI_COLOR%(13) = 5 | ||
ANSI_COLOR%(14) = 3 | ||
ANSI_COLOR%(15) = 7 | ||
CONST BLACK = 0% | ||
CONST BLUE = 1% | ||
CONST GREEN = 2% | ||
CONST CYAN = 3% | ||
CONST RED = 4% | ||
CONST MAGENTA = 5% | ||
CONST YELLOW = 6% | ||
CONST WHITE = 7% | ||
CONST BRIGHT_BLACK = 8% | ||
CONST BRIGHT_BLUE = 9% | ||
CONST BRIGHT_GREEN = 10% | ||
CONST BRIGHT_CYAN = 11% | ||
CONST BRIGHT_RED = 12% | ||
CONST BRIGHT_MAGENTA = 13% | ||
CONST BRIGHT_YELLOW = 14% | ||
CONST BRIGHT_WHITE = 15% | ||
|
||
'$INCLUDE:'../STRINGS/STRINGS.BI' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
'' | ||
' QB64_GJ_LIB | ||
' GRYMMJACK'S CONSOLE LIB | ||
' | ||
' CONSOLE object with debugging. | ||
' | ||
' USAGE: | ||
' Insert '$INCLUDE:'path_to_GJ_LIB/CONSOLE/CONSOLE.BI' at the top of file | ||
' Insert '$INCLUDE:'path_to_GJ_LIB/CONSOLE/CONSOLE.BM' at the bottom of file | ||
' | ||
' @author Rick Christy <grymmjack@gmail.com> | ||
' | ||
$LET GJ_LIB_CONSOLE_INC_BM = 1 | ||
|
||
'' | ||
' Log a boxed message to console if DEBUGGING | ||
' @param STRING msg message to send | ||
' @param INTEGER kolor% color to use | ||
' | ||
SUB console.box(msg$, kolor%) | ||
$IF DEBUGGING = TRUE THEN | ||
DIM AS STRING e, color_code, lines, intensity | ||
DIM AS INTEGER fg, afg | ||
intensity$ = "0" | ||
e$ = CHR$(27) | ||
afg% = ANSI_COLOR%(kolor%) | ||
color_code$ = e$ + "[" | ||
IF kolor% > 7 THEN intensity$ = "1" | ||
color_code$ = color_code$ + intensity$ + ";3" | ||
color_code$ = color_code$ + _TRIM$(STR$(afg%)) + "m" | ||
lines$ = "+" + STRING$(LEN(msg$)+2, "-") + "+" | ||
_ECHO color_code$ + lines$ | ||
_ECHO "| " + msg$ + " |" | ||
_ECHO lines$ + e$ + "[0m" | ||
$END IF | ||
msg$ = "" | ||
END SUB | ||
|
||
|
||
'' | ||
' Log a banner to console if DEBUGGING | ||
' @param STRING msg message to send | ||
' @param INTEGER kolor% color to use | ||
' | ||
SUB console.banner(msg$, kolor%) | ||
$IF DEBUGGING = TRUE THEN | ||
DIM AS STRING e, color_code, intensity | ||
DIM AS INTEGER fg, afg | ||
intensity$ = "0" | ||
e$ = CHR$(27) | ||
afg% = ANSI_COLOR(kolor%) | ||
msg$ = STR.replace$(msg$, "\n", CHR$(10), -1) | ||
msg$ = STR.replace$(msg$, "\t", CHR$(9), -1) | ||
color_code$ = e$ + "[" | ||
IF kolor% > 7 THEN intensity$ = "1" | ||
color_code$ = color_code$ + intensity$ + ";3" | ||
color_code$ = color_code$ + _TRIM$(STR$(afg%)) + "m" | ||
_ECHO color_code$ + msg$ + e$ + "[0m" | ||
$END IF | ||
msg$ = "" | ||
END SUB | ||
|
||
|
||
'' | ||
' Log to console if DEBUGGING | ||
' @param STRING msg message to send | ||
' | ||
SUB console.log(msg$) | ||
$IF DEBUGGING = TRUE THEN | ||
_ECHO msg$ | ||
$END IF | ||
msg$ = "" | ||
END SUB | ||
|
||
|
||
'' | ||
' Log to console as info if DEBUGGING | ||
' @param STRING msg message to send | ||
' | ||
SUB console.info(msg$) | ||
$IF DEBUGGING = TRUE THEN | ||
DIM AS STRING e | ||
e$ = CHR$(27) | ||
_ECHO e$ + "[1;36m" + msg$ + e$ + "[0m" | ||
$END IF | ||
msg$ = "" | ||
END SUB | ||
|
||
|
||
'' | ||
' Log to console as warning if DEBUGGING | ||
' @param STRING msg message to send | ||
' | ||
SUB console.warn(msg$) | ||
$IF DEBUGGING = TRUE THEN | ||
DIM AS STRING e | ||
e$ = CHR$(27) | ||
_ECHO e$ + "[1;33m" + msg$ + e$ + "[0m" | ||
$END IF | ||
msg$ = "" | ||
END SUB | ||
|
||
|
||
'' | ||
' Log to console as error if DEBUGGING | ||
' @param STRING msg message to send | ||
' | ||
SUB console.error(msg$) | ||
$IF DEBUGGING = TRUE THEN | ||
DIM AS STRING e | ||
e$ = CHR$(27) | ||
_ECHO e$ + "[1;31m" + msg$ + e$ + "[0m" | ||
$END IF | ||
msg$ = "" | ||
END SUB | ||
|
||
'$INCLUDE:'../STRINGS/STRINGS.BM' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# [QB64_GJ_LIB](../README.md) | ||
## GRYMMJACK'S CONSOLE LIBRARY | ||
|
||
> CONSOLE object with debugging. | ||
The idea of this library and is to provide a elegant and simple way to include | ||
console output conditionally by setting one `$LET DEBUGGING = TRUE` in your code | ||
and if you do not have this set, just including the library will enable it by | ||
default. This will let you simply include the library and get busy using it. | ||
|
||
So what does it do? Well it provides QB64PE with functions similar to that of | ||
a web developer is spoiled by with a console object to use. | ||
|
||
In this case, we simply send strings to the console terminal of various colors | ||
with ANSI codes. | ||
|
||
I've extended the original idea of the web console.log a bit with a banner, and | ||
a box utility which is handy for seeing output separated from the rest. | ||
|
||
See the example and screenshot for more information. | ||
|
||
|
||
## WHAT'S IN THE LIBRARY | ||
| SUB / FUNCTION | NOTES | | ||
|----------------|-------| | ||
| CONSOLE.log | Log to console if DEBUGGING | | ||
| CONSOLE.info | Log to console as info if DEBUGGING | | ||
| CONSOLE.warn | Log to console as warning if DEBUGGING | | ||
| CONSOLE.error | Log to console as error if DEBUGGING | | ||
| CONSOLE.banner | Log a banner to console if DEBUGGING | | ||
| CONSOLE.box | Log a boxed message to console if DEBUGGING | | ||
|
||
|
||
|
||
### USAGE for CONSOLE LIB (separately) | ||
```basic | ||
'Insert at top of code: | ||
'$INCLUDE:'path_to_GJ_LIB/CONSOLE/CONSOLE.BM' | ||
'...your code here... | ||
'Insert at bottom of code: | ||
'$INCLUDE:'path_to_GJ_LIB/CONSOLE/CONSOLE.BM' | ||
``` | ||
|
||
|
||
|
||
### EXAMPLE | ||
> Screenshot of output from [CONSOLE.BAS](CONSOLE.BAS) | ||
![](CONSOLE.png) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
'' | ||
' QB64_GJ_LIB | ||
' GRYMMJACK'S MISC LIB | ||
' | ||
' Miscellaneous helpful functions and subs that don't fit anywhere else :) | ||
' | ||
' USAGE: | ||
' Insert '$INCLUDE:'path_to_GJ_LIB/MISC/MISC.BI' at the top of file | ||
' Insert '$INCLUDE:'path_to_GJ_LIB/MISC/MISC.BM' at the bottom of file | ||
' | ||
' @author Rick Christy <grymmjack@gmail.com> | ||
' | ||
$LET GJ_LIB_MISC_INC_BI = 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
'' | ||
' QB64_GJ_LIB | ||
' GRYMMJACK'S MISC LIB | ||
' | ||
' Miscellaneous helpful functions and subs that don't fit anywhere else :) | ||
' | ||
' USAGE: | ||
' Insert '$INCLUDE:'path_to_GJ_LIB/MISC/MISC.BI' at the top of file | ||
' Insert '$INCLUDE:'path_to_GJ_LIB/MISC/MISC.BM' at the bottom of file | ||
' | ||
' @author Rick Christy <grymmjack@gmail.com> | ||
' | ||
$LET GJ_LIB_MISC_INC_BM = 1 | ||
|
||
|
||
'' | ||
' Returns a number rounded to a fixed number of decimal places | ||
' @param DOUBLE num Number to round | ||
' @param INTEGER places number of places to round to | ||
' @return DOUBLE rounded number | ||
' | ||
FUNCTION num_fix#(num#, places%) | ||
DIM AS DOUBLE multiplier | ||
DIM AS STRING mult_str | ||
mult_str$ = _TRIM$("1" + STRING$(places%, "0")) | ||
multiplier# = VAL(mult_str$) | ||
num_fix# = FIX(num# * multiplier# + SGN(num#) * .5) / multiplier# | ||
END FUNCTION | ||
|
||
|
||
'' | ||
' Clamps a INTEGER between a minimum and maximum range | ||
' @param INTEGER num number to clamp | ||
' @param INTEGER min minimum allowed | ||
' @param INTEGER max maximum allowed | ||
' @return INTEGER clamped number | ||
' | ||
FUNCTION clamp_int%(num%, min%, max%) | ||
IF num% > max% THEN num% = max% | ||
IF num% < min% THEN num% = min% | ||
clamp_int% = num% | ||
END FUNCTION |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# [QB64_GJ_LIB](../README.md) | ||
## GRYMMJACK'S MISC LIBRARY | ||
|
||
> Miscellaneous helpful functions and subs that don't fit anywhere else :) | ||
|
||
|
||
## WHAT'S IN THE LIBRARY | ||
| SUB / FUNCTION | NOTES | | ||
|----------------|-------| | ||
| num_fix | Returns a number rounded to a fixed number of decimal places | | ||
| clamp_int | Clamps a INTEGER between a minimum and maximum range | | ||
|
||
|
||
|
||
### USAGE for MISC LIB (separately) | ||
```basic | ||
'...your code here... | ||
'Insert at bottom of code: | ||
'$INCLUDE:'path_to_GJ_LIB/MISC/MISC.BM' | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters