mendelt / cmdr

Cmdr is a library for building line-oriented text-based user interfaces in Rust.
Apache License 2.0
15 stars 1 forks source link

(Feature) Provide a way to read from a file a series of instructions #39

Open TFCx opened 4 years ago

TFCx commented 4 years ago

It would be very useful to be able to read a series of instructions from a file. That would allow scripting as well as easy testing. Should there be a way to configure to either 1) do all the instructions even if some returns errors 2) exit at the first instruction returning an error? Also I'm not familiar with rust yet but there might be some additional design/testing involved in an async environment?

mendelt commented 4 years ago

Thank you for the great idea. This should be reasonably easy to implement. I'm not sure about error handling yet. I think we'll crash out of the application when a panic occurs, this is similar to how cmdr works for manual input, and we'll probably go for option 1 in the first version for normal error results. Cmdr itself works completely synchronously at the moment and I'm not sure if it makes sense to change this. I think it makes sense to keep cmdr synchronous but I don't think there are any issues using it to kick of async stuff running in the background. But I havent played with this yet and I'm open to suggestions on how to do this better.

mendelt commented 4 years ago

I have this working right now but I'm not completely happy with the interface yet. So I'll play with this a bit more before I create a release. If you're interested in trying out the new feature I have everything working in the master branch. There is an example in cmdr/examples/09-file-input.rs that shows how to run commands from a file. Basically there already was a LineReader trait that abstracted away input but this was not accessible and only had a RustyLineReader implementation that uses the RustyLine library for user input. I created a FileLineReader and an alternative entry-point to change what LineReader implementation you use.

TFCx commented 4 years ago

I'll test it tomorrow with my small use case. I have been using a locally modified version of cmdr but your code seems better. I have another small request, but i'll open another issue for it.