-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Input machine implementation #36
Conversation
- Make sure we can pass this list of nameplates using RxNameplates event. - From lister this list of nameplates should go to input machine - rendezvous machine should handle nameplates message and generate list of nameplates from it. Then it should emit RxNameplates event for lister machine Misc changes to make sure we can access id key of nameplates message by making it public.
I'll add some thoughts to #24, I think that'll be the best place to design it. But yeah, the InputHelper will be an API-side object, communicating with our state machines through API/IO events, so it won't go into into the "core" crate. |
- New APIEvent called InputHelperEvent which will be emitted by Input machine when it receives nameplates or wordlist. - New InputHelper object which can process the event and stash the nameplates and wordlist provided to it by Input machine. - InputHelper provides `get_completions` API which can be used by input tab completion interface to get possible word completions and emits events for InputMachine at some point. InputHelper is just a helper module and not a statemachine.
This API should be used by readline implementations on cli to get possible completions for user input when user hits TAB key.
@warner What do you think of my last 2 commits?. I read through your explanation on #24 but I found a bit simpler approach. Its not fully completed but I wanted to get your thoughts on this. I've now a InputHelper object which works on InputHelperEvent (APIEvent). Main purpose of InputHelper is to stash the nameplates and wordlist. It also provides api to provide word completion and emits possible events to Input machine. Main api which should be used by rustyline or similar library traits is There are some pending things like what happens if the helper is called before actually machine is initialized etc but that can be fixed. And I'm also yet to write a example code on how to use this code from application side. |
Currently this is fine as if I_Start is got for in wrong state nothing happens we just ignore it in machine. There is no way for helper to know the current state of Input machine for now.
Since I'm doing double mutable borrow on refcell this implementation panics on running.
There is no other way for wormhole to send the actions back to core which happens or tab completions. It has to be taken care by the application to communicate it back to core.
Mostly TxList and TxClaim may be
By making scopes we are trying to make sure we do not due multiple borrow mut on RefCell. slightly ugly but looks like only possible way.
So I handled the panic condition by using nested scopes to avoid trying to hold multiple mutable references. It looks quirky but I could only find this as the way. While trying to make that work I faced couple more issues one was the completer logic needs to handle sending out IOActions generated while trying tab completions (like TxList). This now I handled again looks to me like more of hack. 2nd was the breaking of words during hitting tab does not seem to be correct. I guess I need to use - as break character but not sure about it need to see how rustyline works. Third I need to use thread in readline examples to make sure taking input goes into separate thread as other messages does not get handled like nameplates from server etc. I'm not sure what other problems this will open, let me explore a bit more. |
This is needed as some one needs to process the output from the core else we will be stuck in wormhole.
Currently the co-ordination between inputhelper - wormhole core - and application is partially working. Input completion logic is broken and needs further debugging.
@warner Now code is able to make communication between core - input helper - app. My completion logic is flawed but still it can fetch list of nameplate from server and provide tab completion. I will look more into how to get code completion working in proper way. |
Looks pretty good.. let's land this now and figure out the fixes later. |
Thanks for merging this!. I think core part is fine just completion logic needs fixing. First I need to figure out how rustyline basically works and what BREAK_CHARS I need to use. I will look into those now and clean up warnings from code. |
This is an attempt to port Input machine as per python magic-wormhole code. But this is not complete as it gave out several questions which needs answering.
I looked at rustyline, which was suggested crate in one of the comments in #24. I see one possibility is to make Input machine implement the
Completer
trait and let it internally check for the state and depending on user input and state of the machine it returns appropriate results. This will avoid the tab completions to interact or affect the Input state machine itself. But given that we follow sans-io approach relying on a specific I/O crate might not feel like correct. I also checked most other available crates for readline implementation and all of them needs implementation of trait likeCompleter
in rustyline, only with different input and output value.At the moment I'm bit lost. I've all what is needed to do the completion but I don't know how to really go further :-).
@warner @vu3rdd can you please share your thoughts?.