Skip to content

Conversation

@mrnugget
Copy link
Contributor

@mrnugget mrnugget commented Oct 6, 2020

GIF:

screenshot_2020-10-07_11 30 10

TODO:

  • Timestamp needs to not be truncated, but I'm not sure where to best put the timestamp.

@mrnugget mrnugget marked this pull request as ready for review October 6, 2020 14:22
@mrnugget mrnugget requested a review from a team October 6, 2020 14:22
@mrnugget
Copy link
Contributor Author

mrnugget commented Oct 7, 2020

Timestamps truncated and moved to the right. TODOs checked off. Ready for the big review @sourcegraph/campaigns!

Comment on lines 17 to 21
if !o.caps.Isatty {
newProgressWithStatusBarsSimple(barPtrs, statusBars, o)
}

return newProgressWithStatusBarsTTY(barPtrs, statusBars, o, opts)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note to reviewers: progressWithStatusbarsTTY and progressWithSatusBarsSimple have a lot of similarities with progressTTY and progressSimple respectively. I've tried to extract some of the common stuff and embed progressTTY in progressWithStatusBarsTTY. That helped but not as much as it would've in a language where inheritance was a first class concept.

The problem in Go is this:

type inner struct {
	name string
}

func (i *inner) String() string { return i.format() }
func (i *inner) format() string { return fmt.Sprintf("my name is %s", i.name) }

type outer struct {
	*inner
}

func (o *outer) format() string { return "i am outer!" }

func main() {
	i := &inner{name: "inner"}
	fmt.Println(i)

	o := &outer{inner: i}
	fmt.Println(o)
}

That prints:

my name is inner
my name is inner

See this StackOverflow answer for details. Short version: Go doesn't have virtual methods.

I might try to "invert" the code and have the structs' methods call functions, passing themselves in, but I'm not sure it's worth it.

Because right now I don't think the duplication is a problem. The code that is duplicated depends on the callee's state and doesn't contain a lot of duplicated logic. The hairy bits are not duplicated.

Copy link
Member

@eseliger eseliger left a comment

Choose a reason for hiding this comment

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

Looks good! Thanks for taking on the effort of designing a TUI 👍

StartedAt time.Time
FinishedAt time.Time

// TODO: add current step and progress fields.
Copy link
Member

Choose a reason for hiding this comment

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

is this todo comment related to the newly added line? If not, I'd add a newline here to avoid confusion

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll let @LawnGnome decide. He added the TODO and I wasn't sure whether he had something else in mind, like

TotalSteps int
CurrentStep int

or something like that.

Copy link
Contributor

Choose a reason for hiding this comment

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

That was my intention, but I think it's unnecessary now with the work that you've done since I wrote that, so we could remove the TODO.

Copy link

@chrispine chrispine left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

Copy link
Contributor

@LawnGnome LawnGnome left a comment

Choose a reason for hiding this comment

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

This LGTM! I think there's a lot of good stuff in here.

There is an issue right now with outputting to a non-TTY, so I'm going to mark this as changes requested, but I think there's a clear path to fixing it and getting this landed.

I also tested this on Windows. Behold:

out

StartedAt time.Time
FinishedAt time.Time

// TODO: add current step and progress fields.
Copy link
Contributor

Choose a reason for hiding this comment

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

That was my intention, but I think it's unnecessary now with the work that you've done since I wrote that, so we could remove the TODO.

}

if !o.caps.Isatty {
newProgressWithStatusBarsSimple(barPtrs, statusBars, o)
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't actually return the simple version, which means that ANSI escape codes are still used and the output (if being redirected to a file) is unusable.

However, progressWithStatusBarsSimple doesn't implement ProgressWithStatusBars at the moment, so that's another issue that would have to be dealt with.

I've pushed 19b6ec5 with what I think would be a reasonable fix, but haven't merged it into this branch: PTAL!

@mrnugget mrnugget merged commit 5141363 into main Oct 8, 2020
@mrnugget mrnugget deleted the mrnugget/magic-status-bar branch October 8, 2020 16:01
mrnugget added a commit that referenced this pull request Oct 12, 2020
* First try to add progress with status bars

* Refactoring and renaming

* Tiny step and refactoring

* Get ProgressWithStatusBars working

* Change API of progressWithStatusbars

* Refactor StatusBar printing

* Embed ProgressTTY in ProgressWithStatusBarsTTY

* More merging of progressTTY and progressWithStatusbarsTTY

* Add simple progress with status bars

* Move demo of progress with bars to _examples

* Restore overwritten methods

* Restore more overwritten methods

* Restore another overwritten method

* WIP: Wire up status bars with executor

* Print status bars below progress bar and add ASCII box characters

* WIP1: Introduce campaign progress printer

* WIP2: More refactoring of campaign status printing

* More cleanup and refactoring

* Change styling of progress bar with status

* Add time to StatusBar and display right-aligned

* Use a const

* Add CHANGELOG entry

* Ignore invisible characters for text length in progress bar

* Update CHANGELOG.md

Co-authored-by: Adam Harvey <aharvey@sourcegraph.com>

* Erase previous content with spaces on blank line

* Thin box drawing lines

* Improve non-TTY output for progress indicators with status bars.

Co-authored-by: Adam Harvey <aharvey@sourcegraph.com>
Co-authored-by: Adam Harvey <adam@adamharvey.name>
mrnugget added a commit that referenced this pull request Oct 12, 2020
* Add 'campaigns new' command

* Print success message

* Update cmd/src/campaigns_new.go

Co-authored-by: Adam Harvey <aharvey@sourcegraph.com>

* Show current worker goroutine status below progress bar (#338)

* First try to add progress with status bars

* Refactoring and renaming

* Tiny step and refactoring

* Get ProgressWithStatusBars working

* Change API of progressWithStatusbars

* Refactor StatusBar printing

* Embed ProgressTTY in ProgressWithStatusBarsTTY

* More merging of progressTTY and progressWithStatusbarsTTY

* Add simple progress with status bars

* Move demo of progress with bars to _examples

* Restore overwritten methods

* Restore more overwritten methods

* Restore another overwritten method

* WIP: Wire up status bars with executor

* Print status bars below progress bar and add ASCII box characters

* WIP1: Introduce campaign progress printer

* WIP2: More refactoring of campaign status printing

* More cleanup and refactoring

* Change styling of progress bar with status

* Add time to StatusBar and display right-aligned

* Use a const

* Add CHANGELOG entry

* Ignore invisible characters for text length in progress bar

* Update CHANGELOG.md

Co-authored-by: Adam Harvey <aharvey@sourcegraph.com>

* Erase previous content with spaces on blank line

* Thin box drawing lines

* Improve non-TTY output for progress indicators with status bars.

Co-authored-by: Adam Harvey <aharvey@sourcegraph.com>
Co-authored-by: Adam Harvey <adam@adamharvey.name>

* Incorporate feedback

* Change placeholders in campaign skeleton

Co-authored-by: Adam Harvey <aharvey@sourcegraph.com>
Co-authored-by: Adam Harvey <adam@adamharvey.name>
scjohns pushed a commit that referenced this pull request Apr 24, 2023
* First try to add progress with status bars

* Refactoring and renaming

* Tiny step and refactoring

* Get ProgressWithStatusBars working

* Change API of progressWithStatusbars

* Refactor StatusBar printing

* Embed ProgressTTY in ProgressWithStatusBarsTTY

* More merging of progressTTY and progressWithStatusbarsTTY

* Add simple progress with status bars

* Move demo of progress with bars to _examples

* Restore overwritten methods

* Restore more overwritten methods

* Restore another overwritten method

* WIP: Wire up status bars with executor

* Print status bars below progress bar and add ASCII box characters

* WIP1: Introduce campaign progress printer

* WIP2: More refactoring of campaign status printing

* More cleanup and refactoring

* Change styling of progress bar with status

* Add time to StatusBar and display right-aligned

* Use a const

* Add CHANGELOG entry

* Ignore invisible characters for text length in progress bar

* Update CHANGELOG.md

Co-authored-by: Adam Harvey <aharvey@sourcegraph.com>

* Erase previous content with spaces on blank line

* Thin box drawing lines

* Improve non-TTY output for progress indicators with status bars.

Co-authored-by: Adam Harvey <aharvey@sourcegraph.com>
Co-authored-by: Adam Harvey <adam@adamharvey.name>
scjohns pushed a commit that referenced this pull request Apr 24, 2023
* Add 'campaigns new' command

* Print success message

* Update cmd/src/campaigns_new.go

Co-authored-by: Adam Harvey <aharvey@sourcegraph.com>

* Show current worker goroutine status below progress bar (#338)

* First try to add progress with status bars

* Refactoring and renaming

* Tiny step and refactoring

* Get ProgressWithStatusBars working

* Change API of progressWithStatusbars

* Refactor StatusBar printing

* Embed ProgressTTY in ProgressWithStatusBarsTTY

* More merging of progressTTY and progressWithStatusbarsTTY

* Add simple progress with status bars

* Move demo of progress with bars to _examples

* Restore overwritten methods

* Restore more overwritten methods

* Restore another overwritten method

* WIP: Wire up status bars with executor

* Print status bars below progress bar and add ASCII box characters

* WIP1: Introduce campaign progress printer

* WIP2: More refactoring of campaign status printing

* More cleanup and refactoring

* Change styling of progress bar with status

* Add time to StatusBar and display right-aligned

* Use a const

* Add CHANGELOG entry

* Ignore invisible characters for text length in progress bar

* Update CHANGELOG.md

Co-authored-by: Adam Harvey <aharvey@sourcegraph.com>

* Erase previous content with spaces on blank line

* Thin box drawing lines

* Improve non-TTY output for progress indicators with status bars.

Co-authored-by: Adam Harvey <aharvey@sourcegraph.com>
Co-authored-by: Adam Harvey <adam@adamharvey.name>

* Incorporate feedback

* Change placeholders in campaign skeleton

Co-authored-by: Adam Harvey <aharvey@sourcegraph.com>
Co-authored-by: Adam Harvey <adam@adamharvey.name>
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.

5 participants