mod diff;

use std::io;

struct Range {
    start: i32,
    end: i32,
}

fn input() -> Vec<String> {
    let mut lines: Vec<String> = Vec::new();
    loop {
        let mut line = String::new();
        io::stdin().read_line(&mut line)
            .ok()
            .expect("Error reading line");
        match line.trim() {
            "." => {
                break
            },
            _ => {
                lines.push(line)
            }
        }
    }
    return lines;
}

fn command(line: &String, line_num: &mut i32, diff: &mut diff::Diff) {
    // parse the command line to get
    // Line num or range
    // command
    match line.trim() {
        "a" => {
            append_after(Range{start: *line_num, end: *line_num}, diff);
        },
        "q" => std::process::exit(0),
        _ => println!("Command: {}", line),
    }
}

fn append_after(range: Range, diff: &mut diff::Diff) {
    diff.add_lines(range.end+1, input());
}

fn main() {
    let prompt = ":";
    let mut diff = diff::Diff::new();
    let mut line_num: i32 = 1;
    loop {
        let mut line = String::new();
        match io::stdin().read_line(&mut line) {
            Ok(_) => (),
            Err(_) => {
                println!("?");
                continue
            },
        }
        command(&line, &mut line_num, &mut diff);
    }
}

mod diff;

use std::io;

enum Mode {
    Command,
    Input,
}

struct Range {
    start: i32,
    end: i32,
}


fn command_line(line: &String, mode: &mut Mode) {
    match line.trim() {
        "a" => *mode = Mode::Input,
        "q" => std::process::exit(0),
        _ => println!("Command: {}", line),
    }
}

fn input_line(line: &String, mode: &mut Mode) {
    match line.trim() {
        "." => *mode = Mode::Command,
        _ => println!("Input: {}", line),
    }
}

fn append_after(lines: Vec<String>, range: Range, diff: &mut diff::Diff) {
    diff.add_lines(range.start, lines);
}

fn main() {
    let mut mode = Mode::Command;
    loop {
        let mut line = String::new();
        match io::stdin().read_line(&mut line) {
            Ok(_) => (),
            Err(_) => {
                println!("?");
                continue
            },
        }
        match mode {
            Mode::Command => command_line(&line, &mut mode),
            Mode::Input => input_line(&line, &mut mode),
        }
    }
}

--- 
+++ 
@@ -1,52 +1,39 @@
 mod diff;
 
 use std::io;
+
+enum Mode {
+    Command,
+    Input,
+}
 
 struct Range {
     start: i32,
     end: i32,
 }
 
-fn input() -> Vec<String> {
-    let mut lines: Vec<String> = Vec::new();
-    loop {
-        let mut line = String::new();
-        io::stdin().read_line(&mut line)
-            .ok()
-            .expect("Error reading line");
-        match line.trim() {
-            "." => {
-                break
-            },
-            _ => {
-                lines.push(line)
-            }
-        }
-    }
-    return lines;
-}
 
-fn command(line: &String, line_num: &mut i32, diff: &mut diff::Diff) {
-    // parse the command line to get
-    // Line num or range
-    // command
+fn command_line(line: &String, mode: &mut Mode) {
     match line.trim() {
-        "a" => {
-            append_after(Range{start: *line_num, end: *line_num}, diff);
-        },
+        "a" => *mode = Mode::Input,
         "q" => std::process::exit(0),
         _ => println!("Command: {}", line),
     }
 }
 
-fn append_after(range: Range, diff: &mut diff::Diff) {
-    diff.add_lines(range.end+1, input());
+fn input_line(line: &String, mode: &mut Mode) {
+    match line.trim() {
+        "." => *mode = Mode::Command,
+        _ => println!("Input: {}", line),
+    }
+}
+
+fn append_after(lines: Vec<String>, range: Range, diff: &mut diff::Diff) {
+    diff.add_lines(range.start, lines);
 }
 
 fn main() {
-    let prompt = ":";
-    let mut diff = diff::Diff::new();
-    let mut line_num: i32 = 1;
+    let mut mode = Mode::Command;
     loop {
         let mut line = String::new();
         match io::stdin().read_line(&mut line) {
@@ -56,6 +43,9 @@
                 continue
             },
         }
-        command(&line, &mut line_num, &mut diff);
+        match mode {
+            Mode::Command => command_line(&line, &mut mode),
+            Mode::Input => input_line(&line, &mut mode),
+        }
     }
 }
Simplify command parsing; Add input loop
