3 HISTORY_FILE
= paste(path
.expand("~"), "/.mal-history", sep
="")
5 library(rdyncall
, lib
.loc
="lib/")
7 #.rllib <- dynfind(c("edit"))
8 .rllib
<- dynfind(c("readline"))
9 .call_readline
<- .dynsym(.rllib
,"readline")
10 .call_add_history
<- .dynsym(.rllib
,"add_history")
13 .state$rl_history_loaded
= FALSE
15 .readline
<- function(prompt
) {
16 res
<- .dyncall(.call_readline
, "Z)p", prompt
)
17 if (is
.nullptr(res
)) {
24 readline
<- function(prompt
) {
25 if (!.state$rl_history_loaded
) {
26 .state$rl_history_loaded
<- TRUE
28 if (file
.access(HISTORY_FILE
, 4) == 0) {
29 lines
<- scan(HISTORY_FILE
, what
="", sep
="\n", quiet
=TRUE)
30 for(add_line
in lines
) {
31 .dyncall(.call_add_history
, "Z)v", add_line
)
36 line
<- .readline(prompt
)
37 if (is
.null(line
)) return(NULL)
38 .dyncall(.call_add_history
, "Z)v", line
)
39 if (file
.access(HISTORY_FILE
, 2) == 0) {
40 write(line
, file
=HISTORY_FILE
, append
=TRUE)