tmux-interface-rs icon indicating copy to clipboard operation
tmux-interface-rs copied to clipboard

Globality must be specified before option name in SessionOptions

Open ypoluektovich opened this issue 3 years ago • 4 comments

https://github.com/AntonGepting/tmux-interface-rs/blob/aab389358dc1b1f936ed58f040ab3b38c71e8f91/src/options/session_options.rs#L1307

Otherwise it doesn't work. Tested on tmux 3.2a.

ypoluektovich avatar Aug 06 '21 17:08 ypoluektovich

Thank you.

fixed, published 0.2.1

AntonGepting avatar Aug 07 '21 15:08 AntonGepting

new mechanisms proposed in v0.3.0

options control

    let gl_session_options_ctl = GlobalSessionOptionsCtl::default();

    let session_options = gl_session_options_ctl.get_all();
    dbg!(session_options);

    let base_index = gl_session_options_ctl.get_base_index();
    dbg!(base_index);

or just building command for getting options for custom purposes

    let cmd = GetGlobalSessionOption::base_index(Some("my_session"));
    dbg!(cmd);

in the same way library can be used for window, pane, server options (with globality for session and window)

AntonGepting avatar May 31 '23 15:05 AntonGepting

After migrating to this new mechanism, I can say that it needs some documentation for discoverability :)

(Update: I found the documentation! It's in the Rust docs on the module level.)

A minor issue: this is what I ended up writing:

let get_default_shell = GetGlobalSessionOptionValue::default_shell::<&'static str>(None);

Note the explicit typing. I don't have a target for this command, so I have to specify None, but then Rust can't auto-resolve the generic type. Not sure if it can be "fixed", or if it even needs fixing.

ypoluektovich avatar Jun 09 '23 19:06 ypoluektovich

Unfortunately, documentation is incomplete, unstructured, partially just drafts so far. Until fundamental principles and basic skeleton are not stabilized, I decided not to focus on docs.

I agree with you that this type annotation is "unnecessary" in case of None variant for the target. There are not so many possibilities to improve it, since generics are used, compiler needs this information, according to my knowledge and Rust syntax. Maybe this sub-module will be redesigned again some day, if a better and more beautiful approach will be found.

Some examples

    use tmux_interface::{
        GetGlobalSessionOptionValue, GetSessionOptionTr, GlobalSessionOptionsCtl,
        SessionOptionsCtl, StartServer, Tmux,
    };

    // 1. type annotation for None
    let value = Tmux::with_command(StartServer::new())
        .add_command(GetGlobalSessionOptionValue::default_shell(None::<&str>))
        .output()
        .unwrap();
    dbg!(value);

    // 2. type annotation for .default_shell() function
    let value = Tmux::with_command(StartServer::new())
        .add_command(GetGlobalSessionOptionValue::default_shell::<&str>(None))
        .output()
        .unwrap();
    dbg!(value);

    // 3. using "options controller"
    let value = GlobalSessionOptionsCtl::with_invoker(&|cmd| {
        Tmux::with_command(StartServer::new())
            .add_command(cmd)
            .output()
    })
    .get_default_shell()
    .unwrap();
    dbg!(value);

AntonGepting avatar Jun 11 '23 13:06 AntonGepting