AntonGepting / tmux-interface-rs

Rust language library for communication with TMUX via CLI
MIT License
51 stars 5 forks source link

Globality must be specified before option name in SessionOptions #8

Open ypoluektovich opened 3 years ago

ypoluektovich commented 3 years ago

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.

AntonGepting commented 3 years ago

Thank you.

fixed, published 0.2.1

AntonGepting commented 1 year ago

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)

ypoluektovich commented 1 year ago

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.

AntonGepting commented 1 year ago

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);