Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

TkCon embedded in application - How to display prompt at end of executing a command?

58 views
Skip to first unread message

Frank

unread,
Mar 18, 2019, 11:28:43 AM3/18/19
to
Hi,

I have TkCon embedded in an application. The user can execute application commands right from TkCon. The command executes successfully writing stdout and stderr to the console. The problem is that at then end of the command executed I am not getting the prompt at the bottom. Once the user presses enter in the console the prompt is the displayed.

Is there a way I can tell TkCon that I finished executing the command and to provide the prompt again at the bottom?

My application writes directly to the TkCon text widget when the command is executed.


This is an example of what I see:


tkCon_prompt > my_application_command

.....
This is the output of my_application_command
..... the command execution is done here (no prompt)

<user presses enter in the keyboard with the TkCon in focus>

tkCon_prompt > <prompt now appears and is ready for the next command>




Hopefully that explains the situation.

Thanks in advance.

Christian Gollwitzer

unread,
Mar 18, 2019, 12:16:11 PM3/18/19
to
Am 18.03.19 um 16:28 schrieb Frank:
> I have TkCon embedded in an application. The user can execute application commands right from TkCon. The command executes successfully writing stdout and stderr to the console. The problem is that at then end of the command executed I am not getting the prompt at the bottom. Once the user presses enter in the console the prompt is the displayed.

I also have embedded tkcon in several applications, and for me it just
works.
>
> Is there a way I can tell TkCon that I finished executing the command and to provide the prompt again at the bottom?
>
> My application writes directly to the TkCon text widget when the command is executed.

What does this mean, which command do you use to write to the text
widget? I simply use "puts", which is redirected by the tkcon.

>
>
> This is an example of what I see:
>
>
> tkCon_prompt > my_application_command
>
> .....
> This is the output of my_application_command
> ..... the command execution is done here (no prompt)
>
> <user presses enter in the keyboard with the TkCon in focus>
>
> tkCon_prompt > <prompt now appears and is ready for the next command>
>

I alos know this situation when your comman ddoes not return, but anters
a nested event loop. Doing "vwait something" in a proc will not come
back and requires you to hit the enter key.

This is how I start tkcon:

set tversion [package require tkcon]
# setup tkcon, as in http://wiki.tcl.tk/17616
#------------------------------------------------------
# The console doesn't exist yet. If we create it
# with show/hide, then it flashes on the screen.
# So we cheat, and call tkcon internals to create
# the console and customize it to our application.
#------------------------------------------------------
set tkcon::PRIV(showOnStartup) 0
set tkcon::PRIV(root) .console
set tkcon::PRIV(protocol) {tkcon hide}
set tkcon::OPT(exec) ""



Christian

Frank

unread,
Mar 19, 2019, 12:25:03 AM3/19/19
to

Hi Christian,

Thanks for the reply. I write directly to the TkCon text widget. This way I can add tags and easily change the text formatting.

> I alos know this situation when your comman ddoes not return, but anters
> a nested event loop. Doing "vwait something" in a proc will not come
> back and requires you to hit the enter key.
>

Okay so this is what I mean but I do not know what is causing this. I do not have the "vwait" issue. The only vwait I found was in the TkCon code itself.

What else could cause this nested event loop? Can I flush the events some how to test it?

Thanks in advance.

Christian Gollwitzer

unread,
Mar 19, 2019, 1:45:28 AM3/19/19
to
Am 19.03.19 um 05:25 schrieb Frank:

> Thanks for the reply. I write directly to the TkCon text widget. This way I can add tags and easily change the text formatting.

Then how about finishing your commands with a single
puts ""

?

Christian

Rich

unread,
Mar 19, 2019, 10:25:53 AM3/19/19
to
Frank <kra...@gmail.com> wrote:
>
> Hi Christian,
>
> Thanks for the reply. I write directly to the TkCon text widget.
> This way I can add tags and easily change the text formatting.

Meaning you do not use "puts" and instead directly insert data into the
TKCon text widget by directly calling the widget itself?

If so, then the cause might be that you are bypassing the normal TKCon
input code, and maybe something within that code is tracking text
widget line positions to do some extra 'magic'. If this is the case,
then the cause would be that you are not also updating some critical
internal state of TkCon (or not calling a critical 'show prompt' proc)
that necessary for it to redisplay its prompt.

> What else could cause this nested event loop? Can I flush the events
> some how to test it?

Are you sure you have a nested event loop to begin with? If not, don't
go down this rabbit hole just yet.

First real question would be, does your code ever allow the event loop
to run in the first place? This is a very common mistake to make,
failing to let the event loop get a chance to run, but expecting some
output to show up on the screen.

Frank

unread,
Mar 19, 2019, 12:49:16 PM3/19/19
to
Hi Rich,

You got me looking more in detail to the TkCon code. :-)

If I execute the following code:

if { ![catch {package present tkcon} } { ::tkcon::Prompt }

The prompt is redisplayed at the end/bottom of the tkCon console.

The question is now, how could I automate this so when idle (no procs running) the prompt will be added.

Currently I am looking into using a bind so when the focus or mouse enters widget it will be invoked but I am looking for a more elegant solution.

Thanks again

Rich

unread,
Mar 19, 2019, 1:50:24 PM3/19/19
to
[This is a Usenet newsgroup, you just happen to be using google groups
to read/post to it. In which case, please follow Usenet conventions in
properly quoting context from the article to which you are replying.
Those of us who avoid google groups like the plague (it is an awful way
to read Usenet newgroups) end up with a new article with zero context
of what was in the article to which you replied.]

Frank <kra...@gmail.com> wrote:
> You got me looking more in detail to the TkCon code. :-)
> If I execute the following code:
> if { ![catch {package present tkcon} } { ::tkcon::Prompt }
> The prompt is redisplayed at the end/bottom of the tkCon console.
>
> The question is now, how could I automate this so when idle (no procs
> running) the prompt will be added.

The easiest would be to just create for yourself a wrapper proc for
interacting with TkCon window, and call tkcon::Prompt as the last thing
you do in the wrapper. I.e.:

proc write-console {string} {
.tkcon.text insert end $string ;# Note - I don't know how you are
# actually 'stuffing' data into the
# text widget, so I've made something
# up here.
other-stuff-you-do-with-the-console

::tkcon::Prompt
}

This would give you a prompt after every "write-console" call,
automatically.

If you only want a prompt after some writes, but not others, then
create two wrappers, and always remember to call the 'prompting'
wrapper at the points where you really do want a prompt to appear.

> Currently I am looking into using a bind so when the focus or mouse
> enters widget it will be invoked but I am looking for a more elegant
> solution.

Seems overkill, unless you only want the prompt to appear when a user
focuses into the console. But if the user never focuses out and back
in, this binding would not fire, and no prompt would appear.

Frank

unread,
Mar 19, 2019, 6:24:36 PM3/19/19
to
Hi Rich,

On Tuesday, March 19, 2019 at 12:50:24 PM UTC-5, Rich wrote:
> [This is a Usenet newsgroup, you just happen to be using google groups
> to read/post to it. In which case, please follow Usenet conventions in
> properly quoting context from the article to which you are replying.
> Those of us who avoid google groups like the plague (it is an awful way
> to read Usenet newgroups) end up with a new article with zero context
> of what was in the article to which you replied.]
>
> Frank <kra...@gmail.com> wrote:
> > You got me looking more in detail to the TkCon code. :-)
> > If I execute the following code:
> > if { ![catch {package present tkcon} } { ::tkcon::Prompt }
> > The prompt is redisplayed at the end/bottom of the tkCon console.
> >
> > The question is now, how could I automate this so when idle (no procs
> > running) the prompt will be added.
>
> The easiest would be to just create for yourself a wrapper proc for
> interacting with TkCon window, and call tkcon::Prompt as the last thing
> you do in the wrapper. I.e.:
>
> proc write-console {string} {
> .tkcon.text insert end $string ;# Note - I don't know how you are
> # actually 'stuffing' data into the
> # text widget, so I've made something
> # up here.
> other-stuff-you-do-with-the-console
>
> ::tkcon::Prompt
> }


I have something that does fundamentally what you have above. I could not add it there because as you pointed out I get it on every output to the console and it looks bad.

I ended up adding a bind when the mouse enters, could be focus too. It calls a proc that checks if the last line is a prompt. If it is, it does not do anything. If not then it adds the prompt and shows the last line.

It is not perfect but I did not want to make changes through the code deciding when to call the proc to add the prompt and when not to.

So far it seems to be behaving good.


>
> This would give you a prompt after every "write-console" call,
> automatically.
>
> If you only want a prompt after some writes, but not others, then
> create two wrappers, and always remember to call the 'prompting'
> wrapper at the points where you really do want a prompt to appear.
>
> > Currently I am looking into using a bind so when the focus or mouse
> > enters widget it will be invoked but I am looking for a more elegant
> > solution.
>
> Seems overkill, unless you only want the prompt to appear when a user
> focuses into the console. But if the user never focuses out and back
> in, this binding would not fire, and no prompt would appear.


Thanks again

Frank

unread,
Mar 19, 2019, 7:57:56 PM3/19/19
to
Hi Christian,

Sorry I did not reply. I tried to add the puts at the end. It did not work.

0 new messages