Skip to content

feat: open current exercise via --editor#2204

Open
pacexy wants to merge 6 commits intorust-lang:mainfrom
pacexy:open-in-editor
Open

feat: open current exercise via --editor#2204
pacexy wants to merge 6 commits intorust-lang:mainfrom
pacexy:open-in-editor

Conversation

@pacexy
Copy link
Copy Markdown

@pacexy pacexy commented Jan 29, 2025

This PR implements the --edit-cmd suggested in #2164 (comment). But with the name --editor the same as git.

close #2164

@pacexy pacexy changed the title feat: open current exercie via --editor feat: open current exercise via --editor Jan 29, 2025
@glima
Copy link
Copy Markdown

glima commented Jul 19, 2025

No interest in merging this?

show_key(b'l', b":list / ")?;
show_key(b'c', b":check all / ")?;
show_key(b'x', b":reset / ")?;
show_key(b'e', b":edit / ")?;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This should only be shown if --editor is passed

if let Err(e) = self.app_state.current_exercise().open_in_editor(editor) {
writeln!(stdout, "Failed to open editor: {}", e)?;
}
} else {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If --editor is not passed, then entering e should be ignored


continue;
}
KeyCode::Char('e') => InputEvent::Edit,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ignoring e should happen here


/// Open the exercise file in the specified editor
pub fn open_in_editor(&self, editor: &str) -> io::Result<bool> {
let parts: Vec<&str> = editor.split_whitespace().collect();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You should use shlex instead of split_whitespace


```bash
rustlings --editor code # For VS Code
rustlings --editor vim # For Vim
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't want to advertise using a terminal editor with --editor because it would cover Rustlings and eliminate its interactive design.

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.

Allow opening current exercise in $EDITOR

3 participants