]> gitweb.factorcode.org Git - factor.git/commitdiff
readline: adding a with-history combinator.
authorJohn Benediktsson <mrjbq7@gmail.com>
Tue, 5 Dec 2023 20:28:33 +0000 (12:28 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Tue, 5 Dec 2023 20:28:33 +0000 (12:28 -0800)
extra/readline/readline.factor

index 784e43dabae0da9e24734d5a4000c7b7425afd03..0d5f1c592807fd179c858c4e855d0d48903aaf76 100644 (file)
@@ -1,7 +1,8 @@
 ! Copyright (C) 2011 Erik Charlebois.
 ! See https://factorcode.org/license.txt for BSD license.
 USING: alien.data alien.libraries alien.strings compiler.units
-destructors io.encodings.utf8 kernel libc sequences words ;
+continuations destructors io.encodings.utf8 kernel libc
+sequences words ;
 QUALIFIED: readline.ffi
 IN: readline
 
@@ -31,3 +32,7 @@ IN: readline
         ] ( -- alien ) define-temp
     ] with-compilation-unit execute( -- alien )
     readline.ffi:set-rl_completion_entry_function ;
+
+:: with-history ( path quot -- )
+    path readline.ffi:read_history io-error
+    quot [ path readline.ffi:write_history io-error ] finally ; inline