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,39 +1,52 @@
 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(line: &String, mode: &mut Mode) {
+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" => *mode = Mode::Input,
+        "a" => {
+            append_after(Range{start: *line_num, end: *line_num}, diff);
+        },
         "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 append_after(range: Range, diff: &mut diff::Diff) {
+    diff.add_lines(range.end+1, input());
 }
 
 fn main() {
-    let mut mode = Mode::Command;
+    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) {
@@ -43,9 +56,6 @@
                 continue
             },
         }
-        match mode {
-            Mode::Command => command_line(&line, &mut mode),
-            Mode::Input => input_line(&line, &mut mode),
-        }
+        command(&line, &mut line_num, &mut diff);
     }
 }
Simplify command parsing; Add input loop
