In this post, I briefly introduce a newly added “alternate” scrolling mode for cli4clj, a library for easing the implementation of interactive command line interfaces (CLIs) for Clojure applications.
Since quite some time, I had been a bit unhappy about how repeated and asynchronous output is handled for CLIs implemented with cli4clj. The main cause of the problem is that, simply speaking, everything (commands, command output, completion hints, user input, etc.) is printed into the same shell. This causes the situation that repeatedly printed asynchronous output interferes with user input. Which ultimately causes the problem that the interactive CLI can become hardly usable or completely unusable. Below, an animated gif illustrates the problem.
To solve this situation, I added a first version of an “alternate” scrolling mode. The idea of the alternate scrolling mode is to split the shell into different areas:
- one for showing “scrolling” output
- one for entering and editing commands,
- and one for displaying completion hints and “special” output such as error messages.
Below an example of the alternate scrolling mode is shown.
The largest area at the top above the line is used for printing the “scrolling” output. Below the line, input can be entered at the usual prompt. Below the prompt, “special” output such as completion hints or errors are printed.
The alternate scroll mode can be enabled by setting the key “:alternate-scrolling” to “true” in the cli4clj options map. Alternatively, a predicate function returning a Boolean value can be set.
In addition, the height of the area underneath the prompt reserved for the special output can be adjusted by setting the “:alternate-height” key to a corresponding integer value.
You can try the alternate scrolling mode yourself in the example application by passing “alt” as argument, e.g., by starting it via Leiningen as follows: “lein run — alt”
With the alternate scrolling, I am mostly scratching my own itch. However, I hope that some of you will also have good use cases for the alternate scrolling mode. I would be very happy to hear if cli4clj is helpful for you or if you have constructive comments or feedback.