Skip to content

Commit

Permalink
Address trptcolin#166: Set history file max size from inputrc via JLine
Browse files Browse the repository at this point in the history
  • Loading branch information
timmc-bcov committed Jul 16, 2018
1 parent 1e55b56 commit 195b5ce
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,21 @@
# REPLy Changelog

## Unreleased
- #166: Set history file max size from inputrc
- Use newer jline2 to support history max size config

## 0.4.0

## 0.3.10

## 0.3.8

## 0.3.7

## 0.3.6

## 0.3.5

## 0.3.4 (there was no 0.3.3), 2014-08-06
- Exclude nrepl from drawbridge dependency

Expand Down
2 changes: 1 addition & 1 deletion project.clj
Expand Up @@ -4,7 +4,7 @@
(defproject reply "0.4.1-SNAPSHOT"
:description "REPL-y: A fitter, happier, more productive REPL for Clojure."
:dependencies [[org.clojure/clojure "1.6.0"]
[jline "2.14.5"]
[jline "2.14.6"]
[org.thnetos/cd-client "0.3.6"]
[clj-stacktrace "0.2.7"]
[nrepl "0.4.1"]
Expand Down
28 changes: 25 additions & 3 deletions src/clj/reply/reader/simple_jline.clj
Expand Up @@ -2,7 +2,7 @@
(:require [reply.reader.jline.completion :as jline.completion])
(:import [java.io File FileInputStream FileDescriptor
PrintStream ByteArrayOutputStream IOException]
[jline.console ConsoleReader]
[jline.console ConsoleReader ConsoleKeys]
[jline.console.history FileHistory MemoryHistory]
[jline.internal Configuration Log]))

Expand Down Expand Up @@ -68,6 +68,24 @@
(when-let [completer (first (.getCompleters reader))]
(.removeCompleter reader completer))))

(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."
[^String app-name]
(try
(-> (ConsoleKeys. app-name (ConsoleReader/getInputRc))
(.getVariable "history-size")
(Integer/parseInt))
(catch IOException ioe
nil)))

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

(defn setup-console-reader
[{:keys [prompt-string reader input-stream output-stream
history-file completer-factory blink-parens]
Expand All @@ -77,12 +95,16 @@
blink-parens true}
:as state}]
(let [reader (ConsoleReader. input-stream output-stream)
file-history (FileHistory. (make-history-file history-file))
hist-size (default-history-size nil) ;; currently null appName
file-history (doto (FileHistory. (make-history-file history-file) false)
(configure-history hist-size)
(.load))
history (try
(flush-history file-history)
file-history
(catch IOException e
(MemoryHistory.)))
(doto (MemoryHistory.)
(configure-history hist-size))))
completer (if completer-factory
(completer-factory reader)
nil)]
Expand Down

0 comments on commit 195b5ce

Please sign in to comment.