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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |