Skip to content

add streaming git command status panel #296

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

Closed
wants to merge 36 commits into from

Conversation

scbizu
Copy link

@scbizu scbizu commented Sep 20, 2018

image

const (
// cmdStatusLen is a magic number
// that defines the max columns of CommandStatus panel
cmdStatusLen = 12

Choose a reason for hiding this comment

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

cmdStatusLen is unused

@jesseduffield
Copy link
Owner

Very good idea! This looks like a very promising PR

@ponsfrilus
Copy link
Contributor

[off topic] @scbizu ingress enlightened spotted :)

@scbizu scbizu force-pushed the feature/go-cmd branch 7 times, most recently from 3cdb39e to c6601b5 Compare September 28, 2018 08:14
@codecov-io
Copy link

codecov-io commented Sep 28, 2018

Codecov Report

Merging #296 into master will increase coverage by 0.09%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #296      +/-   ##
==========================================
+ Coverage   84.89%   84.98%   +0.09%     
==========================================
  Files          21       21              
  Lines        3515     3537      +22     
==========================================
+ Hits         2984     3006      +22     
  Misses        491      491              
  Partials       40       40
Impacted Files Coverage Δ
pkg/commands/git.go 65.53% <100%> (+0.41%) ⬆️
pkg/i18n/english.go 100% <100%> (ø) ⬆️
pkg/i18n/dutch.go 100% <100%> (ø) ⬆️
pkg/i18n/polish.go 100% <100%> (ø) ⬆️
pkg/commands/os.go 73.33% <100%> (+1.3%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 471733f...d5daf9b. Read the comment docs.

func TestGitCommandCommitWithStatus(t *testing.T) {
type scenario struct {
testName string
command func(string, ...string) *cmd.Cmd

Choose a reason for hiding this comment

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

command is unused

@scbizu scbizu force-pushed the feature/go-cmd branch 3 times, most recently from 3cc7347 to 96f2b36 Compare October 5, 2018 14:06
@scbizu scbizu changed the title WIP: add streaming git command status panel add streaming git command status panel Oct 6, 2018
go func() {
for {
select {
case status := <-cs.command.Stdout:
Copy link
Owner

Choose a reason for hiding this comment

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

what would be an example value for status? Would it be a random string read from the buffer, or a single character etc?

Copy link
Owner

Choose a reason for hiding this comment

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

also I'm not sure if this is possible but can we call cs.refreshCommandStatus(cs.gui, "") after the command has completed so that we have line breaks between the outputs of different commands (utilising the newline added in refreshCommandStatus)?

Copy link
Author

Choose a reason for hiding this comment

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

  1. The value will be the plain git command output, you can check the output within the dev mode by grep collect\ message,however, I will rename it with the cmdOutput for better understanding .

  2. Do you mean add new line break for different git command? To implement this, I think we'd better to pass a echo \n(shell) to command status panel.

Copy link
Owner

Choose a reason for hiding this comment

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

yes, that's what I mean. Although we'd still need to know when to pass that command, which would require us to know when the first command has finished, which if we knew, we could just add a newline. I'm happy to leave this issue as too-tricky-to-solve for now, unless you have an idea of how to do it :)

Copy link
Author

Choose a reason for hiding this comment

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

Yeah. we can receive the done singnal when the cmd is done. And then we add this line break.

}

// Update updates the command status panel
func (cs *CommandStatus) Update(ui *Gui) {
Copy link
Owner

Choose a reason for hiding this comment

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

conventionally we use gui as the variable name for *Gui, rather than ui


c, isGPG := gui.GitCommand.CommitWithStatus(message)
if isGPG {
// put it into subprogress
Copy link
Owner

Choose a reason for hiding this comment

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

minor typo: this should read subprocess rather than subprogress

// put it into subprogress
sub, err := gui.GitCommand.Commit(message)
if err != nil {
// TODO need to find a way to send through this error
Copy link
Owner

Choose a reason for hiding this comment

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

is this TODO still necessary? using an error panel should be fine in my opinion

Copy link
Author

Choose a reason for hiding this comment

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

I am not sure whether I can remove this, so I just keep it as before.

}

// Update updates the command status panel
func (cs *CommandStatus) Update(ui *Gui) {
Copy link
Owner

Choose a reason for hiding this comment

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

I think this could have a better name, something like PrintCommandOutput. The name Update suggests to me that it will be an immediate operation

pkg/gui/gui.go Outdated
@@ -136,6 +142,17 @@ func (gui *Gui) scrollDownMain(g *gocui.Gui, v *gocui.View) error {
return nil
}

func (gui *Gui) scrollDownCommandStatus(g *gocui.Gui, v *gocui.View) error {
Copy link
Owner

Choose a reason for hiding this comment

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

this duplicates some code from the above scroll method. Could we make a generic function that takes a view name and returns a method for scrolling that view? Something like this:

func (gui *Gui) genericScrollDown(viewName string) func(g *gocui.Gui, v *gocui.View) error {
	return func (g *gocui.Gui, v *gocui.View) error {
		view, err := g.View(viewName)
		if err != nil {
			return err
		}
		ox, oy := view.Origin()
		if oy < len(view.BufferLines()) {
			return view.SetOrigin(ox, oy+gui.Config.GetUserConfig().GetInt("gui.scrollHeight"))
		}
		return nil
	}	
}

then in our keybindings file we can use it like so:

		}, {
			ViewName: "",
			Key:      gocui.KeyPgdn,
			Modifier: gocui.ModNone,
			Handler:  gui.genericScrollDown("main"),
		}, {

return err
isStreamingStatusEnable := gui.Config.GetUserConfig().GetBool("commandStatus")

if isStreamingStatusEnable {
Copy link
Owner

Choose a reason for hiding this comment

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

this duplicates some code. The only difference between the two blocks in the if statement is commitsBranchesBoundary vs optionsTop, so we can just assign that value to a variable based on the value of isStreamingStatusEnable and then we don't need to have the SetView method repeated

@@ -217,7 +248,7 @@ func (gui *Gui) layout(g *gocui.Gui) error {
}
filesView.Highlight = true
filesView.Title = gui.Tr.SLocalize("FilesTitle")
v.FgColor = gocui.ColorWhite
filesView.FgColor = gocui.ColorWhite
Copy link
Owner

Choose a reason for hiding this comment

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

good pickup ;)

pkg/gui/gui.go Outdated
@@ -429,6 +471,13 @@ func (gui *Gui) quit(g *gocui.Gui, v *gocui.View) error {
return gui.createUpdateQuitConfirmation(g, v)
}
if gui.Config.GetUserConfig().GetBool("confirmOnQuit") {
// clear command status buffer
Copy link
Owner

Choose a reason for hiding this comment

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

I'm not sure why we're clearing this buffer if we're about to quit anyway

Copy link
Author

Choose a reason for hiding this comment

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

It is seems unnecessary to do this XD

Copy link
Owner

@jesseduffield jesseduffield left a comment

Choose a reason for hiding this comment

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

Cool stuff! I've been using it throughout the week and it seems pretty stable.

I left some comments :)

@scbizu
Copy link
Author

scbizu commented Oct 12, 2018

Thanks for your advice , i will do some code fix this weekend.

@scbizu
Copy link
Author

scbizu commented Apr 17, 2019

Hello @jesseduffield , I rebased my code, and pushed again for re-review.

(BTW, The package management is the really disappointing thing , when I add my cmd repo in toml, and run dep ensure , the vendor comes with so many changes XD. Really MISSING the go mod now~

@mjarkk
Copy link
Contributor

mjarkk commented May 3, 2019

@scbizu I have a number of questions and comments..

  • How can that this pull adds ~3,300,000 extra lines of code?
  • The go.mod file is removed in master
  • I can be wrong here but i can remember from looking thought your code that there was a PTY package somewhere. PTYs don't work on the windows subsystem see: https://github.com/kr/pty/issues/67 , If you have no access to windows i'm fine with testing this for you on win

@scbizu
Copy link
Author

scbizu commented May 5, 2019

@mjarkk Hi, thanks for your reply.

  • Because of the missing version tag in Gopkg.toml(I mean the constraint),when I run dep ensureto add another dependency, the out-of-date package will update to its new release.

  • I forget to push my recent commit XD , thanks! (go mod is removed)

  • In master Gopkg.toml,the pty package points to github.com/jesseduffield/pty? According to the CI report, I do not find any breaks for Windows builds.

@mjarkk
Copy link
Contributor

mjarkk commented May 5, 2019

In master Gopkg.toml,the pty package points to github.com/jesseduffield/pty? According to the CI report, I do not find any breaks for Windows builds.

Great to hear that the program still work on win :),
The jesseduffield/pty package is a problem but that has nothing to do with your PR
There is also already a PR open to fix the usage of that package.

@scbizu
Copy link
Author

scbizu commented May 5, 2019

In master Gopkg.toml,the pty package points to github.com/jesseduffield/pty? According to the CI report, I do not find any breaks for Windows builds.

Great to hear that the program still work on win :),
The jesseduffield/pty package is a problem but that has nothing to do with your PR
There is also already a PR open to fix the usage of that package.

Sounds GREAT XD

@jesseduffield
Copy link
Owner

Giving this a quick local test, I've noticed a few things:

  1. The CommandStatus only has output when I'm doing a git commit. Is this expected behaviour? Or do we also want this printing a line whenever we run any git (or bash) command?
  2. After committing a file, the files view is not updated immediately, meaning it is only refreshed to show that the staged file is no longer present after the automatic refresh that happens every ten seconds
  3. The output has no colour, which makes pre-commit output hard to read if it is usually coloured. I'm not sure if there's a way around this.
  4. The CommandStatus panel does not scroll automatically once the content spills out of view
  5. It would be nice to be able to scroll the commandStatus view with the mouse, as you can do with the other panels.

@scbizu
Copy link
Author

scbizu commented May 7, 2019

Giving this a quick local test, I've noticed a few things:

  1. The CommandStatus only has output when I'm doing a git commit. Is this expected behaviour? Or do we also want this printing a line whenever we run any git (or bash) command?
  2. After committing a file, the files view is not updated immediately, meaning it is only refreshed to show that the staged file is no longer present after the automatic refresh that happens every ten seconds
  3. The output has no colour, which makes pre-commit output hard to read if it is usually coloured. I'm not sure if there's a way around this.
  4. The CommandStatus panel does not scroll automatically once the content spills out of view
  5. It would be nice to be able to scroll the commandStatus view with the mouse, as you can do with the other panels.
  1. yep, my original idea is to fix the pre-commit message. So, hmm, these changes currently not support other git commands. Others will be easily integrated once the streaming panel works as we excepted.

  2. Is this a known issue or the new issue 🙈 ?

  3. The streaming panel only forwards the stdout and stderr. According to my knowledge, it will keep the color text. But I haven't test it yet,I will give it a try these days (sounds like an interesting point ;) ).

  4. Great point, I will support this these days.

  5. Mouse... I will try it .

@jesseduffield
Copy link
Owner

doing a cleanup of PR's so I'm closing this but if you ever want to give it another shot feel free to raise another PR :)

@marcjay
Copy link

marcjay commented May 12, 2020

This PR was looking promising - I'm looking to see the output from a git push command as that includes a link to raise a PR, e.g.:

remote: Create pull request for <branch-name>:
remote:   https://<URL-to-create-PR-here>

Am aware of the bitbucket/github integration but the version of bitbucket I'm using uses a different URL structure. Was this PR addressing push output as well, or just commit? Wanting to know whether to raise a separate issue for this.
I suspect the other option is to raise an issue/PR for extending the 'create pull request' support to have configurable URLs

@scbizu
Copy link
Author

scbizu commented May 13, 2020

Hi @matejcik , this PR does nothing special but only output which git push(or other git commands) does , which means that if your git command shows you

remote: Create pull request for <branch-name>:
remote:   https://<URL-to-create-PR-here>

and then the streaming panel will be too .

(Since I unfollowed the lazygit ecosystem too long so that maybe this PR is already out-of-date and has no guaranteed deadline)

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.

7 participants