Re: Command Line Interface

From: Scott McPhillips [MVP] (org-dot-mvps-at-scottmcp)
Date: 02/07/05


Date: Mon, 07 Feb 2005 08:21:56 -0500

Mark Randall wrote:

> Hmm, fair read thanks for that
>
> This is somewhat I am aiming for, to be honest my idea for this is Java
> Netbean's 'console window' which it uses for user input and output. I
> understand the problem is tho that Java is a interpretted language and I
> wish to have compiled code.
>
> I have a project I have written myself with between 10 and 15 thousand lines
> of code and containing several configurable options, rather than creating a
> GUI for them I wanted to impliment a streamed command line mode to edit them
> in the apps GUI' instead of having to provide dialogs for all of them.
>
> For example, I have a global defined class with some data in it, and I want
> the user to be able to change some settings via a command-line like
> interface for it, but in a structured way in my code, for example:
>
> flw -config
> flw> Enter Target: [user enters string]
> flw> Enter Speed: [user enters string and conv to double]
> [global class updated]
>
> Now in a console application I would write this as
>
> void SomeSub(void)
> {
> char target[128] = { 0 };
> double speed = 0.0;
> char happy[8] = { 0 };
>
> cout << "Enter Target: ";
> cin >> target;
> cout << "Enter Speed";
> cin >> speed;
>
> However, I want this to be implimented in a CEdit, or preferably, a
> CRichEditCtrl... I can write functions to read a string from the end of a
> line by using CString::Mid from the last length, to the new length once
> return is pressed.
>
> What I want my 'command line' like interface to do, is wait while the user
> enters a string, and then it continues once return has been pressed,

The existing procedural code will have to be run in a secondary thread
so the GUI will remain responsive while the code is waiting for user
intput. That can be done by putting all that code under a single
function, say "ThreadMain", then calling AfxBeginThread(ThreadMain, param).

Then to achieve I/O in the GUI you could impliment a few helper
functions to provide the equivalent of cin, cout, etc. to your thread.
These functions would use interthread communication to accomplish the
I/O in the GUI thread. Each helper function would use
WaitForSingleObject() to pause the worker thread until the user response
is available. The GUI thread uses SetEvent to signal the worker thread
when to resume.

-- 
Scott McPhillips [VC++ MVP]


Relevant Pages

  • Re: AppleCommander 1.3.5
    ... Java package, you'd do something like this from the command line: ... Please don't take me the wrong way, when I did try the GUI version, ... home dot woh dot rr dot com slash jbmatthews ...
    (comp.sys.apple2.programmer)
  • Re: How to make java client app to download jar package from server autoly?
    ... why would you want to use Java to ... command line, as opposed to a program with a GUI? ... JVM needs to load, loads some basic classes, load ... A GUI would be a disaster for this type of work - there is no way I'm ...
    (comp.lang.java.programmer)
  • Re: AppleCommander 1.3.5
    ... Java package, you'd do something like this from the command line: ... Please don't take me the wrong way, when I did try the GUI version, ... and I'm sure that for the reasons you developed ...
    (comp.sys.apple2.programmer)
  • Re: Java Application (ie no gui, applets, etc) Beginners Books?
    ... | learn that then work my way up to GUI's and applets and web ... It is simpler debugging from the command line. ... people scream for when they are learning Java, ... Command line classes can have a GUI put on top ...
    (comp.lang.java.programmer)
  • Re: Urgent ! place the Console Window inside the GUI
    ... > I am developing GUI application in tcltk, i want the console window to ... > be a part of my GUI, ... For a command line, I usually use the following for debugging: ... .con insert end ">" ...
    (comp.lang.tcl)