Question about write a simple shell : how to output resoult to tty correctly

  • Follow


Hi all

I am write a console based application.
Something like a "shell" :  enter string and parser explain it, (actually 
like cisco's console).

I want my app can be controlled on tty via telnet/ssh. so what I want to 
reach is quite like juniper's cli:
sense sample:

host%
host%./app

<APP/MODULE>
>command you input            // input command pre defined , it will cause 
>"parser" parse it and execute it

Command "command you input"  executed!
This execute resoult here.


<APP/MODULE>
>                             // giving prompt and waiting command again

<APP/MODULE>
>exit
sure to exit (y/n) y

host%


=======================================

My basic design idea:
"
tty? <------    OutputBuffer        <-------  app
       |             ^
       |             |
       |-----> VirtualKeyboard     ------->  parser --------> execute

"


I think what I needed is, maybe like  a cli text editor. so I am trying to 
read source code of "vi" ,but too much for me -- sorry to say , out of my 
mind.

then I am trying to using "ncurses" ,and I found using ncurses's WINDOW* and 
set it's y-x manually make more complex mechanism .(scroll screen, echoback 
etc.)
also directly using it may cause wrong display on other telnet 
client.(tested the "Digipad")


My confuse is between tty and OutBuffer , how to make my OutBuffer class 
link with tty more easier ? (may be just like std::cout.)


And what's the next step I should do? any suggest?

Sorry for my knowledge on tty/unix,I am trying.



Thank you very much.


                                                                           key9





0
Reply key9 5/16/2006 4:54:05 PM

key9 wrote:
> Hi all
> 
> I am write a console based application.
> Something like a "shell" :  enter string and parser explain it, (actually 
> like cisco's console).
> 
> I want my app can be controlled on tty via telnet/ssh. so what I want to 
> reach is quite like juniper's cli:
> sense sample:
> 
> host%
> host%./app
> 
> <APP/MODULE>
> 
>>command you input            // input command pre defined , it will cause 
>>"parser" parse it and execute it
> 
> 
> Command "command you input"  executed!
> This execute resoult here.
> 
> 
> <APP/MODULE>
> 
>>                            // giving prompt and waiting command again
> 
> 
> <APP/MODULE>
> 
>>exit
> 
> sure to exit (y/n) y
> 
> host%
> 
> 
> =======================================
> 
> My basic design idea:
> "
> tty? <------    OutputBuffer        <-------  app
>        |             ^
>        |             |
>        |-----> VirtualKeyboard     ------->  parser --------> execute
> 
> "
> 
> 
> I think what I needed is, maybe like  a cli text editor. so I am trying to 
> read source code of "vi" ,but too much for me -- sorry to say , out of my 
> mind.
> 
> then I am trying to using "ncurses" ,and I found using ncurses's WINDOW* and 
> set it's y-x manually make more complex mechanism .(scroll screen, echoback 
> etc.)
> also directly using it may cause wrong display on other telnet 
> client.(tested the "Digipad")
> 
> 
> My confuse is between tty and OutBuffer , how to make my OutBuffer class 
> link with tty more easier ? (may be just like std::cout.)
> 
> 
> And what's the next step I should do? any suggest?
> 
> Sorry for my knowledge on tty/unix,I am trying.
> 
> 
> 
> Thank you very much.
> 
> 
>                                                                            key9
> 
> 
> 

Are you trying to write a shell in C++?  No matter.  I can see no reason
why you should resort to ncurses or anything other than std::cin and
std::cout to do your command I/O.  If you are trying to implement some
kind of command line editing, then you might want to set the tty into
"raw" mode to allow you to override the built-in editing.  If you are
not trying to implement command line editing, then why not just stick
with stdio?

--

Fletcher Glenn

0
Reply Fletcher 5/16/2006 5:53:38 PM


thank you for your reply;

> Are you trying to write a shell in C++?
   something like that

> why you should resort to ncurses or anything other than std::cin and
> std::cout to do your command I/O.

>If you are trying to implement some
> kind of command line editing, then you might want to set the tty into
> "raw" mode to allow you to override the built-in editing.  If you are
> not trying to implement command line editing, then why not just stick
> with stdio?


May be the story beginning from my self educated roadmap of how 
rogramming  -- 2 year ,a reversed way:

"OO design  ; C++  ; STD; design patterns ; ACE ; UNIX/LINUX BASIC(fd thread 
process mutex...);UNIX SOCKET ; UNIX IO, gnu clib...)
 (no C experience,start from little/almost no programming experience)

So my application is design/running on my mind for 2 years.

before coding ,I don't think I/O is a problem until I met I must scan "a 
keypress" to make my parser to determine action. std::cin have no this 
function(getch()),
also I want my app(actually it can be called a  Library) can running on 
other OS . either GUI and CLI , so there must be a adapter layer.(use 
"string" to link them)

I found I have to design an other lib to adapter UNIX I/O,

and may be due to greed, I want lib have "ERR  , DEBUG , COUT_..."belong to 
itself , they can display on same screen or sparated, or dump to file ,so 
it's may be need a window manager.
........
.......
.......

finally I lost my mind , my pool knowledge about ui design drive me crazy. 
reinvent the big wheel?

so I found "ncurses" and pin my hope on it , and after serval day's trying , 
almost there , but still have problem --- telnet can not display it 
correctly.... crazy again. ^_^

.......


As you see I am a "dabbler" now ,especially  no experience on C  :-) . may 
be afraid , may be just too lazy to study "tty" it self.


 now I am reading "Joe's Own Editor" , I  hope after another serval days , I 
can master it.


ps: I didn't found there's a c++ lib can do such things -----(pure code) a 
chartype  window manager ,support sub window ,with string to as display ,can 
adapter with basic IO . etc...
to wrote it is too expensive for me , if you know one , please tell me.









 


0
Reply key9 5/16/2006 8:20:06 PM

2 Replies
211 Views

(page loaded in 0.038 seconds)

Similiar Articles:

7/29/2012 3:18:02 AM


Reply: