So Rust is the alternative to the Rubyunix code base. Both employ the same parser (Bash.rb), although Rust is more complete and has many useful and redeeming qualities. But this isn't about competing code bases.... yet....
So starting in the main file... rust.rb
--> rust.rb
rust.rb is the head of the shell. It starts off my loading all of the files (in a certain order, due to method dependencies). First the non-local dependencies, then the local ones. The Dir.glob() trick is very common in all of _why's code, and it loads all of the parsers located in the parser directory. For final release, I will change this so that it is ~/.parsers/ . The Rust class is the actually OOP head of the shell, as it organizes everything else to do its part. $keys is a hash that stores all of the user's captured keys. For instance, if you choose to capture ^A, you would be able to hit ^A, and then the attached proc would be called. <at> io is the InOut class, which handles all of the IO. The only reason for using that instead of HighLine is that HighLine calls a multitude of methods to getting user input, and on *nix systems, that is Readline. And in Readline, I can't twist it so that it will check for any captured keys. And besides, I stole the best of the functionality of HighLine and put it into InOut (like colored output!).
The run method loads the user's configuration file and eval's it in the context of CommandCenter. It's a pretty simple method.
The prompt method is also very straightforward. It just asks the user for input! The reason that it is 'line += ask($prompt)' is because I would like to check for backslashes and then just add the next line onto the previous one.
--> syntax/command.rb
Obsolete and unused. Don't even worry about it!
--> syntax/pipes.rb
pipes.rb is a seemingly long and complicated file, particularly since it is one method! But really, it's not that bad. It starts out by parsing the *args. That much is obvious. The rest of it is (mostly) taken from Open3.popen3(). It takes the pipe assignments from args, and then, in a new fork, reassigns the pipes and then runs the command according to the designated style, given to it by the parser. Pipes.pipe_to should be called _only_ by helpers/parser.rb::run() or run_standard(). Those methods are called by the parser.
--> syntax/paths.rb
Pretty much self evident. Just a few useful methods for finding files. Can be called by anyone.
--> helpers/array.rb
Contains one method: string(). It is called by CommandCenter when running any ruby-based code.
--> helpers/command_center.rb
command_center.rb has the methods for running any commands in the shell environment. It includes the BuiltinCommands module so that the builtin commands can be run.
--> helpers/constants.rb
Nothing much here. Just one constant used by io.rb. If there ever needs to be any constants stored, however, the should be stored here.
--> helpers/io.rb
Simple stuff here! Basic IO operations, plus some methods that should really get removed, as they are uneeded (silence, silenced? and speak).
--> helpers/parser.rb
Contains all methods that can be used as sugar for writing parsers. It needs to be advanced and made into a class!
--> helpers/rush_control.rb
rush_control.rb is an extension of CommandCenter, but it contains methods used in the config file. It is an extension of CommandCenter because I think you should be able to capture a new key and put it into effect without having to modify your config file and relaunch the shell.
--> helpers/trollop.rb
The modified trollop command parser that **can** be used by any builtin command to parse the args. See the trollop rubyforge page for examples in general usage, and then see my examples for integration.
--> commands/builtins.rb
Plain jane. Self explanatory. Take a look and you will know! It is there, because all internal commands must be registered:
register_builtin :cmd
and all replacement programs should be registered as:
register :cmd
Subtle, but please take care to note the differences! It also contains a Kernel addition that allows for inquiries into the arrays of commands.
I hope this has given you all some good insight into the Rust codebase. Really, though, it's not as complex as it seems.
_______________________________|
- Ari
I just bought another case of RockStar. Expect architectural changes.