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

lib: repl add .load-editor feature #14503

Closed
wants to merge 4 commits into from
Closed

Conversation

robbinhan
Copy link

support input .load-editor in repl

@nodejs-github-bot nodejs-github-bot added the repl Issues and PRs related to the REPL subsystem. label Jul 26, 2017
Copy link
Contributor

@Fishrock123 Fishrock123 left a comment

Choose a reason for hiding this comment

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

lib/repl.js Outdated
@@ -1267,6 +1267,34 @@ function defineDefaultCommands(repl) {
'// Entering editor mode (^D to finish, ^C to cancel)\n');
}
});

repl.defineCommand('load-editor', {
help: 'Enter load and editor mode',
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe 'Load a file and enter editor mode'?

@robbinhan robbinhan force-pushed the master branch 2 times, most recently from ab13971 to b217b78 Compare July 27, 2017 02:02
@XadillaX
Copy link
Contributor

XadillaX commented Jul 27, 2017

Would you please update your summary to describe your PR?

eg.

repl: fix .... (not an issue number but describe what exactly you have done)

inputStream.write('.help\n');
assert(/\n\.say1 help for say1\n/.test(output),
Copy link
Contributor

Choose a reason for hiding this comment

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

any reason to have these modification? (a blank line and some spaces)

Copy link
Author

Choose a reason for hiding this comment

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

because add .load-editor command need more space for fomat

> .help
.break         Sometimes you get stuck, this gets you out
.clear         Break, and also clear the local context
.editor        Enter editor mode
.exit          Exit the repl
.help          Print this help message
.load          Load JS from a file into the REPL session
.load-editor   Load a file and enter editor mode
.save          Save all evaluated commands in this REPL session to a file
.say1          help for say1
.say2
>

Copy link
Contributor

Choose a reason for hiding this comment

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

👌

@robbinhan robbinhan changed the title lib: repl for #14022 lib: repl add .load-editor feature Jul 27, 2017
Trott
Trott previously requested changes Jul 27, 2017
Copy link
Member

@Trott Trott left a comment

Choose a reason for hiding this comment

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

Thanks for this! It would seem that it needs a test.

@@ -34,8 +34,9 @@ r.defineCommand('say2', function() {
this.displayPrompt();
});


Copy link
Contributor

Choose a reason for hiding this comment

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

How about this blank line?

@robbinhan robbinhan force-pushed the master branch 2 times, most recently from 97dc9c9 to 6137b22 Compare July 27, 2017 10:18
@robbinhan
Copy link
Author

@Fishrock123 I updated doc
@Trott I added a test
@XadillaX I removed it

@Trott Trott dismissed their stale review July 27, 2017 20:38

test added, dismissing review

@addaleax addaleax added the semver-minor PRs that contain new features and should be released in the next minor version. label Jul 30, 2017
@@ -39,6 +39,7 @@ The following special commands are supported by all REPL instances:
* `.load` - Load a file into the current REPL session.
`> .load ./file/to/load.js`
* `.editor` - Enter editor mode (`<ctrl>-D` to finish, `<ctrl>-C` to cancel)
* `.load-editor` - Load a file and enter editor mode (`<ctrl>-D` to finish, `<ctrl>-C` to cancel)
Copy link
Member

Choose a reason for hiding this comment

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

It would be helpful to have an example

Copy link
Author

Choose a reason for hiding this comment

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

Do you mean add an example in doc?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah. For instance, I presume there's a way of providing the file name to load but that's not captured here

Copy link
Contributor

Choose a reason for hiding this comment

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

Just how .load does it should be fine, the second line.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks, I have updated doc file

const stream = new common.ArrayStream();
const outputStream = new common.ArrayStream();

stream.write = () => { throw new Error('Writing not allowed!'); };
Copy link
Member

Choose a reason for hiding this comment

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

stream.write = common.mustNotCall('writing not allowed');

Copy link
Author

Choose a reason for hiding this comment

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

thank you for your help

Copy link
Contributor

@Fishrock123 Fishrock123 left a comment

Choose a reason for hiding this comment

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

@lance
Copy link
Member

lance commented Aug 17, 2017

In #14861 (comment) I discovered that .load will only work with some .js files, but not all depending on the formatting. I wonder if it makes more sense to just have .load capable of loading and executing any JS file, vs having it work for some but not all. I'm not sure the benefit of adding additional surface area to the REPLServer interface with .load-editor when .load itself should be improved (imo).

@robbinhan
Copy link
Author

@lance
In my opinion, these are two different command. ‘.load’ just a command to lad file, and does’t do more things rather than that. ‘.load-editor’ means that load file and change into editor mode.

@lance
Copy link
Member

lance commented Aug 18, 2017

@robbinhan I see your point. But it seems to me that, as-is, .load is broken and should be fixed. A reasonable fix for it would be to enable editor mode when .load is executed. In doing that, there is no need for .load-editor.

As I said in my PR, I didn't mean to encroach on what you were doing here, I was just trying to address #14022. I wasn't aware of your PR until a comment from @Fishrock123. I definitely appreciate your contribution here, and I am willing to go with whatever approach makes the most sense. In this case, I feel it's fixing .load, but I will defer to others' opinions.

@robbinhan
Copy link
Author

@lance So, does improve .load command to enable editor mode, than remove .load-editor command is the best choice?

@lance
Copy link
Member

lance commented Aug 19, 2017

@robbinhan in my opinion, yes. But I want to hear from other @nodejs/collaborators on it.

@jasnell
Copy link
Member

jasnell commented Aug 24, 2017

I'm thinking that the other PR is likely the better option. Not quite ready to sign off on it tho.

@BridgeAR
Copy link
Member

I looked at both of these and I am definitely in favor of #14861. As @lance already pointed out it is more like a bug fix instead of adding a new feature. .load is simply not working as it is intended to and #14861 fixes that. Because of those reasons I am actually opposed to landing this.

@robbinhan I appreciate your work a lot nevertheless!

@BridgeAR
Copy link
Member

Closing due to the already mentioned reasons.

@BridgeAR BridgeAR closed this Aug 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
repl Issues and PRs related to the REPL subsystem. semver-minor PRs that contain new features and should be released in the next minor version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants