How do I build a basic Terminal from scratch
I've looked online including on stackoverflow for some suggestions or pointers but anything I have found is overwhelming and I'm unsure where to start. Apologizes if I have overlooked something obvious.
I want to learn how a Terminal works and I would like to build one from scratch, I would love any advice or suggestions on material that covers the concepts and functionality required in a terminal but I don't just want links to source code. I have found plenty of open source projects but I find them overwhelming.
I would Ideally like to build my own terminal that can run on OS X, Linux and/or windows (I would probably use Java but would consider other languages) and eventually have a web interface ( would like to have my console in my browser ) I know this has been done but I want to do it myself so I can understand in detail how it works and Just to have a project to do.
What I'm really looking for is a starting point with reading material/tutorials to give me some direction. If it means taking a step back to something even more basic then a Terminal, I am happy to do that once I have something to actually program that will keep me progressing toward the main aim
The idea behind a terminal is an infinite loop which interprets and execute every command. Here is an example in Perl:
use strict;
use warnings;
while(<>) {
system($_);
}
exit 0;
I know Perl isn't the most simple language to read (but surely it was the fastest to write), but this is all you need to understand the above program:
<>
reads from standard input.
system($_)
execute the command (where $_
is a special Perl variable which works inside loops and represent the currently evaluated item, so, in our case, the given command).
You can try to run the above program saving it on your computer as foo.pl
, open a terminal and execute perl foo.pl
.
So, this is the basic idea. I think every language implements a command system
which does the same (the name may change, but it's likely to be the same as well). You can have a look to man system
to find out how this command works in C
. I don't know Java, but I'm quite sure you have to search for something similar. From this starting point, I think you can start to build your own terminal.
Create a socket connection to the target computer, [read from it if any, display], [wait for user input, display, send that to the socket], repeat. You've got the basic terminal.
链接地址: http://www.djcxy.com/p/12408.html下一篇: 我如何从头开始构建基本的终端