'=========================================================================== ' Subject: ANSI COLORS Date: 12/28/92 (00:00) ' Author: Jim Morey Code: PDS, VBDOS ' Keys: ANSI,COLORS Packet: ANSI.ABC '=========================================================================== 'ANSI color printing example 1 ' 'The screen must be opened as a file for output and printed to. 'BASIC's PRINT statement prints directly, thus bypassing ANSI.SYS. ' 'Another point to note: A standard (of your choosing) must be 'established when combining various ANSI options. The order of the 'colors and highlighting codes is unimportant, so long as the sequence 'begins with the escape and ends with the 'm' and is separated by a ';'. 'The standard chosen below is to insert the highlighting codes between 'the escape and the colors, with the colors containing the 'm' 'parameter, and the highlighting codes containing the ';' separator. 'Your milage may vary. DECLARE SUB printchar (char$) esc$ = CHR$(27) + "[" normal$ = "0m" blinking$ = "5;" bold$ = "1;" red$ = "31m" green$ = "32m" yellow$ = "33m" blue$ = "34m" magenta$ = "35m" cyan$ = "36m" white$ = "37m" OPEN "O", #1, "cons:" CLS PRINT #1, esc$ + red$ + "red" PRINT #1, esc$ + green$ + "green" PRINT #1, esc$ + yellow$ + "yellow" PRINT #1, esc$ + blue$ + "blue" PRINT #1, esc$ + magenta$ + "magenta" PRINT #1, esc$ + cyan$ + "cyan" PRINT #1, esc$ + white$ + "white" PRINT #1, esc$ + normal$ + "normal" PRINT #1, PRINT #1, esc$ + bold$ + red$ + "bold red" PRINT #1, esc$ + bold$ + green$ + "bold green" PRINT #1, esc$ + bold$ + yellow$ + "bold yellow" PRINT #1, esc$ + bold$ + blue$ + "bold blue" PRINT #1, esc$ + bold$ + magenta$ + "bold magenta" PRINT #1, esc$ + bold$ + cyan$ + "bold cyan" PRINT #1, esc$ + bold$ + white$ + "bold white" PRINT #1, esc$ + normal$ + "normal" PRINT #1, PRINT #1, "Press a key..." dummy$ = INPUT$(1) CLS PRINT #1, esc$ + blinking$ + red$ + "blinking red" PRINT #1, esc$ + blinking$ + green$ + "blinking green" PRINT #1, esc$ + blinking$ + yellow$ + "blinking yellow" PRINT #1, esc$ + blinking$ + blue$ + "blinking blue" PRINT #1, esc$ + blinking$ + magenta$ + "blinking magenta" PRINT #1, esc$ + blinking$ + cyan$ + "blinking cyan" PRINT #1, esc$ + blinking$ + white$ + "blinking white" PRINT #1, esc$ + normal$ + "normal" PRINT #1, PRINT #1, esc$ + bold$ + blinking$ + red$ + "bold blinking red" PRINT #1, esc$ + bold$ + blinking$ + green$ + "bold blinking green" PRINT #1, esc$ + bold$ + blinking$ + yellow$ + "bold blinking yellow" PRINT #1, esc$ + bold$ + blinking$ + blue$ + "bold blinking blue" PRINT #1, esc$ + bold$ + blinking$ + magenta$ + "bold blinking magenta" PRINT #1, esc$ + bold$ + blinking$ + cyan$ + "bold blinking cyan" PRINT #1, esc$ + bold$ + blinking$ + white$ + "bold blinking white" PRINT #1, esc$ + normal$ + "normal" PRINT #1, PRINT #1, "Press a key..." dummy$ = INPUT$(1) LOCATE 20, 1 END 'ANSI color printing example 2 ' 'Another method of interfacing with ANSI.SYS is to use the DOS function '21/02. This function will print one character at a time to the screen. 'A function to print an entire string is also available, but this 'example uses a secondary sub to parse the string and pass it to the 'first sub. cr$ = CHR$(13) + CHR$(10) esc$ = CHR$(27) + "[" normal$ = "0m" blinking$ = "5;" bold$ = "1;" red$ = "31m" green$ = "32m" yellow$ = "33m" blue$ = "34m" magenta$ = "35m" cyan$ = "36m" white$ = "37m" CLS call printstring$(esc$+red$+"red"+cr$) call printstring$(esc$+green$+"green"+cr$) call printstring$(esc$+yellow$+"yellow"+cr$) call printstring$(esc$+blue$+"blue"+cr$) call printstring$(esc$+magenta$+"magenta"+cr$) call printstring$(esc$+cyan$+"cyan"+cr$) call printstring$(esc$+white$+"white"+cr$) call printstring$(esc$+normal$+"normal"+cr$) call printstring$(cr$) call printstring$(esc$+bold$+red$+"bold red"+cr$) call printstring$(esc$+bold$+green$+"bold green"+cr$) call printstring$(esc$+bold$+yellow$+"bold yellow"+cr$) call printstring$(esc$+bold$+blue$+"bold blue"+cr$) call printstring$(esc$+bold$+magenta$+"bold magenta"+cr$) call printstring$(esc$+bold$+cyan$+"bold cyan"+cr$) call printstring$(esc$+bold$+white$+"bold white"+cr$) call printstring$(esc$+normal$+"normal"+cr$) call printstring$(cr$) call printstring$("Press a key..."+cr$) dummy$ = INPUT$(1) CLS call printstring$(esc$+blinking$+red$+"blinking red"+cr$) call printstring$(esc$+blinking$+green$+"blinking green"+cr$) call printstring$(esc$+blinking$+yellow$+"blinking yellow"+cr$) call printstring$(esc$+blinking$+blue$+"blinking blue"+cr$) call printstring$(esc$+blinking$+magenta$+"blinking magenta"+cr$) call printstring$(esc$+blinking$+cyan$+"blinking cyan"+cr$) call printstring$(esc$+blinking$+white$+"blinking white"+cr$) call printstring$(esc$+normal$+"normal"+cr$) call printstring$(cr$) call printstring$(esc$+bold$+blinking$+red$+"bold blinking red"+cr$) call printstring$(esc$+bold$+blinking$+green$+"bold blinking green"+cr$) call printstring$(esc$+bold$+blinking$+yellow$+"bold blinking yellow"+cr$) call printstring$(esc$+bold$+blinking$+blue$+"bold blinking blue"+cr$) call printstring$(esc$+bold$+blinking$+magenta$+"bold blinking magenta"+cr$) ** EDITOR WRAPPED ** call printstring$(esc$+bold$+blinking$+cyan$+"bold blinking cyan"+cr$) call printstring$(esc$+bold$+blinking$+white$+"bold blinking white"+cr$) call printstring$(esc$+normal$+"normal"+cr$) call printstring$(cr$) call printstring$("Press a key..."+cr$) dummt$ = INPUT$(1) LOCATE 20, 1 END SUB printchar (char$) reg 1, &H200 reg 4, ASC(char$) call interrupt &h21 END SUB SUB printstring (temp$) FOR i = 1 TO LEN(temp$) t$ = MID$(temp$, i, 1) CALL printchar(t$) NEXT i END SUB