Expand/Shrink

free_console

Definition: free_console()
Description: Free (delete) any console window associated with your program.
pwa/p2js: Implemented as a dummy routine that does nothing.
Comments: Phix will create a console text window for your program the first time that your program prints something to the screen, reads something from the keyboard, or in some way needs a console (similar to a DOS-prompt window).
On Windows this window will automatically disappear when your program terminates, but you can call free_console() to make it disappear sooner.
On Linux, the text mode console is always there, but an xterm window will disappear after Phix issues a "Press Enter" prompt at the end of execution.

On Linux, free_console() will set the terminal parameters back to normal, undoing the effect that curses has on the screen.

In a Linux xterm window, a call to free_console(), without any further printing to the screen or reading from the keyboard, will eliminate the "Press Enter" prompt that Phix normally issues at the end of execution.

After freeing the console window, you can create a new console window by printing something to the screen, or simply calling clear_screen(), position() or any other routine that needs a console.

When you use the trace facility, or when your program has an error, Phix automatically creates a console window to display trace information, error messages etc.

There is a Windows API routine, FreeConsole() that does something similar to free_console().
You should use free_console(), because it lets the interpreter know that there is no longer a console.

While developing Edita/Edix, I often have some diagnostic output to a console (ie one exists). When running a program, a call to free_console() "dis-associates" the existing parent console, with a new one opened as needed. For this reason you may find that several of my demo programs start with free_console(), so that any output does not quietly get shown on the existing console, hidden in the background. Otherwise, of course, it has no effect.
Implementation: via :%opFreeCons / ffree_console() in builtins\VM\pfileioN.e (an autoinclude).
See Also: clear_screen