jline / jline2

Jline 2.x
http://jline.github.com/jline2/
Other
713 stars 182 forks source link

Address #277: Allow setting max history-size for FileHistory. #278

Closed timmc closed 6 years ago

timmc commented 7 years ago

For #277. Two parts:

timmc commented 7 years ago

For reference, here's what the integration looks like from my working branch of a relying Clojure project:

(defn ^Integer default-history-size
  "Get default history size from system settings, or nil if not set.
Set `app-name` for jline's reading of inputrc, or null for default."
  [app-name]
  (try
    (-> (ConsoleKeys. app-name (ConsoleReader/getInputRc))
        (.getVariable "history-size")
        (Integer/parseInt))
    (catch IOException ioe
      (binding [*out* *err*]
        (println "Error retrieving history size for REPL-y:" ioe))
      nil)))

(defn configure-history
  "Configure a MemoryHistory or FileHistory's max-size, if non-nil."
  [hist size]
  (when size
    (.setMaxSize hist size)))

...
(doto (FileHistory. (make-history-file history-file) false)
  (configure-history (default-history-size))
  (.load))
...