Enjoy

Code: Select all
; ConsoleTools
; Copyright (c) 2025 by Quin.
; Public domain.
; Credit is greatly appreciated, but not required.
DeclareModule ConsoleTools
EnableExplicit
;{ Public Macros
; Exits the application and displays an error message.
Macro Die(_ErrorText)
ConsoleError(_ErrorText)
End 1
EndMacro
; Exits the application, printing a message before doing so.
Macro Exit(_Message)
PrintN(_Message)
End
EndMacro
; Displays the text "Press any key to continue . . ." and waits for keyboard input, like the pause command in batch scripts.
Macro Pause
PrintN("Press any key to continue . . .")
Repeat
Delay(10)
Until Inkey() <> "" Or RawKey()
EndMacro
;}
;{ Declares
Declare.i Menu(Prompt$, Items$)
Declare$ Prompt(Message$)
;}
EndDeclareModule
Module ConsoleTools
EnableExplicit
;{ Public Procedures
; Displays a menu to the user, letting them choose an option by typing a number. Menu items are separated by the vertical bar (|).
Procedure.i Menu(Prompt$, Items$)
Protected.i i, Count
Count = CountString(Items$, "|")
Protected Dim Items.s(Count)
For i = 0 To Count
Items(i) = StringField(Items$, i + 1, "|")
Next
PrintN(Prompt$)
For i = 0 To Count
PrintN(Str(i + 1) + " = " + Items(i))
Next
ProcedureReturn Val(Input())
EndProcedure
; Prints a message and reads a string from stdin.
Procedure$ Prompt(Message$)
Print(Message$)
ProcedureReturn Input()
EndProcedure
EndModule
CompilerIf #PB_Compiler_IsMainFile
EnableExplicit
UseModule ConsoleTools
OpenConsole("Test")
Define Name$ = Prompt("What is your name?")
If Name$ = ""
Die("You must enter a name")
EndIf
Select Menu("Okay " + Name$ + ", do you love PureBasic?", "Yes|No|Dunno")
Case 1
PrintN("Glad to hear it!")
Case 2
PrintN("Oh no! 😦")
Case 3
PrintN("Okay then. 😕")
EndSelect
Pause
Exit("Goodbye!")
CompilerEndIf