Author: Eric Taylor <[email protected]>
State: Draft
Type: Project
Vote: Pending
Created: 23-Jan-2020
Post-History:
Tcl-Version: 9.1
Keywords: Tk
Tk-Branch: tip-561
Abstract
This TIP proposes that the console
command be made an official supported
command for Linux and other Unix platforms (hereafter called unix). A console
can currently be run under unix, but it requires some additional code. This
TIP proposes that official support be given for the console
command on unix
and that the code to do so become part of the Tcl/Tk core.
Rationale and Discussion
In the Tcl'ers Wiki, there
is a submitted code block that can be used on unix that will add the console
command and text window to a Tcl/Tk program. This works quite well, and has
been available since 2005. However, it is not automatically supported "out of
the box" and one has to do a few things to get the code and run it. It would
be very handy if one could open a console on unix directly in the same way as
on the other console
command aware systems.
There is one caveat mentioned in the wiki code. In particular, it makes use of some undocumented internals and could thus break in a future release. Since this code works so well, it seems that it should become a supported core feature on unix.
This TIP would eliminate an existing incompatibility between platforms, and should also protect this console code from breakage in future releases.
Proposal
The console
command would become a supported command in the core on all
Tk-enabled systems. The above mentioned wiki code (with a bit extra as shown
below) would be stored along with the other pure Tcl/Tk code (possibly in
tklib) and used in the unix platform.
No special setup would be required to use the console
command. However,
until the console
command is executed at least once, stdout and stderr would
continue to go to the terminal window where wish was invoked. This would
retain the current behavior. Only after executing a console
command (e.g.
console show
) would stdout and stderr be redirected to a new console text
window.
Incompatibilities
Currently in unix, output for stdout and stderr goes to the terminal window
where the program was run. After the above mentioned code is sourced, output
to stdout and stderr are redirected to a new toplevel window. In order to
remain compatible with existing behavior, the initial setup of a unix console
needs to be delayed until the user first issues, at least one, console
command, such as console show
or console hide
.
Some consideration may need to be given if the user redirected output either
by a shell command or in an exec
command and also includes a console
statement.
Implementation
The following has been tested on a pop-os linux system by sourcing the below code. A small change to the current wiki code is needed to keep compatibility with the existing unix stdout and stderr behavior.
set ::tk::console_on_unix {
<include wiki code here with the one extra statement below at the end>
set ::tk::console_on_unix_begin 1 ;# extra statement to continue after vwait
}
proc console {args} { ;# initial one time use definition of console
rename console {} ;# delete this definition of console now
after 0 {eval $::tk::console_on_unix ; unset -nocomplain ::tk::console_on_unix}
vwait ::tk::console_on_unix_begin ;# wait till setup complete
unset -nocomplain ::tk::console_on_unix_begin
tailcall console {*}$args ;# call the new console command with current args
}
This code would need to be executed at startup automatically on a unix system.
It provides the initial definition of console
that would, when once called,
complete the remaining setup, remove itself, and call the new console
definition with the current arguments.
This method will retain the current stdout and stderr behavior until at least
one console statement is executed. So, if the user were to issue a console
show
command, it will work as expected.
If the user only wants to create the console but not have it visible yet, one
can call console hide
as the first console statement. Any stdout/stderr
output after the setup would then become visible when the console was later
opened.
Since this would made available in 8.7 or later, some of the wiki code might not be needed.
Copyright
This document has been placed in the public domain.