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

Informational prompt? #1163

Open
ristillu opened this issue Feb 17, 2021 · 4 comments
Open

Informational prompt? #1163

ristillu opened this issue Feb 17, 2021 · 4 comments

Comments

@ristillu
Copy link

@ristillu ristillu commented Feb 17, 2021

Is your feature request related to a problem? Please describe.
In our project we use git describe all the time for issue tracking. I implemented a custom command that sort of does what I want but I'm interested if you have ever thought about informational only prompts. I.e. not 'input' or 'menu', just outputting the result of something like git describe. There may be other use cases for informational prompts but lg is pretty comprehensive and I'm struggling to think of anything else where you haven't covered my bases already.

Describe the solution you'd like
I'd like to have a bound customCommand that pops up the prompt and exits perhaps on Esc or Enter (doesn't matter, whichever makes sense to you).

Describe alternatives you've considered
Here's what I implemented, which works fine but it feels a bit like a context switch:

customCommands:
  - key: 'D'
    command: 'git describe'
    context: 'commits'
    subprocess: true

I can also use the ':' option and type in git describe as an on-the-fly custom command from the localBranches or commits tabs. Also a workable solution but also feels context switchy. And I'd prefer a single command to typing the full command each time.

Additional context
Thanks so much for lg. A few of my colleagues and I love it.

@jesseduffield
Copy link
Owner

@jesseduffield jesseduffield commented Feb 17, 2021

First off, thanks for your kind words :)

Sounds like we want a showOutput boolean key there so that the output of the command appears in a popup

@jesseduffield
Copy link
Owner

@jesseduffield jesseduffield commented Apr 5, 2021

I'm chucking the good-first-issue label on this because I reckon this will be pretty straightforward to implement. Relevant places that need updating:
handleCustomCommandKeybinding function in pkg/gui/custom_commands.go
CustomCommand struct in pkg/config/user_config.go

@dutroctu
Copy link

@dutroctu dutroctu commented Sep 8, 2021

I would like to fix this. I can understand that we can add the showOutput in the CustomCommand to check whether we need to show output in the handleCustomCommandKeybinding. But I am quite newbie so I don't know show to popup the output of the command. Could you please give me the reference of the popup @jesseduffield
I am willing to contribute to the community.

Thanks

@jesseduffield
Copy link
Owner

@jesseduffield jesseduffield commented Oct 17, 2021

@dutroctu you would want to go into handleCustomCommandKeybinding in pkg/gui/custom_commands.go and do something like the following:

		f := func() error {
			cmdStr, err := gui.resolveTemplate(customCommand.Command, promptResponses)
			if err != nil {
				return gui.surfaceError(err)
			}

			if customCommand.Subprocess {
				return gui.runSubprocessWithSuspenseAndRefresh(gui.OSCommand.PrepareShellSubProcess(cmdStr))
			}

			loadingText := customCommand.LoadingText
			if loadingText == "" {
				loadingText = gui.Tr.LcRunningCustomCommandStatus
			}
			return gui.WithWaitingStatus(loadingText, func() error {
				output, err := gui.OSCommand.
					WithSpan(gui.Tr.Spans.CustomCommand).
					RunShellCommandWithOutput(cmdStr)
				if err != nil {
					return gui.surfaceError(err)
				}

				if err := gui.refreshSidePanels(refreshOptions{}); err != nil {
					return err
				}

				if customCommand.ShowOutput {
					return gui.ask(askOpts{
						title:  customCommand.Command,
						prompt: output,
					})
				}

				return nil
			})
		}

The RunShellCommandWithOutput function does not yet exist but you can go to RunShellCommand and see that it actually drops the output of the command that's run. So you can create a RunShellCommandWithOutput which does not drop that output, and then have RunShellCommand call RunShellCommandWithOutput and just return the error.

Lemme know if you need any help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants