I have been considering adding an interactive shell to one of our
stand alone applicaions.
Any ideas on how to do this?
Dave
Dave
#!/usr/bin/tclsh
set saveinterp [ interp create -safe ]
puts stderr "saveinterp created : $saveinterp"
set prompt "\n>> "
set ::run 1
set ::ifd stdin
set ::ofd stdout
# I guess here you would insert some aliases and stuff
# for commands not present in the save interp to work
# ( in a save way, puts, exit, ... comes to mind )
# end of prelude
while {$::run} {
puts -nonewline $::ofd \n$prompt ; flush $::ofd
append script " "
append script [ gets $::ifd ]
if {[info complete $script]} {
catch { interp eval $saveinterp $script } cerr
puts -nonewline $::ofd $cerr ; flush $::ofd
unset script
set ::prompt "\n>> "
} else {
set ::prompt "\n > "
}
}
uwe
Not sure how this works -- the idea I was hoping for was more along
the lines of a text editor that I would be able to embed in my Tcl/Tk
application for the user to perofrm tcl functions, string
manipulations, evaluations, etc. from within the text widget.
Got any ideas on that?
Dave
> ...
> Not sure how this works -- the idea I was hoping for was more along
> the lines of a text editor that I would be able to embed in my Tcl/Tk
> application for the user to perofrm tcl functions, string
> manipulations, evaluations, etc. from within the text widget.
>
> Got any ideas on that?
>
If your Tcl/Tk application simply embedded tkcon (= sourceing tkcon.tcl)
, would that provide the sort of functionality that that you're after?
You probably need to make some modifications to make the interactive
interpreter safe.
References:
http://tkcon.sourceforge.net/
http://mini.net/tcl/tkcon
Erik
--
leunissen@ nl | Merge the left part of these two lines into one,
e. hccnet. | respecting a character's position in a line.
What are you actually trying to achieve?
One fast way is embedding the tkcon megawidget as a command shell.
(http://wiki.tcl.tk/17616)
Depending on your requirements (aka should users be able to block/kill
the app from the shell or not) you might want put the console into a
separate thread and in a safe interpreter there or just in a safe
interpreter.
If you put tkcon into a child interpreter (safe or not) you can then
export your application API with some interp aliases. I usually put my
external interface in one namespace and then use something like this to
init the aliases in the console interpreter:
foreach cmd [info commands ::external::*] {
interp alias $consoleInterp $cmd {} $cmd
}
If you think about user written plugins, the pluginmgr module in tcllib
might be useful for you, it provides a safe interpreter sandbox with
definable APIs for plugins.
http://tcllib.sourceforge.net/doc/pluginmgr.html
Especially [exit] should be remapped in the child interpreter, to do
something sane for your app.
Michael
YES - that is about PEREFCT - but Too MUCH! Anyway to get rid of the
menus and all of that..?
Dave