-(ns mash-commander.nix.story)
+(ns mash-commander.nix.story
+  (:require [clojure.string :as string]))
 
-(defn- eq [want then]
-  (fn [got _] (when (= want got) then)))
+(defn- if-line [want then]
+  (fn [got _] (when (= want (:line got)) then)))
+
+(defn- if-inotify-path [want then]
+  (fn [got _] (when (= want (reverse (:path got))) then)))
 
 (def pages
   {;; Debugging
    :page-0 {:when-events [{:type :new-line
-                           :then (eq {:type :new-line :line "ls"}
-                                     {:say "saw `ls` command"})
-                           :recur true}]}
+                           :then (if-line "ls" {:say "saw `ls` command"})
+                           :recur true}
+                          {:type :inotify
+                           :then (if-inotify-path ["usr" "key"] {:say "key touched"})}]}
    ;; Learning `ls` and typing commands.
    :page-1 {:allow []
             :say "Hi, I'm Nix."

                   :then {
                          :allow ["ls"]
                          :wait-event {:type :new-line
                                       :then (eq {:type :new-line :line "ls"}
                                                 {:goto :page-2})}}}}
   :page-2 {:allow []
            :say "Good job! The results of your command are shown underneath in the grey box."
            :goto :page-3}

            :then {:say "Try changing into the `bin` directory by typing `cd bin`."
                   :then {:allow ["cd bin"]
                          :wait-event {:type :new-line
                                       :then (if-line "cd bin" {:goto :page-4})}}}}
   :page-4 {:allow []
            :say "Nice! Now your current directory is `bin`."
            :then {:say "Notice the green nix: command prompt changed to tell you where you are."
