Skip to content

Initial implementation of frontend-configurable command runner #663

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

Merged
merged 20 commits into from
Dec 28, 2024

Conversation

rben01
Copy link
Contributor

@rben01 rben01 commented Nov 30, 2024

No description provided.

@rben01
Copy link
Contributor Author

rben01 commented Nov 30, 2024

Related to #584

Copy link
Owner

@sharkdp sharkdp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for this. It looks like this is going in the right direction! Before I take a more detailed look, I have two high-level comments. In general, the more code we can move from numbat-cli towards numbat, the better. It doesn't look like we made a lot of progress on this front, given that main.rs is longer than it was before.

It might make sense to also work on the WASM frontend, to see how it all plays out.

rben01 and others added 9 commits November 30, 2024 16:34
The `CommandRunner` is now the entry point to commands (no need for eg `SourcelessCommandParser`)
`SessionHistory` is now owned by `CommandRunner`
Moved most logic into the CommandRunner itself
As @sharkdp suggested, this helped to remove some duplicated checks of enabled-ness
Now it's perfectly testable and isn't a massive pile of spaghetti
@rben01
Copy link
Contributor Author

rben01 commented Dec 12, 2024

Making a note here to not forget to also merge the copy-to-clipboard branch into this one, as this currently does not include that command.

Comment on lines 165 to 168
pub fn enable_print_markup(mut self, action: fn(&Markup)) -> Self {
self.print_markup = Some(action);
self
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this basically enables list/info/help and some other things. Maybe we could call this something like

Suggested change
pub fn enable_print_markup(mut self, action: fn(&Markup)) -> Self {
self.print_markup = Some(action);
self
}
pub fn print_markup_using(mut self, action: fn(&Markup)) -> Self {
self.print_markup = Some(action);
self
}

or just

Suggested change
pub fn enable_print_markup(mut self, action: fn(&Markup)) -> Self {
self.print_markup = Some(action);
self
}
pub fn print_using(mut self, action: fn(&Markup)) -> Self {
self.print_markup = Some(action);
self
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about print_with?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good!

Copy link
Owner

@sharkdp sharkdp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fantastic, thank you very much!

I have added a few minor review comments, and I have one remaining question:

The web frontend has a reset command:

} else if (input_trimmed == "reset") {
numbat = create_numbat_instance();
numbat.interpret("use units::currencies");
combined_input = "";
updateUrlQuery(null);
this.clear();

Do you think we can implement this using the current architecture?

We basically need mutable access to the Context to reset it to some (frontend-configurable) default state. And we currently also clear the screen from the reset command. I guess that could be done frontend-independently. If reset is exectuted, we could check if clear_fn is set, and just run it in addition.

Making a note here to not forget to also merge the copy-to-clipboard branch into this one, as this currently does not include that command.

Can we maybe do this in a second step after this has been merged?

@rben01
Copy link
Contributor Author

rben01 commented Dec 28, 2024

Pushed an initial implementation of reset. It simply asks the frontend to provide a function that can construct a fresh Context. (In theory it could reinitialize an existing Context, which would presumably be cheaper, but I didn't see how to achieve this easily.)

@sharkdp
Copy link
Owner

sharkdp commented Dec 28, 2024

Thank you for the updates!

@sharkdp sharkdp merged commit 587f720 into sharkdp:master Dec 28, 2024
16 checks passed
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.

2 participants