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

Be able to test the output of cmdr #40

Open TFCx opened 4 years ago

TFCx commented 4 years ago

I'm doing some unit testing to check if my software produces the correct results. Right now, cmdr uses println!() but it would be cool I could configure the output stream. Would that mean that scopes should store a reference to a "Write" interface and use write!() instead of print!()? In addition to testing, I think it could also be needed if someone uses cmdr using some TCP stream or if they want to both stdout and log the commands and results produced.

mendelt commented 4 years ago

Sounds good but this will take some more time. I had similar requests when I did a talk about cmdr some months ago. This also fits nicely with your other issue #39. Being able to redirect input is more useful if you can also redirect output. This will probably be optional, people should still be able to use println! for output in simple use-cases. And I'll have to think about how this fits with some of the other planned features. I don't really want to go the route of forcing users of the library to store state in their scopes. I might be able to add scope state with the cmdr macro but I'd like to avoid that if I could. I think the sane way to do this would be to pass in a writer as a parameter to commands that need it. That would be quite a change in the api though.