Skip to content

Latest commit

 

History

History
60 lines (40 loc) · 2.11 KB

File metadata and controls

60 lines (40 loc) · 2.11 KB

Prompts

The :prompt config key names a zero-arg function with a qualified symbol:

;; .cljconf/org.clojure/clojure-cli.repl.edn
{:prompt dev.prompt/prompt}

The function lives in the config directory's src and is called by the client before each input line. The function should return the prompt as a vector of segments.

Segments

A segment is a map of :text and an optional :style:

(ns dev.prompt
  (:require [clojure-cli.repl.api :as api]))

(defn prompt []
  [{:text @api/current-ns :style {:fg :blue :bold true}}
   {:text " => "}])

Style keys: :fg, :bg, :bold, :italic, :underline, and :inverse. Colors: :black, :red, :green, :yellow, :blue, :magenta, :cyan, :white, and their :bright-* variants or an xterm 256 value (0-255).

A {:text "\n"} segment starts a new line and can be used to create multi-line prompts.

REPL state

clojure-cli.repl.api holds client state a prompt can read:

  • current-ns: An atom holding the name of the current namespace
  • last-response: An atom holding the last eval's nREPL response. An :ex key is present if the eval threw an error.
  • terminal-width: The current terminal column width.

The rest of the api namespace is documented with keybindings.

Server data

To isolate dependencies, the prompt runs in a separate process from where code is evaluated. Middleware is required to add server data to the prompt.

Example

Two-line full-width prompt with labeled segments

The example config has a full-width prompt that demonstrates using the api namespace and middleware to supply the time of the last eval and the server heap.

Copy the example dir into a project, or ~/.clojure for user level installation:

git clone https://github.com/clojure/clojure-cli.repl.git
cp -R clojure-cli.repl/examples/.cljconf .
clojure -M:repl