I recently wanted to write a bit of interactive shell and to my dismay discovered that apparently no one in the wide clojure community has yet wrapped up the JLine library. What a shame!
So I have knocked up something as best as I could. The result is available under on GitHub: http://github.com/tuor713/uwh-clojure-common.
Example usage:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use 'uwh.common.jline) | |
(use '[clojure.contrib.io :only (file read-lines)]) | |
(def processor (atom identity)) | |
(defn nil-safe [f] #(if (nil? %) % (f %))) | |
(defn add! [f] (swap! processor #(comp (nil-safe f) %))) | |
(run | |
(commands | |
(transform [f :file] | |
(doall (map (comp (nil-safe println) @processor) | |
(read-lines (file f))))) | |
(reset [] (reset! processor identity)) | |
(include [re :any] | |
(add! #(if (.matches % (str ".*" re ".*")) | |
% nil))) | |
(exclude [re :any] | |
(add! #(if (.matches % (str ".*" re ".*")) | |
nil %))) | |
(replace [re :any s :any] | |
(add! #(.replaceAll % re s))) | |
(exit [] (reset! *exit* true)))) | |
No comments:
Post a Comment