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

Prompt fix #22

Merged
merged 3 commits into from
Aug 28, 2019
Merged

Prompt fix #22

merged 3 commits into from
Aug 28, 2019

Conversation

syrusakbary
Copy link
Member

This PR refactors the stdin prompt reads into it's own utility module (local-echo) - inspired by https://www.linkedin.com/pulse/xtermjs-local-echo-ioannis-charalampidis (repo: https://github.com/wavesoft/local-echo).

It also fixed QuickJS prompts so they work seamlessly.
2019-08-28 01-07-11 2019-08-28 01_08_49

const parse = parse_;

import { Terminal } from "xterm";

Copy link
Member Author

Choose a reason for hiding this comment

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

All this imports were not used, so I removed them

Choose a reason for hiding this comment

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

Thank you! 😄

this.wasmerFileSystem.volume.fds[0].read = this.stdinRead.bind(this);
this.wasmerFileSystem.volume.fds[1].write = this.stdoutWrite.bind(this);
this.wasmerFileSystem.volume.fds[2].write = this.stdoutWrite.bind(this);

if (sharedStdin) {
this.sharedStdin = sharedStdin;
Copy link
Member Author

Choose a reason for hiding this comment

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

This was not necessary since the params are already typed with the same types as the object types

@syrusakbary
Copy link
Member Author

Note: this PR breaks the commands a, cowsay and lolcat. I believe the fix should be easy, but haven't investigated much

@syrusakbary
Copy link
Member Author

syrusakbary commented Aug 28, 2019

Edit: a, duk and lolcat are now working properly 🎉

@torch2424 torch2424 self-requested a review August 28, 2019 17:19
Copy link

@torch2424 torch2424 left a comment

Choose a reason for hiding this comment

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

Left some comments! Would appreciate if you would read through them @syrusakbary 😄

Merging as I will be the one to address the comments 😂

commandHistory: Array<string>;
commandHistoryIndex: number;

localEcho: LocalEchoController;

Choose a reason for hiding this comment

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

Can we rename the local echo service? When I hear "echo" I think of the command echo, which doesn't really make sense to me that it handles input for xterm? 🤔 😄

const parse = parse_;

import { Terminal } from "xterm";

Choose a reason for hiding this comment

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

Thank you! 😄

@@ -132,8 +124,11 @@ export default class CommandRunner {
(window as any).SharedArrayBuffer && (window as any).Atomics;

this.xterm = xterm;
this.localEcho = new LocalEchoController(this.xterm, {

Choose a reason for hiding this comment

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

So the suffix Controller I think is a little too verbose. Also, in the webdev world, Controllers tend to refer to angularJS Controllers, which is usually associated with a DOM Component. I think this is more of a Service if we were to add a suffix. 🤔 😄 👍

processStdinReadCallback() {}
processStdinReadCallback() {
// When the stdin read begins
// console.log(

Choose a reason for hiding this comment

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

I tend to remove debug code when submitting PRs. In general, I tend to agree with leaving old commented code is bad. I feel it is just noise, and it is the reason why git history exists 😄

Also, especially in terms of console logs, a log that makes sense to you, will not for me because i don't have context on where the log is coming from 👍

/**
* The history controller provides an ring-buffer
*/
export class HistoryController {

Choose a reason for hiding this comment

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

Probably would like to rename this to CommandHistoryService. 😄

@@ -44,18 +44,14 @@ export default class WASICommand extends Command {

this.wasmerFileSystem = new WasmerFileSystem();

// Bind our stdinRead
// Bind our stdinRead / stdoutWrite

Choose a reason for hiding this comment

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

Thanks 😄

} else {
this.stdinReadCounter = 0;
}
if (this.isReadingStdin) {

Choose a reason for hiding this comment

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

Thank you for solving the mystery 🔍 😂

},
"dependencies": {
"@types/shell-quote": "^1.6.1",
"local-echo": "github:wavesoft/local-echo",

Choose a reason for hiding this comment

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

Oh nice, didn't know this existed, glad someone made it: https://github.com/wavesoft/local-echo 😄 🔥 🔥 🔥

Still think the naming should be different. Perhaps, XtermInputHandler.

Controller does make some sense in this case, but i'd still be wary since it has nothing to do with DOM directly.

@@ -93,5 +93,10 @@
"typescript": "^3.5.3",
"url": "^0.11.0",
"xterm": "^3.14.5"
},
"dependencies": {
"@types/shell-quote": "^1.6.1",

Choose a reason for hiding this comment

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

So Right now you are adding dependencies to the lib, that are actually needed to build the shell.

See npm dependencies.

If someone were to try and install the Wasi lib (Which the package.json represents), they would then also need to install these dependencies. When really, these are not needed by the lib, but are required by the shell. Some of these dependencies would be "kind of" correct once we split out the terminal into its own lib as well with lerna. But as of now, I don't think this is. 😄 👍

"dependencies": {
"@types/shell-quote": "^1.6.1",
"local-echo": "github:wavesoft/local-echo",
"shell-quote": "^1.7.1"

Choose a reason for hiding this comment

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

This is rad too: https://www.npmjs.com/package/shell-quote

😄 👏 🎉

@torch2424 torch2424 self-assigned this Aug 28, 2019
@torch2424
Copy link

Merging! 😄

@torch2424 torch2424 merged commit 87d42db into master Aug 28, 2019
@torch2424 torch2424 deleted the prompt-fix branch August 28, 2019 18:20
@torch2424
Copy link

Also, just another note to myself / @syrusakbary , FireFox and Safari get stuck in an infinite prompt() loop. Sometimes, the text is shown incorrectly in the prompt as well 🤔

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