2021-07-01 21:24:06 +02:00
|
|
|
;{- Code Header
|
|
|
|
; ==- Basic Info -================================
|
|
|
|
; Name: VirtualTerminal/Basic.pb
|
|
|
|
; Author: Herwin Bozet
|
|
|
|
;
|
|
|
|
; ==- Links & License -===========================
|
|
|
|
; License: Unlicense
|
2021-07-01 22:31:17 +02:00
|
|
|
; GitHub: https://github.com/aziascreations/PB-ConsoleHelpers
|
2021-07-01 21:24:06 +02:00
|
|
|
;}
|
|
|
|
|
|
|
|
;- Compiler Directives
|
|
|
|
|
|
|
|
EnableExplicit
|
|
|
|
|
|
|
|
XIncludeFile "../../VirtualTerminal.pbi"
|
|
|
|
|
|
|
|
CompilerIf #PB_Compiler_ExecutableFormat <> #PB_Compiler_Console
|
|
|
|
CompilerWarning "You should preferably compile the example as a console app !"
|
|
|
|
CompilerEndIf
|
|
|
|
|
|
|
|
|
|
|
|
;- Code
|
|
|
|
|
2021-07-01 22:31:17 +02:00
|
|
|
;-> Safely openning the console
|
2021-07-01 21:24:06 +02:00
|
|
|
If OpenConsole("My first title")
|
|
|
|
If Not VirtualTerminal::EnableVirtualTerminalProcessing()
|
|
|
|
VirtualTerminal::WriteErrorN("Unable to activate virtual terminal processing, output is likely piped !")
|
|
|
|
CloseConsole()
|
|
|
|
End 2
|
|
|
|
EndIf
|
|
|
|
Else
|
|
|
|
Debug "Can't open console !"
|
|
|
|
End 1
|
|
|
|
EndIf
|
|
|
|
|
2021-07-01 22:31:17 +02:00
|
|
|
|
|
|
|
;-> Clearing the console
|
2021-07-01 21:24:06 +02:00
|
|
|
VirtualTerminal::ClearDisplay(AinsiEscapeCode::#ED_2) ; 2 or +ClearDisplayFull() also works just fine
|
|
|
|
VirtualTerminal::CursorTo(0, 0)
|
|
|
|
|
2021-07-01 22:31:17 +02:00
|
|
|
|
|
|
|
;-> Intro
|
2021-07-01 21:24:06 +02:00
|
|
|
VirtualTerminal::WriteOutputN("-===- Welcome to the 'Basic' demo for 'VirtualTerminal' -===-")
|
2021-07-01 22:31:17 +02:00
|
|
|
|
|
|
|
VirtualTerminal::WriteOutputN("This program serves as a short demo of the 'VirtualTerminal' include for PureBasic.")
|
|
|
|
VirtualTerminal::WriteOutputN("This include and its module aim to bring the functionalities of the escape character sequences"+
|
|
|
|
" to PureBasic without using any OS-specific API.")
|
|
|
|
VirtualTerminal::WriteOutputN("")
|
|
|
|
VirtualTerminal::WriteOutputN("Some features may not work properly on some third-party consoles such as ConEmu.")
|
|
|
|
VirtualTerminal::WriteOutputN("The 'GetTerminalWidth()' and 'GetTerminalHeight()' procedure tend to scroll the viewport on them.")
|
|
|
|
VirtualTerminal::WriteOutputN("")
|
2021-07-01 21:24:06 +02:00
|
|
|
VirtualTerminal::WriteOutputN("Press enter to start...")
|
|
|
|
Input()
|
|
|
|
|
2021-07-01 22:31:17 +02:00
|
|
|
|
|
|
|
;-> Basic info
|
2021-07-01 21:24:06 +02:00
|
|
|
VirtualTerminal::WriteOutputN("-=- Basic info -=-")
|
2021-07-01 22:31:17 +02:00
|
|
|
Define TerminalWidth.i = VirtualTerminal::GetTerminalWidth()
|
|
|
|
Define TerminalHeight.i = VirtualTerminal::GetTerminalHeight()
|
|
|
|
VirtualTerminal::WriteOutputN("Terminal size: "+Str(TerminalWidth)+"x"+Str(TerminalHeight))
|
2021-07-01 21:24:06 +02:00
|
|
|
VirtualTerminal::WriteOutputN("Press enter to continue...")
|
|
|
|
Input()
|
|
|
|
|
2021-07-01 22:31:17 +02:00
|
|
|
|
|
|
|
;-> Title demo
|
2021-07-01 21:24:06 +02:00
|
|
|
VirtualTerminal::WriteOutputN("-=- Title -=-")
|
|
|
|
VirtualTerminal::WriteOutputN("Press enter to change the title...")
|
|
|
|
Input()
|
|
|
|
VirtualTerminal::SetWindowTitle("My new title")
|
|
|
|
|
|
|
|
|
2021-07-01 22:31:17 +02:00
|
|
|
;-> Dynamic UI demo
|
|
|
|
VirtualTerminal::WriteOutputN("-=- Dynamic UI -=-")
|
|
|
|
VirtualTerminal::WriteOutputN("Press enter to start...")
|
|
|
|
Input()
|
|
|
|
|
|
|
|
Define Percentage.i = 0
|
|
|
|
|
|
|
|
Repeat
|
|
|
|
Define ProgressBarSize.i = Round((TerminalWidth) * (Percentage / 100), #PB_Round_Down)
|
|
|
|
|
|
|
|
Define OriginalCursorPosition.Console::CursorPosition
|
|
|
|
VirtualTerminal::GetCursorPosition(@OriginalCursorPosition)
|
|
|
|
|
|
|
|
VirtualTerminal::WriteOutput("["+RSet("", ProgressBarSize, "#")+RSet("", TerminalWidth - ProgressBarSize - 2, " ")+"]")
|
|
|
|
VirtualTerminal::CursorTo(0, OriginalCursorPosition\Y)
|
|
|
|
|
|
|
|
Percentage = Percentage + 1
|
|
|
|
Delay(15)
|
|
|
|
Until Percentage = 100
|
|
|
|
|
|
|
|
VirtualTerminal::CursorDownBy(2)
|
|
|
|
|
|
|
|
|
|
|
|
;-> ???
|
|
|
|
|
|
|
|
|
|
|
|
;-> Finishing
|
2021-07-01 21:24:06 +02:00
|
|
|
VirtualTerminal::WriteOutputN("-=- End of the demo -=-")
|
|
|
|
Print("Press enter to clear the terminal and exit...")
|
|
|
|
Input()
|
|
|
|
VirtualTerminal::ClearDisplayFull()
|
|
|
|
VirtualTerminal::CursorTo(0, 0)
|
|
|
|
|
2021-07-01 22:31:17 +02:00
|
|
|
|
|
|
|
;-> Quitting safely
|
2021-07-01 21:24:06 +02:00
|
|
|
VirtualTerminal::DisableVirtualTerminalProcessing()
|
|
|
|
CloseConsole()
|
|
|
|
End 0
|