readline/readline: add readline-newline' and
readline-redisplay'
mzrl.rkt: Add and provide readline-newline and readline-readisplay. readline.scrbl: Documentation and example code.
This commit is contained in:
parent
5134bc0888
commit
0f6a5833fc
|
@ -4,7 +4,8 @@
|
|||
(provide readline readline-bytes
|
||||
add-history add-history-bytes
|
||||
history-length history-get history-delete
|
||||
set-completion-function!)
|
||||
set-completion-function!
|
||||
readline-newline readline-redisplay)
|
||||
|
||||
;; libtermcap needed on some platforms
|
||||
(define libtermcap (with-handlers ([exn:fail? void]) (ffi-lib "libtermcap")))
|
||||
|
@ -117,3 +118,14 @@
|
|||
;; make it possible to run Scheme threads while waiting for input
|
||||
(set-ffi-obj! "rl_event_hook" libreadline (_fun -> _int)
|
||||
(lambda () (sync/enable-break real-input-port) 0))
|
||||
|
||||
|
||||
;; force cursor on a new line
|
||||
(define readline-newline
|
||||
(get-ffi-obj "rl_crlf" libreadline (_fun -> _void)
|
||||
(lambda ()
|
||||
(get-ffi-obj "rl_newline" libreadline (_fun -> _void)))))
|
||||
|
||||
;; force redisplay of prompt and current user input
|
||||
(define readline-redisplay
|
||||
(get-ffi-obj "rl_forced_update_display" libreadline (_fun -> _void)))
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
readline/pread
|
||||
readline/readline
|
||||
racket/contract
|
||||
ffi/unsafe/atomic
|
||||
(except-in ffi/unsafe ->)))
|
||||
|
||||
@(define readline "Readline")
|
||||
|
@ -240,6 +241,32 @@ Sets @|readline|'s @tt{rl_completion_entry_function} to
|
|||
from @racketmodname[ffi/unsafe], determines the type of value supplied
|
||||
to the @racket[proc].}
|
||||
|
||||
@defproc[(readline-newline) void?]{
|
||||
|
||||
Sets the cursor to the start of a new line.}
|
||||
|
||||
|
||||
@defproc[(readline-redisplay) void?]{
|
||||
|
||||
Forces a redisplay of the @|readline| prompt and current user input.
|
||||
|
||||
The @racket[readline-redisplay] function can be used together with
|
||||
@racket[readline-newline] to prevent a background thread from
|
||||
cluttering up the user input by interleaving its output. For example,
|
||||
an unsafe wrapper function for the thread's output might look like the
|
||||
following:
|
||||
|
||||
@racketblock[
|
||||
(define (with-thread-safe-output output-thunk)
|
||||
(dynamic-wind
|
||||
(lambda ()
|
||||
(start-atomic)
|
||||
(readline-newline))
|
||||
output-thunk
|
||||
(lambda ()
|
||||
(readline-redisplay)
|
||||
(end-atomic))))]}
|
||||
|
||||
|
||||
@section[#:tag "readline-license"]{License Issues}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user