add history-expand and its test cases
This commit is contained in:
parent
d3acad378c
commit
114d4b5163
|
@ -232,6 +232,21 @@ pic_rl_truncate_file(pic_state *pic)
|
||||||
return pic_undef_value();
|
return pic_undef_value();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static pic_value
|
||||||
|
pic_rl_history_expand(pic_state *pic)
|
||||||
|
{
|
||||||
|
char *input, *result;
|
||||||
|
int status;
|
||||||
|
|
||||||
|
pic_get_args(pic, "z", &input);
|
||||||
|
|
||||||
|
status = history_expand(input, &result);
|
||||||
|
if(status == -1 || status == 2)
|
||||||
|
pic_errorf(pic, "%s\n", result);
|
||||||
|
|
||||||
|
return pic_obj_value(pic_str_new_cstr(pic, result));
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
pic_init_readline(pic_state *pic){
|
pic_init_readline(pic_state *pic){
|
||||||
using_history();
|
using_history();
|
||||||
|
@ -258,5 +273,6 @@ pic_init_readline(pic_state *pic){
|
||||||
pic_defun(pic, "read-history", pic_rl_read_history);
|
pic_defun(pic, "read-history", pic_rl_read_history);
|
||||||
pic_defun(pic, "write-history", pic_rl_write_history);
|
pic_defun(pic, "write-history", pic_rl_write_history);
|
||||||
pic_defun(pic, "truncate-file", pic_rl_truncate_file);
|
pic_defun(pic, "truncate-file", pic_rl_truncate_file);
|
||||||
|
pic_defun(pic, "history-expand", pic_rl_history_expand);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -324,5 +324,16 @@ pos 1
|
||||||
(truncate-file testfile 5)
|
(truncate-file testfile 5)
|
||||||
;(read-history testfile)
|
;(read-history testfile)
|
||||||
(test 5 (history-length))
|
(test 5 (history-length))
|
||||||
|
(clear-history)
|
||||||
|
(add-history "foo")
|
||||||
|
(add-history "bar")
|
||||||
|
(add-history "baz")
|
||||||
|
(test "baz" (history-expand "!b"))
|
||||||
|
(test "baz" (history-expand "!!"))
|
||||||
|
(test "bar" (history-expand "!?r?"))
|
||||||
|
(add-history "com arg")
|
||||||
|
(test "arg" (history-expand "!!:$"))
|
||||||
|
(test "arg" (history-expand "!$"))
|
||||||
|
(test "command arg" (history-expand "!!:s/com/command/"))
|
||||||
|
|
||||||
(test-end)
|
(test-end)
|
||||||
|
|
Loading…
Reference in New Issue