nvim_oxi_api/opts/
open_term.rs

1use crate::Buffer;
2use crate::ToFunction;
3
4/// Arguments passed to the callback registered to
5/// [`on_input`](OpenTermOptsBuilder::on_input). The `(a, b, c, d)` tuple
6/// represents:
7///
8/// - `a`: the string literal `"input"`;
9/// - `b`: channel id;
10/// - `c`: the [`Buffer`] associated to the terminal instance;
11/// - `d`: data input.
12pub type OnInputArgs = (
13    String,        // the string literal `"input"`
14    u32,           // channel_id
15    Buffer,        // buffer
16    types::String, // data input
17);
18
19/// Options passed to [`open_term()`](crate::open_term).
20#[derive(Clone, Debug, Default, macros::OptsBuilder)]
21#[repr(C)]
22pub struct OpenTermOpts {
23    #[cfg(feature = "neovim-0-10")] // On 0.10 and nightly.
24    #[builder(mask)]
25    mask: u64,
26
27    #[cfg(not(feature = "neovim-0-10"))] // 0nly on 0.9.
28    #[builder(
29        generics = "F: ToFunction<OnInputArgs, ()>",
30        argtype = "F",
31        inline = "types::Object::from_luaref({0}.into_luaref())"
32    )]
33    /// Callback invoked on data input (like keypresses in terminal mode).
34    on_input: types::Object,
35
36    #[cfg(feature = "neovim-0-10")] // On 0.10 and nightly.
37    #[builder(
38        generics = "F: ToFunction<OnInputArgs, ()>",
39        argtype = "F",
40        inline = "{0}.into_luaref()"
41    )]
42    /// Callback invoked on data input (like keypresses in terminal mode).
43    on_input: types::LuaRef,
44}
45
46#[cfg(not(feature = "neovim-0-10"))] // 0nly on 0.9.
47impl From<&OpenTermOpts> for types::Dictionary {
48    fn from(opts: &OpenTermOpts) -> Self {
49        Self::from_iter([("on_input", opts.on_input.clone())])
50    }
51}