Created
December 2, 2018 18:49
-
-
Save middlesphere/07a5d8dded9c405581e046352d2b9865 to your computer and use it in GitHub Desktop.
jline3 demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns jline3.demo | |
(:gen-class) | |
(:import (org.jline.terminal TerminalBuilder Terminal$SignalHandler Terminal) | |
(org.jline.reader LineReaderBuilder LineReader LineReader$Option) | |
(org.jline.reader.impl LineReaderImpl) | |
(org.jline.utils InfoCmp$Capability))) | |
(defn new-terminal | |
"creates new JLine3 Terminal. | |
returns terminal object" | |
^Terminal [term-name] | |
(let [terminal (-> (TerminalBuilder/builder) | |
(.system true) | |
(.name term-name) | |
(.encoding "UTF-8") | |
(.signalHandler (Terminal$SignalHandler/SIG_IGN)) | |
(.build))] | |
terminal)) | |
(defn new-line-reader | |
"creates new terminal line reader. | |
returns ^LineReader object." | |
^LineReader [terminal] | |
(let [line-reader (-> (LineReaderBuilder/builder) | |
(.terminal terminal) | |
(.build))] | |
line-reader)) | |
(defn -main | |
"entry point to program." | |
[& args] | |
(println "starting terminal...") | |
(let [t (new-terminal "jline demo") | |
prompt "prompt> " | |
lr (new-line-reader t) | |
continue? (atom true)] | |
(while @continue? | |
(let [line (.readLine lr prompt )] | |
(.redrawLine ^LineReaderImpl lr) | |
(when (= "quit" line) | |
(reset! continue? false)))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{:paths ["resources" "src"] | |
:extra-paths ["resources"] | |
:deps {org.clojure/clojure {:mvn/version "1.10.0-RC2"} | |
org.jline/jline {:mvn/version "3.9.0"}} | |
:aliases {:test {:extra-paths ["test"] | |
:extra-deps {org.clojure/test.check {:mvn/version "RELEASE"}}} | |
:build {:extra-deps {luchiniatwork/cambada {:mvn/version "1.0.0"}} | |
:main-opts ["--main" "cambada.uberjar" | |
"--main" "jline3.demo" | |
"--app-group-id" "com.middlesphere" | |
"--app-artifact-id" "jline3-demo" | |
"--app-version" "0.1" | |
"--aot" "jline3.demo" | |
"--no-copy-source"]} | |
:runner {:extra-deps {com.cognitect/test-runner | |
{:git/url "https://github.com/cognitect-labs/test-runner" | |
:sha "76568540e7f40268ad2b646110f237a60295fa3c"}} | |
:main-opts ["-m" "cognitect.test-runner" | |
"-d" "test"]}}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment