diff --git a/fish-rust/src/lib.rs b/fish-rust/src/lib.rs index 74a68d00a..c98b0b4ee 100644 --- a/fish-rust/src/lib.rs +++ b/fish-rust/src/lib.rs @@ -44,12 +44,14 @@ mod locale; mod nix; mod null_terminated_array; mod operation_context; +mod output; mod parse_constants; mod parse_tree; mod parse_util; mod parser_keywords; mod path; mod re; +mod reader; mod redirection; mod signal; mod smoke; diff --git a/fish-rust/src/output.rs b/fish-rust/src/output.rs new file mode 100644 index 000000000..8f76c92f7 --- /dev/null +++ b/fish-rust/src/output.rs @@ -0,0 +1,19 @@ +use bitflags::bitflags; + +bitflags! { + pub struct ColorSupport: u8 { + const NONE = 0; + const TERM_256COLOR = 1<<0; + const TERM_24BIT = 1<<1; + } +} + +pub fn output_set_color_support(value: ColorSupport) { + extern "C" { + pub fn output_set_color_support(value: libc::c_int); + } + + unsafe { + output_set_color_support(value.bits() as i32); + } +} diff --git a/fish-rust/src/reader.rs b/fish-rust/src/reader.rs new file mode 100644 index 000000000..15ea8ac07 --- /dev/null +++ b/fish-rust/src/reader.rs @@ -0,0 +1,15 @@ +use crate::env::Environment; +use crate::wchar::L; + +#[repr(u8)] +pub enum CursorSelectionMode { + Exclusive = 0, + Inclusive = 1, +} + +pub fn check_autosuggestion_enabled(vars: &dyn Environment) -> bool { + vars.get(L!("fish_autosuggestion_enabled")) + .map(|v| v.as_string()) + .map(|v| v != L!("0")) + .unwrap_or(true) +} diff --git a/src/output.cpp b/src/output.cpp index da0ff8f99..bc494c2e6 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -41,9 +41,10 @@ static bool term_supports_color_natively(unsigned int c) { return static_cast(max_colors) >= c + 1; } -color_support_t output_get_color_support() { return color_support; } - -void output_set_color_support(color_support_t val) { color_support = val; } +extern "C" { + void output_set_color_support(color_support_t val) { color_support = val; } + color_support_t output_get_color_support() { return color_support; } +} unsigned char index_for_color(rgb_color_t c) { if (c.is_named() || !(output_get_color_support() & color_support_term256)) { diff --git a/src/output.h b/src/output.h index 2b786c31c..4aee22e6e 100644 --- a/src/output.h +++ b/src/output.h @@ -127,8 +127,10 @@ rgb_color_t parse_color(const env_var_t &var, bool is_background); /// Sets what colors are supported. enum { color_support_term256 = 1 << 0, color_support_term24bit = 1 << 1 }; using color_support_t = unsigned int; -color_support_t output_get_color_support(); -void output_set_color_support(color_support_t val); +extern "C" { + color_support_t output_get_color_support(); + void output_set_color_support(color_support_t val); +} rgb_color_t best_color(const std::vector &candidates, color_support_t support); diff --git a/src/reader.cpp b/src/reader.cpp index 0e25a45f6..436acff89 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -2922,6 +2922,10 @@ void reader_change_cursor_selection_mode(cursor_selection_mode_t selection_mode) } } +void reader_change_cursor_selection_mode(uint8_t selection_mode) { + reader_change_cursor_selection_mode((cursor_selection_mode_t) selection_mode); +} + static bool check_autosuggestion_enabled(const env_stack_t &vars) { if (auto val = vars.get(L"fish_autosuggestion_enabled")) { return val->as_string() != L"0"; @@ -2942,6 +2946,18 @@ void reader_set_autosuggestion_enabled(const env_stack_t &vars) { } } +void reader_set_autosuggestion_enabled_ffi(bool enable) { + // We don't need to _change_ if we're not initialized yet. + reader_data_t *data = current_data_or_null(); + if (data) { + if (data->conf.autosuggest_ok != enable) { + data->conf.autosuggest_ok = enable; + data->force_exec_prompt_and_repaint = true; + data->inputter.queue_char(readline_cmd_t::repaint); + } + } +} + /// Add a new reader to the reader stack. /// \return a shared pointer to it. static std::shared_ptr reader_push_ret(parser_t &parser, diff --git a/src/reader.h b/src/reader.h index 4d282be28..9adc8467d 100644 --- a/src/reader.h +++ b/src/reader.h @@ -168,11 +168,17 @@ enum class cursor_selection_mode_t : uint8_t { inclusive, }; +#if INCLUDE_RUST_HEADERS void reader_change_cursor_selection_mode(cursor_selection_mode_t selection_mode); +#else +void reader_change_cursor_selection_mode(uint8_t selection_mode); +#endif /// Enable or disable autosuggestions based on the associated variable. void reader_set_autosuggestion_enabled(const env_stack_t &vars); +void reader_set_autosuggestion_enabled_ffi(bool); + /// Write the title to the titlebar. This function is called just before a new application starts /// executing and just after it finishes. /// diff --git a/src/screen.cpp b/src/screen.cpp index 79c45fd29..afb5eb08f 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -63,6 +63,10 @@ class scoped_buffer_t : noncopyable_t, nonmovable_t { // Note this is deliberately exported so that init_curses can clear it. layout_cache_t layout_cache_t::shared; +void screen_clear_layout_cache_ffi() { + layout_cache_t::shared.clear(); +} + /// Tests if the specified narrow character sequence is present at the specified position of the /// specified wide character string. All of \c seq must match, but str may be longer than seq. static size_t try_sequence(const char *seq, const wchar_t *str) { diff --git a/src/screen.h b/src/screen.h index 4c667baa6..d215fa4da 100644 --- a/src/screen.h +++ b/src/screen.h @@ -244,6 +244,8 @@ class screen_t { /// Issues an immediate clr_eos. void screen_force_clear_to_end(); +void screen_clear_layout_cache_ffi(); + // Information about the layout of a prompt. struct prompt_layout_t { std::vector line_breaks; // line breaks when rendering the prompt