Skip to content
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

Merged
merged 19 commits into from
May 12, 2018

Conversation

copyninja
Copy link
Contributor

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.

  1. We do not need another helper object as in python code, at least that is what I feel. One reason for this is unlike python code we only emit events and no IO is performed on our side. Also in python code helper is passed to rlcompleter class to trigger event that leads to return of completions. I think with some thinking we can do that in Input struct itself.
  2. I've added 2 events specifically for tab completions this should be triggered only when user hits tab. But I'm unsure how we communicate back the results to completer. May be new IO Events?.

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 like Completer 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?.

- 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.
@warner
Copy link
Collaborator

warner commented May 5, 2018

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.

@warner warner mentioned this pull request May 6, 2018
- 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.
@copyninja
Copy link
Contributor Author

@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 get_completions in Wormhole object. This calls InputHelper's get_completions and processes all event before passing over result to app.

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.
@copyninja
Copy link
Contributor Author

@warner I wrote down my idea of using inputhelper in readline.rs example. But at the moment it panics as it is hit by both completer and client trying to hold mutable reference, which you mentioned in the comment on #24.

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.
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.
@copyninja
Copy link
Contributor Author

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.
@copyninja
Copy link
Contributor Author

@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.

@warner
Copy link
Collaborator

warner commented May 12, 2018

Looks pretty good.. let's land this now and figure out the fixes later.

@warner warner merged commit e559961 into magic-wormhole:master May 12, 2018
@copyninja copyninja deleted the input-machine branch May 14, 2018 06:05
@copyninja
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants