Alternate Console

Share your advanced PureBasic knowledge/code with the community.
User avatar
JHPJHP
Addict
Addict
Posts: 1851
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Alternate Console

Post by JHPJHP »

-----------------------------------------------------------------------------------

Download Alternate Console from My PureBasic Stuff

-----------------------------------------------------------------------------------

Announcements
PureBasic Interface to OpenCV
PureBasic Interface to WinDivert
PureBasic Interface to WinRAR
PureBasic Interface to 7-Zip
PureBasic Interface to ImDisk
Windows Services & Other Stuff
Invading Space Aliens
Death Star vs Asteroids
GIF Toolkit
LSB Image Steganography
Spider Web Drawing
Deform Image: MLS
Video Snipping Tool
Chromium Edge WebGadget
IAccessible Interface
Stitch Images: SIFT
OldSkool Fire Effect
Image Waves: LUT
YouTube Player & Downloader
MP4 Player & Downloader
Large Image Viewer
Barcode Generator
Google Translate Service
Embed JS into PureBasic
Geolocation: Google Maps
Book & Viewer & Magnify
Video for Windows: VfW
Alternate Console
Network Share Management

-----------------------------------------------------------------------------------

ShowConsole(State = 1)
- defaults to showing Console in Normal Mode (1)
- sets state for both AltConsole or CmdConsole (0 = hidden, 1 = Normal, 2 = Minimized, 3 = Maximized)

BringToTop(hConsole)
- not called directly
- brings AltConsole or a visible CmdConsole to the foreground on open

GetColors(CharacterColor, BackgroundColor)
- not called directly
- sets colors for both AltConsole or CmdConsole

HandlerRoutine(dwCtrlType)
- not called directly
- callback to catch AltConsole or CmdConsole closing

-----------------------------------------------------------------------------------

altOpenConsole(State = 1, Title.s = "Alternative Console", xColumn = 80, yRow = 300)
- defaults to showing Console in Normal Mode (1) with "Alternative Console" for Title and Console Width (80) Height (300)
- opens in various states (0 = hidden, 1 = Normal, 2 = Minimized, 3 = Maximized)
- resizes the Console width/height
- opens a new Console with specified Title

altConsoleTitle(State = 1, Title.s = "Alternative Console")
- defaults "Alternative Console" for new Title
- changes current Console's Title

altPrint(Text.s = " ", nRepeat = 1)
- defaults one space
- option to repeat Text n times

altPrintN(Text.s = #Null$, nRepeat = 1)
- defaults one newline
- option to repeat Text/Newline n times

altFillChar(Character, nLength = 1)
- fills ascii Character n length

altFillColor(CharacterColor = 7, BackgroundColor = 0, nLength = 1)
- defaults one character length of the deafult colors
- fills n character length to chosen colors (color codes same as PureBasic)

altConsoleColor(CharacterColor = 7, BackgroundColor = 0, Mode = 0)
- default colors for new text (Mode 0) old text remains the same
- Mode 0: changes colors for new text / old text remains the same (color codes same as PureBasic)
- Mode 1: changes entire Console to chosen colors (color codes same as PureBasic)

altConsoleLocate(xColumn, yRow)
- moves the cursor to the new x/y location

altReadConsoleData(xColumn = 0, yRow = 0, nLength = 0)
- defaults reading the entire Console text
- reads the console text from x/y n length

altClearConsole(xColumn = 0, yRow = 0, nLength = 0)
- defaults clearing the entire Console's text and colors
- clears the Console text from x/y n length

altNewConsole(State = 99, Title.s = #Null$)
- defaults to showing Console in State from previous Console with Title from previous Console
- closes previous Console
- opens new Console with optional new State
- opens new Console with optional new Title

altInkey()
- captures ascii key strokes showing the character key value

altRawKey()
- shows the raw key code for ascii and non-ascii keys

altConsoleImage(ImageName.s = #Null$, nDelay = 1000)
- defaults with an OpenFileRequester prompt and a transition Delay of 1000ms
- optional ImageName can be either path or path\filename
- translates the pixels from a *.jpg | *.png | *.bmp file to console characters
- nDelay is used to pause n milliseconds between images

altConsoleAnimate(hImage)
- translates the pixels from a *.png file to console characters
- requires a sprite sheet with equally spaced x/y images or an animated GIF

altInput(Text.s = #Null$)
- defaults a pause waiting for the Enter key to be pressed
- reads text written after the input (pause) location
- allows for Text to be included with the pause
- dispalys optional Text in bottom/left of visible Console

-----------------------------------------------------------------------------------

cmdOpenConsole(State = 1, Title.s = "Command Console")
- defaults to showing Console in Normal Mode (1) with "Command Console" for Title
- opens in various states (0 = hidden, 1 = Normal, 2 = Minimized, 3 = Maximized)
- opens a new Command Console with specified Title

cmdChangeColor(CharacterColor = 7, BackgroundColor = 0)
- defaults the Command Console to default colors
- changes the Command Console to chosen colors (color codes same as PureBasic)

cmdAddAlias(Source.s, Target.s, ExeName.s = "cmd.exe")
- defaults alias commands to cmd.exe
- allows multiple commands to be combined then called using an alias
- alias commands can be used with any executable

cmdRunScript(Text.s, RunAndWait = #False)
- defaults to passing commands without waiting for them to finish
- runs commands passed by Text with an option to wait for them to finish

cmdRunBatch(FileName.s = #Null$, RunAndWait = #False)
- defaults with an OpenFileRequester prompt
- reads a .bat or .txt file line by line and runs the commands
- optional run and wait (will be applied to each command)

cmdReadConsole(nLeft = 0, nTop = 0, nRight = 0, nBottom = 0, nDelay = 0)
- defaults reading the entire Command Console text
- reads the Command Console text from the left/top/right/bottom location
- delay the reading until the console is fully populated

cmdCloseConsole()
- closes the Command Console
- this should always be called with a hidden Command Console
Last edited by JHPJHP on Sat Oct 16, 2021 9:00 pm, edited 86 times in total.

STATUS: Mostly Unavailable :: Downloads moved to My PureBasic Stuff; free executables, access key required for source code.
_________________
User avatar
ostapas
Enthusiast
Enthusiast
Posts: 192
Joined: Thu Feb 18, 2010 11:10 pm

Re: Alternate Console

Post by ostapas »

Many thanks for the recent "parcel out" of your codes, this really brings some fresh air to the forum!
User avatar
JHPJHP
Addict
Addict
Posts: 1851
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: Alternate Console

Post by JHPJHP »

Hi ostapas,

You're most welcome. It was cathartic to "clean out my script closet", and hopefully provide something useful in the process.

Cheers!

STATUS: Mostly Unavailable :: Downloads moved to My PureBasic Stuff; free executables, access key required for source code.
_________________
User avatar
Kwai chang caine
Addict
Addict
Posts: 4968
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Alternate Console

Post by Kwai chang caine »

Splendid !!! Works very well...
Impressive the man work and panther :shock:
Thanks for sharing 8)
ImageThe happiness is a road...
Not a destination
User avatar
JHPJHP
Addict
Addict
Posts: 1851
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: Alternate Console

Post by JHPJHP »

Hi Kwai chang caine,

Thank you for your comments.

--------------------------------------------------

Updated to support Windows 10, including various bug fixes.

If the animations show in full-screen:
- delete the Registry key: HKEY_CURRENT_USER\Console
-- the Console key will be recreated when changes are made to a console's properties
- set cmd.exe (Command Console) to legacy mode from properties
-- don't set this option from the console created by the program
-- this option may not be available in earlier versions of Windows
Last edited by JHPJHP on Tue May 08, 2018 9:15 pm, edited 3 times in total.

STATUS: Mostly Unavailable :: Downloads moved to My PureBasic Stuff; free executables, access key required for source code.
_________________
User avatar
JHPJHP
Addict
Addict
Posts: 1851
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: Alternate Console

Post by JHPJHP »

Updated:
- added 1 example
-- alt_animation_gif.pb
- added 5 images
-- countdown.gif, fishing.gif, flipping.gif, running.gif, troll.gif

Previously only Sprite sheets were used to generate Console animations, but thanks to the PureBasic team adding GIF support, animated GIF's can also be used.

If your interest is only Console animations, download the Standalone version of Console Animation from the first post, I'm not sure the Alternate Console download has a use outside of curiosity; this was one of the first things I wrote while learning PureBasic, and maybe can assist someone travelling a similar road.

STATUS: Mostly Unavailable :: Downloads moved to My PureBasic Stuff; free executables, access key required for source code.
_________________
User avatar
Kwai chang caine
Addict
Addict
Posts: 4968
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Alternate Console

Post by Kwai chang caine »

Hello JHPJHP :D

I use your splendid alternate console since several month ago 8) , and i don't know why, only sometime not always, i have an IMA at this line

Code: Select all

Dim lpBuffer.CHAR_INFO(BufferSize, nRight - 1)
in the procedure

Code: Select all

ReadCmdConsole(nLeft.i = 0, nTop.i = 0, nRight.i = 0, nBottom.i = 0)
Then i stop the code, and run another time and all is good after :shock:

I have noticed the variable "BufferSize" is empty, have you an idea what is the reason why ?
ImageThe happiness is a road...
Not a destination
User avatar
JHPJHP
Addict
Addict
Posts: 1851
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: Alternate Console

Post by JHPJHP »

Hi Kwai chang caine,

I can see a couple problems...

1. The version you are using is out of date: Download links in the first post have been updated.
2. The Function GetConsoleScreenBufferInfo can fail, but I wasn't trapping for it; this has been updated.
-- you may want to include a notification if the call fails
Last edited by JHPJHP on Tue Jun 20, 2017 12:01 am, edited 3 times in total.

STATUS: Mostly Unavailable :: Downloads moved to My PureBasic Stuff; free executables, access key required for source code.
_________________
User avatar
Kwai chang caine
Addict
Addict
Posts: 4968
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Alternate Console

Post by Kwai chang caine »

Thanks a lot for your answer, i try your tips
Have a good night
ImageThe happiness is a road...
Not a destination
User avatar
jassing
Addict
Addict
Posts: 1324
Joined: Wed Feb 17, 2010 12:00 am
Location: (Embarrassed to say country)

Re: Alternate Console

Post by jassing »

Some good stuff in there.
I spotted a couple of (minor) errors.
  • in cmdRunBatch(), (OpenFileRequester()) "StandardFile$" is not defined as local or global variable... shouldn't it be "FileName"?
  • * In cmdReadConsole(), there is a variable that is added to others. "Increment" but this is not defined, so it has no effect.
  • I also found that altPrint() doesn't work if the app is compiled as a console app.
this seems to fix (or hack into submission) the last item.

Code: Select all

Procedure altOpenConsole(State = 1, Title.s = "Alternative Console", xColumn = 80, yRow = 300)
  Protected GetConsoleWindow.protoGetConsoleWindow
  Result = #False
  
  CompilerIf #PB_Compiler_ExecutableFormat = #PB_Compiler_Console
    If  #True  ; hackish, I know.
  CompilerElse 
    If AllocConsole_() 
  CompilerEndIf 

Added a small macro to be the companion to altOpenConsole()

Code: Select all

Macro AltCloseConsole() : FreeConsole_() : EndMacro
Any idea how to tell which window/console has input/focus?

great work!
-j
User avatar
JHPJHP
Addict
Addict
Posts: 1851
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: Alternate Console

Post by JHPJHP »

Hi jassing,

Thank you for your generous contribution, and for your previous post outlining some potential problems with Alternate Console.

Alternate Console was probably my first attempt at creating something "useful" with PureBasic; looking over the code...
- in cmdRunBatch(), (OpenFileRequester()) "StandardFile$" is not defined as local or global variable
-- fixed, package updated
- in cmdReadConsole(), there is a variable that is added to others. "Increment" but this is not defined
-- Increment is used for scrolling/copying the console contents to the debug window/variable; updated the example cmd_show_console.pb to better demonstrate its use
- I also found that altPrint() doesn't work if the app is compiled as a console app
-- I compiled/tested some of the examples (Windows 10) without a problem, please be more specific; small change made to the Procedures altPrint, altPrintN
- Added a small macro to be the companion to altOpenConsole()
-- Shouldn't be needed, see the Procedure/Callback HandlerRoutine, it will free the console on a close event
- Any idea how to tell which window/console has input/focus?
-- Try using the API GetActiveWindow and GetFocus, matched against data derived from an enumeration of opened Window handles; let me know if you need any help

STATUS: Mostly Unavailable :: Downloads moved to My PureBasic Stuff; free executables, access key required for source code.
_________________
User avatar
jassing
Addict
Addict
Posts: 1324
Joined: Wed Feb 17, 2010 12:00 am
Location: (Embarrassed to say country)

Re: Alternate Console

Post by jassing »

JHPJHP wrote: - Added a small macro to be the companion to altOpenConsole()
-- Shouldn't be needed, see the Procedure/Callback HandlerRoutine, it will free the console on a close event
... unless you want to close the console before program end ...


as for the compiled as a console issue (and maybe I'm missing something...)

Code: Select all

IncludeFile "Alt_Console.pbi"
CompilerIf #PB_Compiler_ExecutableFormat = #PB_Compiler_Console
  If altOpenConsole(1,"Test print",100,500)
    altPrintN("This is a test")
    altInput()  
  Else 
    MessageRequester("Ooops","Console Open Failed")
  EndIf
CompilerElse : CompilerError("Compile as a console")
CompilerEndIf
For me, when run as a windows program, it works as expected. but when run as a console, altOpenConsole() fails
User avatar
JHPJHP
Addict
Addict
Posts: 1851
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: Alternate Console

Post by JHPJHP »

Hi jassing,
jassing wrote:as for the compiled as a console issue (and maybe I'm missing something...)
You're correct, I overlooked your code snippet about the Compiler Format, and only focused on compiling an executable; allocating a console in Console Mode is redundant.
- fixed, package updated
jassing wrote:... unless you want to close the console before program end ...
Can you provide an example where the CloseConsole Macro is needed; the existing Event Handler should be sufficient.

Cheers.

STATUS: Mostly Unavailable :: Downloads moved to My PureBasic Stuff; free executables, access key required for source code.
_________________
User avatar
JHPJHP
Addict
Addict
Posts: 1851
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: Alternate Console

Post by JHPJHP »

Updated:
- added a clear console registry option
- applied a couple minor improvements

Clear Console: Registry
This option only applies to the animated examples executed in Windows 10+.

STATUS: Mostly Unavailable :: Downloads moved to My PureBasic Stuff; free executables, access key required for source code.
_________________
User avatar
Derren
Enthusiast
Enthusiast
Posts: 309
Joined: Sat Jul 23, 2011 1:13 am
Location: Germany

Re: Alternate Console

Post by Derren »

Hey,

I just wanted to test your code. Sadly you offer it only on your website for a payment. :(
Post Reply