Port input.cpp to input.rs

This is not yet adopted.
This commit is contained in:
ridiculousfish 2023-11-27 15:48:58 -08:00
parent 01b04c802e
commit 7ffb62d1d9
5 changed files with 1243 additions and 33 deletions

View file

@ -91,8 +91,8 @@ include_cpp! {
generate_pod!("escape_string_style_t") generate_pod!("escape_string_style_t")
generate!("reader_schedule_prompt_repaint") generate!("reader_schedule_prompt_repaint")
generate!("reader_reading_interrupted")
generate!("reader_change_history") generate!("reader_change_history")
generate!("reader_change_cursor_selection_mode") generate!("reader_change_cursor_selection_mode")
generate!("reader_set_autosuggestion_enabled_ffi") generate!("reader_set_autosuggestion_enabled_ffi")

File diff suppressed because it is too large Load diff

View file

@ -772,6 +772,11 @@ impl Parser {
&self.variables &self.variables
} }
/// Get the variables as an Arc.
pub fn vars_ref(&self) -> Arc<EnvStack> {
Pin::into_inner(Pin::clone(&self.variables))
}
/// Get the library data. /// Get the library data.
pub fn libdata(&self) -> Ref<'_, LibraryData> { pub fn libdata(&self) -> Ref<'_, LibraryData> {
self.library_data.borrow() self.library_data.borrow()

View file

@ -136,6 +136,10 @@ pub fn check_autosuggestion_enabled(vars: &dyn Environment) -> bool {
.unwrap_or(true) .unwrap_or(true)
} }
pub fn reader_reading_interrupted() -> i32 {
crate::ffi::reader_reading_interrupted().0
}
pub fn reader_schedule_prompt_repaint() { pub fn reader_schedule_prompt_repaint() {
crate::ffi::reader_schedule_prompt_repaint() crate::ffi::reader_schedule_prompt_repaint()
} }

View file

@ -815,36 +815,6 @@ static void test_autosuggestion_combining() {
do_test(combine_command_and_autosuggestion(L"alpha", L"ALPHA") == L"alpha"); do_test(combine_command_and_autosuggestion(L"alpha", L"ALPHA") == L"alpha");
} }
// todo!("port this")
static void test_input() {
say(L"Testing input");
inputter_t input{parser_principal_parser()->deref()};
// Ensure sequences are order independent. Here we add two bindings where the first is a prefix
// of the second, and then emit the second key list. The second binding should be invoked, not
// the first!
wcstring prefix_binding = L"qqqqqqqa";
wcstring desired_binding = prefix_binding + L'a';
{
auto input_mapping = input_mappings();
input_mapping->add(prefix_binding, L"up-line");
input_mapping->add(desired_binding, L"down-line");
}
// Push the desired binding to the queue.
for (wchar_t c : desired_binding) {
input.queue_char(c);
}
// Now test.
auto evt = input.read_char();
if (!evt.is_readline()) {
err(L"Event is not a readline");
} else if (evt.get_readline() != readline_cmd_t::down_line) {
err(L"Expected to read char down_line");
}
}
/// Helper for test_timezone_env_vars(). /// Helper for test_timezone_env_vars().
long return_timezone_hour(time_t tstamp, const wchar_t *timezone) { long return_timezone_hour(time_t tstamp, const wchar_t *timezone) {
env_stack_t vars{parser_principal_parser()->deref().vars_boxed()}; env_stack_t vars{parser_principal_parser()->deref().vars_boxed()};
@ -1053,7 +1023,6 @@ static const test_t s_tests[]{
{TEST_GROUP("iothread"), test_iothread}, {TEST_GROUP("iothread"), test_iothread},
{TEST_GROUP("lru"), test_lru}, {TEST_GROUP("lru"), test_lru},
{TEST_GROUP("colors"), test_colors}, {TEST_GROUP("colors"), test_colors},
{TEST_GROUP("input"), test_input},
{TEST_GROUP("completion_insertions"), test_completion_insertions}, {TEST_GROUP("completion_insertions"), test_completion_insertions},
{TEST_GROUP("maybe"), test_maybe}, {TEST_GROUP("maybe"), test_maybe},
{TEST_GROUP("normalize"), test_normalize_path}, {TEST_GROUP("normalize"), test_normalize_path},