<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <link rel="stylesheet" href="../../coverage.css"/> <title> beowulf/reader/char_reader.clj </title> </head> <body> <span class="covered" title="1 out of 1 forms covered"> 001 (ns beowulf.reader.char-reader </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 002 "Provide sensible line editing, auto completion, and history recall. </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 003 </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 004 None of what's needed here is really working yet, and a pull request with </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 005 a working implementation would be greatly welcomed. </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 006 </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 007 ## What's needed (rough specification) </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 008 </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 009 1. Carriage return **does not** cause input to be returned, **unless** </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 010 a. the number of open brackets `(` and closing brackets `)` match; and </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 011 b. the number of open square brackets `[` and closing square brackets `]` also match; </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 012 2. <Ctrl-D> aborts editing and returns the string `STOP`; </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 013 3. <Up-arrow> and <down-arrow> scroll back and forward through history, but ideally I'd like </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 014 this to be the Lisp history (i.e. the history of S-Expressions actually read by `READ`, </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 015 rather than the strings which were supplied to `READ`); </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 016 4. <Tab> offers potential auto-completions taken from the value of `(OBLIST)`, ideally the </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 017 current value, not the value at the time the session started; </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 018 5. <Back-arrow> and <Forward-arrow> offer movement and editing within the line. </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 019 </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 020 TODO: There are multiple problems with JLine; a better solution might be </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 021 to start from here: </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 022 https://stackoverflow.com/questions/7931988/how-to-manipulate-control-characters" </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 023 ;; (:import [org.jline.reader LineReader LineReaderBuilder] </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 024 ;; [org.jline.terminal TerminalBuilder]) </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 025 ) </span><br/> <span class="blank" title="0 out of 0 forms covered"> 026 </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 027 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 028 ;;; </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 029 ;;; Copyright (C) 2022-2023 Simon Brooke </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 030 ;;; </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 031 ;;; This program is free software; you can redistribute it and/or </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 032 ;;; modify it under the terms of the GNU General Public License </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 033 ;;; as published by the Free Software Foundation; either version 2 </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 034 ;;; of the License, or (at your option) any later version. </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 035 ;;; </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 036 ;;; This program is distributed in the hope that it will be useful, </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 037 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 038 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 039 ;;; GNU General Public License for more details. </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 040 ;;; </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 041 ;;; You should have received a copy of the GNU General Public License </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 042 ;;; along with this program; if not, write to the Free Software </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 043 ;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 044 ;;; </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 045 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; </span><br/> <span class="blank" title="0 out of 0 forms covered"> 046 </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 047 ;; It looks from the example given [here](https://github.com/jline/jline3/blob/master/demo/src/main/java/org/jline/demo/Repl.java) </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 048 ;; as though JLine could be used to build a perfect line-reader for Beowulf; but it also </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 049 ;; looks as though you'd need a DPhil in JLine to write it, and I don't have </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 050 ;; the time. </span><br/> <span class="blank" title="0 out of 0 forms covered"> 051 </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 052 ;; (def get-reader </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 053 ;; "Return a reader, first constructing it if necessary. </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 054 </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 055 ;; **NOTE THAT** this is not settled API. The existence and call signature of </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 056 ;; this function is not guaranteed in future versions." </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 057 ;; (memoize (fn [] </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 058 ;; (let [term (.build (.system (TerminalBuilder/builder) true))] </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 059 ;; (.build (.terminal (LineReaderBuilder/builder) term)))))) </span><br/> <span class="blank" title="0 out of 0 forms covered"> 060 </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 061 ;; (defn read-chars </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 062 ;; "A drop-in replacement for `clojure.core/read-line`, except that line editing </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 063 ;; and history should be enabled. </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 064 </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 065 ;; **NOTE THAT** this does not work yet, but it is in the API because I hope </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 066 ;; that it will work later!" </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 067 ;; [] </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 068 ;; (let [eddie (get-reader)] </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 069 ;; (loop [s (.readLine eddie)] </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 070 ;; (if (and (= (count (re-seq #"\(" s)) </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 071 ;; (count (re-seq #"\)" s))) </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 072 ;; (= (count (re-seq #"\[]" s)) </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 073 ;; (count (re-seq #"\]" s)))) </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 074 ;; s </span><br/> <span class="not-tracked" title="0 out of 0 forms covered"> 075 ;; (recur (str s " " (.readLine eddie))))))) </span><br/> </body> </html>