X Tutup
The Wayback Machine - https://web.archive.org/web/20200911235548/https://github.com/cli/cli/pull/1049
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

hackday: gh repo garden #1049

Open
wants to merge 14 commits into
base: trunk
from
Open

hackday: gh repo garden #1049

wants to merge 14 commits into from

Conversation

@vilmibm
Copy link
Member

vilmibm commented May 29, 2020

For this hackday I wanted to create something interactive that was unique to a given repository. As
a big fan of games like Angband I decided to make a repository a top down thing that can be explored. I wanted to convey a sense of people coming together to make something that they couldn't do on their own, so I chose to render a repo's commits as a garden of colorful flowers. The color of each flower is the first 6 characters of a commit's SHA interpreted as a hex code; the character of each flower is the first letter of a commiter's GitHub handle.

garden5

In addition to the commit flowers, there's:

  • a border of trees
  • a randomly placed stream
  • a sign saying the name of the repo

Considerations

  • The flowers are placed randomly but the random seed is based on the repo name; that means that two people looking at the garden for the same repo will see the same layout but each repo's layout is different.
  • This takes advantage of modern terminals' support for 24 bit color. I added utils.RGB(r,g,b,s)
    which can output text of any RGB color. I used this to more accurately convert SHAs to color and
    also to make a gradient fill for the stream.
  • Like my last hack day project, I did not introduce any new third party libraries
  • This uses the GitHub API to get commits. I started out using git log which is nice and fast
    but this meant you couldn't generate a garden for an arbitrary repository; it also meant that
    getting the GitHub handle for a committer was challenging. Using the API is a little slow but I'm
    happier with the results.

Future directions

I'd like to render a much larger space that can be panned around while the user moves. Given a
larger space, I'd render more about a given repository: projects as monuments, closed issues as
graves, contributors as wandering NPCs, etc.

I'd also like to animate it when the user is standing still. Right now it only redraws when the user
moves. I want the stream to twinkle and the grass to move in the wind.

@vilmibm vilmibm force-pushed the garden branch from 1b6fb01 to 3355e69 Jun 12, 2020
@vilmibm vilmibm marked this pull request as ready for review Jun 25, 2020
@vilmibm vilmibm requested review from mislav and probablycorey Jun 25, 2020
Copy link
Member

mislav left a comment

I would love to see this merged! I'm sorry for the late review.

Since this is likely something that we would ship once and avoid refactoring too much, I think it would be beneficial if it was in its own package. Would you be open to moving the implementation to under pkg/cmd/repo/garden/ and for it to use a raw HTTP client directly (like api command does) rather than adding an extra method to the api package? It might be a nice pairing project for us; let me know!

@leereilly
Copy link
Contributor

leereilly commented Aug 8, 2020

SHA-mazing! 😍

If you're looking for an excuse to demo this, and/or watch a whole bunch of talks from fellow Roguelike developers and players, the Roguelike Celebration (usually hosted at GitHub HQ) might still be looking for presenters. I know the organizers well if you'd like an intro!

Check out the videos from yesteryear on YouTube.

@vilmibm
Copy link
Member Author

vilmibm commented Aug 12, 2020

@leereilly oh awesome! Thanks for suggesting that! I've watched videos from that event in the past.

This is a humble little thing and I don't think I could spin it into a talk of any significant length. It might be suitable for a lightning talk; alternatively I can submit next time around once it's more fleshed out.

@vilmibm vilmibm added the hack label Aug 19, 2020
@vilmibm vilmibm added this to Backlog 🗒 in The GitHub CLI via automation Aug 19, 2020
@vilmibm vilmibm moved this from Backlog 🗒 to In progress 🚧 in The GitHub CLI Aug 19, 2020
vilmibm added 11 commits Aug 25, 2020
@vilmibm
Copy link
Member Author

vilmibm commented Aug 25, 2020

@mislav sorry, I totally missed your review 🤦 I've removed the additional method from api.client and isolated this command entirely in its own package in the new command format.

@vilmibm vilmibm requested review from mislav and removed request for probablycorey Aug 25, 2020
@vilmibm vilmibm moved this from In progress 🚧 to Needs review 🤔 in The GitHub CLI Aug 25, 2020
@vilmibm
Copy link
Member Author

vilmibm commented Aug 27, 2020

ok, this works fine on macos now 👍

pkg/cmd/repo/garden/garden.go Outdated Show resolved Hide resolved
Co-authored-by: Lee Reilly <lee@github.com>
Copy link
Member

mislav left a comment

Couple of minor points before this ships

}

func getResponse(client *http.Client, path string, data interface{}) (*http.Response, error) {
url := "https://api.github.com/" + path

This comment has been minimized.

@mislav

mislav Sep 9, 2020

Member

Tip: you can use ghrepo.RESTPrefix() here to gain support for GHE repos

// TODO fix arrow keys

func isLeft(b []byte) bool {
return bytes.EqualFold(b, []byte("a")) || bytes.EqualFold(b, []byte("q")) || bytes.EqualFold(b, []byte("h"))

This comment has been minimized.

@mislav

mislav Sep 9, 2020

Member

If q is Left now, how do we exit the garden?

This comment has been minimized.

@leereilly

leereilly Sep 9, 2020

Contributor

The only way I can exit (on macOS at least) seems to be CTRL C.
That seems acceptable / consistent with gh credits? Q doesn't work for me there either FWIW.

lines = append(lines, "( <3 press ctrl-c to quit <3 )")

This comment has been minimized.

@vilmibm

vilmibm Sep 10, 2020

Author Member

just switching to ctrl+c for quitting seems ok to me

This comment has been minimized.

@mislav

mislav Sep 11, 2020

Member

Sure! I was simply asking about q since it was documented as an exit technique for the garden.

Ctrl-C works, but does not print the nice exit message:

You turn and walk away from the wildflower garden…

break
}

clear(opts.IO)

This comment has been minimized.

@mislav

mislav Sep 9, 2020

Member

I realize that this would add some complexity, but is there a chance you could use cursor positioning to only redraw the 1–2 rows of the garden around the player's current position after a move (plus the status line in the bottom)? Redrawing the whole garden in iTerm2 for me makes the bottom few rows of the garden flicker for me, which is not a huge deal but it does make for a slightly worse experience, especially because it also causes the status line to flicker, which makes the text harder to read while I'm walking around.

This comment has been minimized.

@vilmibm

vilmibm Sep 10, 2020

Author Member

the flickering is present in all platforms; only redrawing the current rows is a great improvement that i just haven't made time to do.

This comment has been minimized.

@mislav

mislav Sep 11, 2020

Member

Yeah, I realize how that delays the whole PR. Let's keep that as a potential improvement for later.

It's not that I feel very strongly that the garden always needs to render super smooth, but I think it would be valuable for us to learn how to position cursor in the terminal in general in case we ever need it in other commands or while redoing prompts in a more accessible manner.

}

quitting := false
switch {

This comment has been minimized.

@mislav

mislav Sep 9, 2020

Member

Could we add a default: case to this switch statement that just skips to the next loop iteration without redrawing the garden? That would avoid re-rendering the garden on invalid keystrokes such as arrow keys

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
The GitHub CLI
  
Needs review 🤔
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.
X Tutup