Creating a Phoronix Module
Now that we have a number of Phoronix-specific libraries, it's about time we organized and collected them into a single Phoronix
module. We currently have these files specific to Phoronix:
- article.rs
- homepage.rs
- phoronix_cli.rs
- phoronix_gui.rs
The names will be changed as such:
article.rs -> article.rs
homepage.rs -> homepage.rs
phoronix_cli.rs -> cli.rs
phoronix_gui.rs -> gui.rs
We are going to move them into a new directory, called phoronix
, and import them into main.rs.
/src
/phoronix
- article.rs
- cli.rs
- gui.rs
- homepage.rs
- phoronix.html
linesplit.rs
- main.rs
Inside our our main.rs file, change your mod lines to this:
mod phoronix {
pub mod article;
pub mod cli;
pub mod gui;
pub mod homepage;
}
And then update the calls in your source code to reflect these changes, such as changing references to use article::Article
to use phoronix::article::Article
and phoronix_gui::launch()
to phoronix::gui::launch()
.
main.rs
extern crate hyper;
extern crate select;
extern crate term;
extern crate getopts;
extern crate gtk;
extern crate gdk;
extern crate pango;
mod phoronix {
pub mod article;
pub mod homepage;
pub mod cli;
pub mod gui;
}
mod linesplit;
use phoronix::cli;
fn main() {
let args: Vec<String> = std::env::args().collect();
let mut opts = getopts::Options::new();
opts.optflag("n", "no-color", "prints without colors");
opts.optflag("h", "help", "show this information");
opts.optflag("g", "gui", "display in a GTK3 GUI");
let matches = opts.parse(&args[1..]).unwrap();
if matches.opt_present("h") { print_help(); return; }
match matches.opt_present("g") {
true => phoronix::gui::launch(),
false => if matches.opt_present("n") { cli::print(); } else { cli::print_colored(); },
};
}
fn print_help() {
println!("Prints the latest information from Phoronix.");
println!(" -h, --help : show this information");
println!(" -g, --gui : launches a GTK3 GUI instead of outputting to the terminal");
println!(" -n, --no-color : prints to stdout without using colors");
}