Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Thrump
    @Thrump
    like do i add those stuff to my depenendicies?
    Alexandre Bury
    @gyscos
    On windows, the only currently supported backend is pancurses, as @sajattack mentionned. You'll need to specify it in your Cargo.toml:
    [dependencies.cursive]
    version = "0.11"
    default-features = false
    features = ["pancurses-backend"]
    It should only need you to have a valid compiler: https://github.com/ihalila/pdcurses-sys
    On Windows this means that you need the Visual C++ Build Tools.
    Chris Vest
    @chrisvest
    @gyscos do you plan on cutting a new release once the crossterm PR is merged?
    Alexandre Bury
    @gyscos
    Sure, I could release something
    Calem Bendell
    @calben
    hullooo everyone. i'm getting build errors after cloning the repositories on a 64 bit windows machine. is that expected?
    Alexandre Bury
    @gyscos
    I think the problem is with the termion backend; it's not working yet on windows
    How are you building?
    On windows you'll probably want to use either pancurses or crossterm (though the latter is still very fresh and may have a bit of paint left)
    Calem Bendell
    @calben
    ah, that would make sense! i was builing with the command shown in the readme. but i'll try one of the other guys.
    i'm happy for a life of growing pains. aren't we all, as rust users?
    Alexandre Bury
    @gyscos
    :D
    For example:
    cargo run --no-default-features --features pancurses-backend --example select
    Calem Bendell
    @calben
    what a beauty! i feel nerdier already
    thanks for the help @gyscos
    eaglgenes101
    @eaglgenes101
    What's the preferred way of working with file descriptors/handles/whatever in cursive? Poll them every so often?
    Or is there an option for incorporating file descriptors into the event loop?
    Alexandre Bury
    @gyscos
    @eaglgenes101 I think it would probably being in its own thread
    File io is not easily async anyway, and blocking calls in the UI thread should be avoided as usual
    Chris Vest
    @chrisvest
    It may depend on how much IO you plan to do. In XV I do file IO calls during the layout of the hex view. Those IOs are quite small and nearly always hit the OS page cache, so they are actually negligible compared to the cost of updating the screen. I was planning on making those IOs asynchronous, but it turned out to not be necessary in practice, and the code is simpler for it.
    eaglgenes101
    @eaglgenes101
    I was thinking reading on the receiving end of a constant stream of IPC data
    So nonblocking calls on the FD in question should be fine
    eaglgenes101
    @eaglgenes101
    But because of the nature of the IO I want to do, it has similar responsiveness requirements to keyboard and mouse events, which is why I had the question in the first place
    Alexandre Bury
    @gyscos
    So far there hasn't been a lot of work integrating other sources in the main loop (having a dedicated thread is often much simpler), but if we have some solid use cases we can start a design :)
    eaglgenes101
    @eaglgenes101
    Alternatively, can I tell Cursive that I want to poll standard input myself and then use Cursive's functionalities to make sense of the values I get from input?
    Alexandre Bury
    @gyscos
    That's possible; it would basically amount to creating your own Backend
    Possibly by wrapping another one
    Alexandre Bury
    @gyscos
    You could wrap the Backend::poll_event function to do your own polling
    eaglgenes101
    @eaglgenes101
    For my purposes, I decided to take the termion backend and rewrite the polling logic so that it does poll calls on a small suite of preselected file descriptors
    termion backend spawns a thread dedicated to input reading, so it's a rewrite rather than a wrapper
    eaglgenes101
    @eaglgenes101
    What should a cursive backend do if it encounters an IO error polling for input? Panic?
    Alexandre Bury
    @gyscos
    Error handling isn't really complete yet :^/ So far most backends do panic on IO error
    It's probably easier to catch_unwind the call to Cursive::run() than to insert error reporting in the full printing pipeline
    Henrik
    @hrkfdn
    hey! does cursive offer a way to change the terminal title using the escape sequences, e.g. like http://tldp.org/HOWTO/Xterm-Title-3.html
    Alexandre Bury
    @gyscos
    Not currently, but this might be added to the backends trait
    That's a great idea though!
    NOP0
    @NOP0
    Whats the best way of getting the string from an edit dialog into a variable stored in Main?
    Alexandre Bury
    @gyscos
    By Main you mean the main function? You'd probably use something like a Rc combined with interior mutability (Cell/RefCell)
    Often you'd want to use this variable in other views, or in other threads; in both cases you'll need this shared ownership (though in the case of threads you'll want it to be atomic, using Arc instead of Rc)
    NOP0
    @NOP0
    Thanks, Ive read up on refcell and it seems a bit "overkill" for my use case 🙂 can't I just return a value from the closure or something? Sorry for "newbie" questions 🙂
    Alexandre Bury
    @gyscos
    RefCell (or even the simpler Cell) are very common underneath a lot of libraries - and they're really not that hard to use!
    use cursive::views::Button;
    use cursive::Cursive;
    use std::cell::Cell;
    use std::rc::Rc;
    
    fn main() {
        let my_result = Rc::new(Cell::new(None));
        {
            let button_result = Rc::clone(&my_result);
            let mut siv = Cursive::default();
            siv.add_layer(Button::new("Do it!", move |s| {
                button_result.set(Some(42));
                s.quit();
            }));
            siv.run();
        }
    
        let result = my_result.replace(None);
        assert_eq!(result, Some(42));
    }
    Alexandre Bury
    @gyscos
    Alternatively you can also use UserData to store something with Cursive and get it at the end:
    use cursive::views::Button;
    use cursive::Cursive;
    
    struct ReturnValues {
        answer: i32,
    }
    
    fn main() {
        let mut siv = Cursive::default();
        siv.set_user_data(ReturnValues { answer: 0 });
        siv.add_layer(Button::new("Do it!", move |s| {
            s.with_user_data(|data: &mut ReturnValues| data.answer = 42);
            s.quit();
        }));
        siv.run();
        let result: ReturnValues = siv.take_user_data().unwrap();
    
        assert_eq!(result.answer, 42);
    }
    NOP0
    @NOP0
    Wow, thanks, will definately have another go at this 🙂 it looks easy and clean to use. Thanks again
    starfear
    @starfear
    Hey, how can i check panic message? my app just crashes without any panics
    maybe it's bad idea, but why there is no multipts support? logs in one pts app in another pts
    Alexandre Bury
    @gyscos
    The common solution is to redirect stderr to a file and check this file from another terminal
    Or you can use catch_unwind and just log something in the app itself