I am trying to do a commandline type emulator using a Tk::Text widget and even if I do say so myself, have done much better then I expected. I have however run into a problem, I am trying to represent a sort of old style main frame form which is filled in with data. I can print out the form but I've tried allsorts of ways to place the curser but to no eval.

1. Is this the right widget to do this sort of job?
2. How can I place the curser? The place I need to do this is in startText
3. Is this a pointless task and would an entry box type interface be better?

Remember some of the users have been working on mainframes for years and love the session stlye interface.

use Tk; use strict; my $start ='1.0'; my $mw = new MainWindow(); my $ta = $mw->Text(-bg => 'black', -fg => 'green', -insertbackground=>'green')->pack(); $ta->focus(); $ta->bind('<Return>',[\&getText, \$start]); $ta->bind('<Up>',[\&setStart, \$start]); $ta->bind('<Down>',[\&setStart, \$start]); $ta->bind('<Left>',[\&setStart, \$start]); $ta->bind('<Right>',[\&setStart, \$start]); $ta->bind('<Control-c>',sub{exit}); startText(); MainLoop; sub startText{ insertText("Mainframe Monkey Version \'dev\' Oct 2004 - RJC Pr +oduction\n"); insertText("\n USER: [ ]\n\n PASSWORD:[ + ]"); #need to loop back to the USER input at this point setStart(); } sub setStart{ $start = $ta->index('insert'); } sub getText{ my @lp = split /\./,$start; my $com = $ta->get($start, "$lp[0].end"); chomp $com; $com =~ s/ //g; $com =~ s/_//g; doAction($com); $start = $ta->index('insert'); } sub doAction{ my $com = $_[0]; $com = uc $com; if ($com eq 'EXIT'){$mw->destroy} elsif ($com eq 'DIR'){my $dir = `dir`;insertText($dir);} elsif ($com eq 'CLS'){$ta->delete('1.0','end');setStart();} else {insertText("\nUnKown command or program\n")} } sub insertText{ my $text = $_[0]; $ta->delete('insert','end'); $ta->insert('insert',$text); $ta->see('insert'); }

Thanks for your help on this one.

Update: Noticed a misstake in the calls to setStart.

In reply to Tk marks and placing the cursor by Scarborough

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.