Happened across
this MSDN page on using Virtual Terminal escape sequences and thought it would be neat to try in QB64. So, I converted the example on the page. Perhaps someone would be interested enough to make something more with it.
The code:
Type CONSOLE_SCREEN_BUFFER_INFO
As COORD dwSize
, dwCursorPosition
As COORD dwMaximumWindowSize
Const INVALID_HANDLE_VALUE
= -1
Const STD_OUTPUT_HANDLE
= -11 Const ENABLE_VIRTUAL_TERMINAL_PROCESSING
= &H0004
EnableVTMode
Dim As CONSOLE_SCREEN_BUFFER_INFO ScreenBufferInfo
GetConsoleScreenBufferInfo hOut
, _Offset(ScreenBufferInfo
)Size.X = ScreenBufferInfo.srWindow.Right - ScreenBufferInfo.srWindow.Left + 1
Size.Y = ScreenBufferInfo.srWindow.Bottom - ScreenBufferInfo.srWindow.Top + 1
'Enter the alternate buffer
'Clear screen, tab stops, set, stop at columns 16, 32
Dim As Long iNumTabStops: iNumTabStops
= 4 '(0, 20, 40, width) Print CSI;
"3g";
'Clear all tab stops Print CSI;
"1;20H";
'Move to column 20 Print ESC;
"H";
'Set a tab stop
Print CSI;
"1;40H";
'Move to column 40 Print ESC;
"H";
'Set a tab stop
'Set scrolling margins to 3, h-2
Dim As Long iNumLines: iNumLines
= Size.Y
- 4
Print "Windows 10 Anniversary Update - VT Example";
'Print a top border - Yellow
PrintHorizontalBorder Size, -1
'Print a bottom border
PrintHorizontalBorder Size, 0
'Draw columns
For lin
= 0 To (iNumLines
* iNumTabStops
) - 1 PrintVerticalBorder
PrintStatusLine "Press any key to see text printed between tab stops.", Size
'Fill columns with output
For lin
= 0 To iNumLines
- 1 For tabs
= 0 To iNumTabStops
- 2 PrintVerticalBorder
PrintVerticalBorder
PrintStatusLine "Press any key to demonstrate scroll margins", Size
For lin
= 0 To (iNumLines
* 2) - 1 For tabs
= 0 To iNumTabStops
- 2 PrintVerticalBorder
PrintVerticalBorder
If lin
+ 1 <> iNumLines
* 2 Then
PrintStatusLine "Press any key to exit", Size
hOut = GetStdHandle(STD_OUTPUT_HANDLE)
GetConsoleMode hOut
, _Offset(dwMode
) dwMode
= dwMode
Or ENABLE_VIRTUAL_TERMINAL_PROCESSING
SetConsoleMode hOut, dwMode
Sub PrintVerticalBorder
()
A screenshot of the output: