]> gitweb.factorcode.org Git - factor.git/blob - extra/readline/readline.factor
Raw FFI bindings to libreadline and a few higher level words
[factor.git] / extra / readline / readline.factor
1 ! Copyright (C) 2011 Erik Charlebois.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: alien.strings destructors io.encodings.utf8 kernel libc
4 sequences macros quotations words compiler.units fry
5 alien.data ;
6 QUALIFIED: readline.ffi
7 IN: readline
8
9 : readline ( prompt -- str )
10     [
11         readline.ffi:readline [
12             |free utf8 alien>string [
13                 [ ] [ readline.ffi:add_history ] if-empty
14             ] keep
15         ] [ f ] if*
16     ] with-destructors ;
17
18 MACRO: set-completion ( quot -- )
19     [
20        '[ @ [ utf8 malloc-string ] [ f ] if* ]
21        '[ _ readline.ffi:rl_compentry_func_t ]
22         (( -- alien )) define-temp
23     ] with-compilation-unit execute
24     '[ _ readline.ffi:set-rl_completion_entry_function ] ;