Console example modified for Gnome Terminal

Applications, Games, Tools, User libs and useful stuff coded in PureBasic
dmontaine
User
User
Posts: 45
Joined: Tue Jun 04, 2019 1:03 pm

Console example modified for Gnome Terminal

Post by dmontaine »

Even though the console commands are marked as Windows only in the documentation, they will work under Linux with Gnome Terminal from Ubuntu 22.04. Use the Create Executable option, then open Gnome Terminal, make the file executable and run from there.

Code: Select all

;
; ------------------------------------------------------------
;
;   PureBasic - Console example file
;
;    (c) Fantaisie Software
;
;   Modified for Gnome Terminal - Ubuntu 22.04
;   by Donald Montaine - 2 Nov 2023
;
; ------------------------------------------------------------
;
    text$  		= "Feel the Power of PureBasic!"  	
    exittext$ 	= "Press any key to exit. "
    dlay   		= 4000						

;
;-------- Open our Console --------
;

    OpenConsole()                                 			 
    ConsoleTitle ("PureBasic - Console Example:")  
    EnableGraphicalConsole(1)                     		 

;
;-------- Ask and display the UserName --------
;
    ClearConsole()
    ConsoleLocate (18,12)                          		
    Print ("Please enter your name:   ")          		
    name$=Input()                                  		

    ClearConsole()                                 			
    
    ConsoleLocate (24,10)                         		
    PrintN ("Welcome "+name$)                      		
    ConsoleLocate (24,12)                          		
    PrintN (text$)                                 			

    Delay (dlay)                                   			

;
;-------- Cls and Cycle the Text-BG-Color 0 to 15 --------
;

    ClearConsole()                                 			
                                                   				
    For i = 0 To 15
        ConsoleColor (0,i)                         			
        ConsoleLocate (24,4+i)                     		
        Print (text$)                             			
    Next i

    Delay (dlay)                                  			

;
;-------- Cls and Cycle the Text-FG-Color 0 to 15 --------
;

    ConsoleColor(0,0)                              			
    ClearConsole()                                 			
                                                   				
    For i = 0 To 15
        ConsoleColor (i,0)                         			
        ConsoleLocate (24,4+i)                     		
        Print (text$)                              			
    Next i

    Delay (dlay)                                   			

;
;-------- Cls and Cycle the Background-Color 0 to 15 --------
;

    For a = 1 To 15
        ConsoleColor(a,a)                          			
        ClearConsole()                             			
 
        For i = 0 To 15
            ConsoleColor (i,a)                     			
            ConsoleLocate (24,4+i)                		
            Print (text$)                          			
        Next i
        ;
        Delay(dlay/10)                             			
    Next a
    ;
    ;-------- Exit --------
    ;
    
    ConsoleColor(15,0)
    ClearConsole()
    ConsoleLocate(0,0)

    Print(exittext$)
    
    Repeat
        RetVal$ = Inkey()  
        Delay(2)
    Until RetVal$ <> ""
    
    ConsoleColor(15,0)
    ClearConsole()
    ConsoleLocate(0,0)
    EnableGraphicalConsole(0)
    CloseConsole()
    
End
User avatar
Kuron
Addict
Addict
Posts: 1626
Joined: Sat Oct 17, 2009 10:51 pm
Location: Pacific Northwest

Re: Console example modified for Gnome Terminal

Post by Kuron »

From the official documentation:

https://www.purebasic.com/documentation ... index.html

Supported OS

All
Best wishes to the PB community. Thank you for the memories. ♥️
dmontaine
User
User
Posts: 45
Joined: Tue Jun 04, 2019 1:03 pm

Re: Console example modified for Gnome Terminal

Post by dmontaine »

Some of the commands say Windows only. For example EnableGraphicalConsole():
However, when used on Linux it enables positioning using ConsoleLocate() which
is also marked Windows only. I am looking at the help that is accessed by choosing
Help, Help in the Linux 6.03 LTS version of PureBasic. Perhaps the embedded documentation
for Linux and the pdf are different???
----------------------------------------------------------------------------------------------------------------
EnableGraphicalConsole()

Parameters

State
If 'State' is 1, then console will be switched to graphical mode, else if 'State' is 0, it will switch back to text mode.

Return value

None.

Remarks

The default mode of the console is the text mode, which means the text can't be positioned anywhere in the console, but redirections (through pipes) work correctly.

When being in the graphical mode, functions like ClearConsole() or ConsoleLocate() are available and the text can be positioned anywhere in the console screen, which allow to do console games or text only applications (which can be useful when accessed remotely through telnet or ssh). The redirection (pipes) doesn't work correctly when being in graphical mode.

Example

If OpenConsole()
EnableGraphicalConsole(1)
ConsoleLocate(7, 8)
PrintN("Press return to exit")
Input()
EndIf



See Also

ConsoleLocate(), ConsoleColor(), ClearConsole()

Supported OS

Windows
------------------------------------------------------------------------------
ConsoleLocate()


Syntax

ConsoleLocate(x, y)

Description

Moves the cursor to the given position, in character coordinates. Any text you print after calling this function will start from the specified coordinates.

Parameters

x
The horizontal position in the console to move to (starting from 0)

y
The vertical position in the console to move to (starting from 0)

Return value

None.

Remarks

The console has to be in graphical mode, see EnableGraphicalConsole().

Example

If OpenConsole()
EnableGraphicalConsole(1)

For i = 0 To 200
ConsoleLocate(Random(79), Random(24))
Print("*")
Next

ConsoleLocate(30, 10)
PrintN("Press return to exit")
Input()
EndIf



See Also

EnableGraphicalConsole()

Supported OS

Windows
Post Reply