LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Position cursor in std i/o window

I suggest you try gets().
gets() handles moving the cursor for you.
gets() can handle the user changing ACmdHere to ACmdOverHere.
Using gets() you don't need GetKey, isalnum, ispunct, putchar, or tests for LEFT_ARROW_KEY, etc.
GetKey isn't in the ANSI C library so you may have trouble porting it to another platform like embedded linux.
0 Kudos
Message 11 of 14
(1,455 Views)
Your right I should probably use getchar() for portability.
The reason I don't want to use gets() is because it only returns when the user hits the ENTER key. I'm implementing command completion functionality for my CLI and need gets() to return if the user enters a TAB (in addition to an ENTER). I was actually, using gets() and your right, it did everything for me(history buffer too with the use of the UP & DOWN arrows!). I then needed to implement the command completion and gets() wouldn't return until an ENTER key was hit. Sooooo, I have to handle all the keys. It's not too bad except I can't figure out how to move the cursor. I think it is done with escape sequences (i.e., '\r' sends the cursor to the beginning of the line, etc.) but I don't know what they are.
0 Kudos
Message 12 of 14
(1,452 Views)
Sorry, I've never seen a command line interface that terminates a command on a tab.
If you control the design requirements for the project, I'd drop the tab as a command terminator.
If you can't do that...
I haven't tried it yet but here are a couple of ideas to start with.
\b is a non-destructive backspace. To back up on a command line, you can putc() putchar() or printf() a \b.
I know of no forward space character in ANSI C or the ASCII character set. To go forward, I think you'll have to rewrite the line then use \b to backup if you're not at the end of the line.
So you'll need to keep track of where you on on the command line.
Stop using \b if you get to the start of the entered command (don't backspace onto the prompt).
Stop moving the cursor if you reach the end of line.
Note that you may have to modify your test for the left and right cursor keys as you move to a different platform: what works for Windows may not work for embedded linux.
0 Kudos
Message 13 of 14
(1,440 Views)
Thanks for your input, this is exactly what I ended up doing.
Incedently, I don't terminate the command on a tab, however I need gets() to return to me on a TAB (which it won't do) so that I can complete the command the user has started (ie., implement command completion). I then terminate his input when he susequently hits the ENTER key.
0 Kudos
Message 14 of 14
(1,433 Views)