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

Allow limiting selection to only GUI/CLI options #10

Open
CyanBlob opened this issue Aug 15, 2021 · 3 comments
Open

Allow limiting selection to only GUI/CLI options #10

CyanBlob opened this issue Aug 15, 2021 · 3 comments

Comments

@CyanBlob
Copy link

I'm working on a GUI application, and was hoping to be able to use this crate to allow users to edit some files. However, it seems to be attempting to launch my CLI editor (nvim) despite being launched from a GUI, which unfortunately makes this crate unusable as it is now.

@milkey-mouse
Copy link
Owner

My goal with this crate is to have behavior similar to Git, which also opens a terminal editor even from a GUI if that is what is set in your EDITOR variable. The hardcoded list of editors is just to provide some sort of fallback in case EDITOR is not set. After all, opening a terminal editor should be better than failing to find an editor to launch at all. I think trying to maintain a blacklist of command-line editors so GUI apps only open GUI editors could be a cat-and-mouse game as I'm sure there are other CLI editors I and edit are not aware of.

The easiest solution is the same as it is for Git: change your default editor to a GUI editor. Many Git tutorials have this as one of the first steps, but I agree that it would be better UX-wise not to have to do this. One workaround if you want this to Just Work for anyone using your GUI app is to set the EDITOR variable upon startup to the path for a GUI editor; then edit should pick it up.

// find the GUI editor of your choice
let gui_editor = "/usr/local/bin/my-editor";
std::env::set_var("EDITOR", gui_editor);
edit::edit("edit me"); // should open my-editor

@ok-nick
Copy link

ok-nick commented May 1, 2024

Is it expected for the crate to open the CLI editor in a new terminal window if invoked from a GUI editor?

@MatthewBlanchard
Copy link

MatthewBlanchard commented Jul 4, 2024

My goal with this crate is to have behavior similar to Git, which also opens a terminal editor even from a GUI if that is what is set in your EDITOR variable. The hardcoded list of editors is just to provide some sort of fallback in case EDITOR is not set. After all, opening a terminal editor should be better than failing to find an editor to launch at all. I think trying to maintain a blacklist of command-line editors so GUI apps only open GUI editors could be a cat-and-mouse game as I'm sure there are other CLI editors I and edit are not aware of.

The easiest solution is the same as it is for Git: change your default editor to a GUI editor. Many Git tutorials have this as one of the first steps, but I agree that it would be better UX-wise not to have to do this. One workaround if you want this to Just Work for anyone using your GUI app is to set the EDITOR variable upon startup to the path for a GUI editor; then edit should pick it up.

// find the GUI editor of your choice
let gui_editor = "/usr/local/bin/my-editor";
std::env::set_var("EDITOR", gui_editor);
edit::edit("edit me"); // should open my-editor

Instead of trying to provide a hardcoded blacklist why not provide the tools for the library consumer to do this themselves? Something like get_editors() that returns a list of all present editors the library tracks, and then an edit_with_editor() that accepts the names returned by get_editors? This would put the figuring out if it's gui or cli part on the crate consumer, but at least give them the tools to do it.

It'd also be nice for GUI tools to be able to present a list of editors found and choose a default there, since I would rather not have EDITOR set to vscode, but there are things I would rather have open in vscode.

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

No branches or pull requests

4 participants