diff --git a/chapter7/tui/src/bin/text-viewer1.rs b/chapter7/tui/src/bin/text-viewer1.rs index 6133322..f4f3b6f 100644 --- a/chapter7/tui/src/bin/text-viewer1.rs +++ b/chapter7/tui/src/bin/text-viewer1.rs @@ -104,6 +104,10 @@ impl TextViewer { fn main() { //Get arguments from command line let args: Vec = args().collect(); + if args.len() < 2 { + println!("Please provide file name as argument"); + std::process::exit(0); + } //Check if file exists. If not, print error message and exit process if !std::path::Path::new(&args[1]).exists() { println!("File does not exist"); diff --git a/chapter7/tui/src/bin/text-viewer2.rs b/chapter7/tui/src/bin/text-viewer2.rs index ca5e68b..3fee9c4 100644 --- a/chapter7/tui/src/bin/text-viewer2.rs +++ b/chapter7/tui/src/bin/text-viewer2.rs @@ -170,6 +170,10 @@ struct Coordinates { fn main() { //Get arguments from command line let args: Vec = args().collect(); + if args.len() < 2 { + println!("Please provide file name as argument"); + std::process::exit(0); + } //Check if file exists. If not, print error message and exit process if !std::path::Path::new(&args[1]).exists() { println!("File does not exist"); @@ -182,7 +186,7 @@ fn main() { println!("{}", termion::cursor::Goto(1, 1)); // Initialize editor let mut editor = TextViewer::init(&args[1]); - editor.show_document(); editor.set_pos(1, 1); + editor.show_document(); editor.run(); }