~severeoverfl0w/wedge-mise

ref: 670720d43c24495284dcce1db98cdd4269109b6e wedge-mise/src/io/dominic/wedge/mise/rebel/impl.clj -rw-r--r-- 1.8 KiB
670720d4 — Dominic Monroe Add nREPL support 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
(require
  '[fipp.edn :as fipp]
  '[io.dominic.wedge.mise :as mise]
  'rebel-readline.clojure.main
  'rebel-readline.core
  '[rebel-readline.jline-api :as api]
  '[rebel-readline.clojure.line-reader :as clj-line-reader])

(defn syntax-highlight-fipp
  "Print a syntax highlighted clojure value.

  This printer respects the current color settings set in the
  service.

  The `rebel-readline.jline-api/*line-reader*` and
  `rebel-readline.jline-api/*service*` dynamic vars have to be set for
  this to work."
  [x]
  (binding [*out* (.. api/*line-reader* getTerminal writer)]
    (try
      (print (api/->ansi
               (clj-line-reader/highlight-clj-str
                 (with-out-str (fipp/pprint x)))))
      (catch java.lang.StackOverflowError _
        (try
          (fipp/pprint x)
          ;; Just in case of
          ;; https://github.com/brandonbloom/fipp/issues/28
          (catch java.lang.StackOverflowError _
            (prn x)))))))

(defn- main*
  []
  (alter-var-root #'clj-line-reader/default-config
                  update-in
                  [:key-bindings :emacs]
                  (fnil conj [])
                  ;; These are the enter key, and forces acceptance.  This is
                  ;; easier for beginners, can be overriden in user-config.
                  [(org.jline.keymap.KeyMap/translate "^M") :clojure-force-accept-line]
                  [(org.jline.keymap.KeyMap/translate "^J") :clojure-force-accept-line])
  (rebel-readline.core/ensure-terminal
    (rebel-readline.clojure.main/repl
      :init (fn []
              (mise/print-usage)
              (println "\n    For Rebel help type :repl/help\n    To change colour theme use :repl/set-color-theme :light-screen-theme"))
      :print syntax-highlight-fipp)
    ;; When the REPL stops, stop:
    (System/exit 0)))