-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Scrollable timeline for latest commits across all repos
- Loading branch information
Toby Padilla
committed
Aug 3, 2021
1 parent
f2794d4
commit ae2a71a
Showing
9 changed files
with
196 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package commits | ||
|
||
import ( | ||
"smoothie/git" | ||
"strings" | ||
|
||
"github.com/charmbracelet/bubbles/viewport" | ||
tea "github.com/charmbracelet/bubbletea" | ||
"github.com/dustin/go-humanize" | ||
) | ||
|
||
type Bubble struct { | ||
Commits []git.RepoCommit | ||
Margin int | ||
Width int | ||
Height int | ||
viewport viewport.Model | ||
} | ||
|
||
func NewBubble(height int, margin int, width int, rcs []git.RepoCommit) *Bubble { | ||
b := &Bubble{ | ||
Commits: rcs, | ||
viewport: viewport.Model{Height: height - margin, Width: width}, | ||
} | ||
s := "" | ||
for _, rc := range rcs { | ||
s += b.renderCommit(rc) + "\n" | ||
} | ||
b.viewport.SetContent(s) | ||
return b | ||
} | ||
|
||
func (b *Bubble) Init() tea.Cmd { | ||
return nil | ||
} | ||
|
||
func (b *Bubble) Update(msg tea.Msg) (tea.Model, tea.Cmd) { | ||
cmds := make([]tea.Cmd, 0) | ||
switch msg := msg.(type) { | ||
case tea.WindowSizeMsg: | ||
b.viewport.Height = msg.Height - b.Margin | ||
case tea.KeyMsg: | ||
switch msg.String() { | ||
case "up", "k": | ||
b.viewport.LineUp(1) | ||
case "down", "j": | ||
b.viewport.LineDown(1) | ||
} | ||
} | ||
return b, tea.Batch(cmds...) | ||
} | ||
|
||
func (b *Bubble) renderCommit(rc git.RepoCommit) string { | ||
s := "" | ||
s += commitRepoNameStyle.Render(rc.Name) | ||
s += " " | ||
s += commitDateStyle.Render(humanize.Time(rc.Commit.Author.When)) | ||
s += "\n" | ||
s += commitCommentStyle.Render(strings.TrimSpace(rc.Commit.Message)) | ||
s += "\n" | ||
s += commitAuthorStyle.Render(rc.Commit.Author.Name) | ||
s += " " | ||
s += commitAuthorEmailStyle.Render(rc.Commit.Author.Email) | ||
s += " " | ||
return commitBoxStyle.Width(b.viewport.Height).Render(s) | ||
} | ||
|
||
func (b *Bubble) View() string { | ||
return b.viewport.View() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package commits | ||
|
||
import ( | ||
"github.com/charmbracelet/lipgloss" | ||
) | ||
|
||
var commitBoxStyle = lipgloss.NewStyle(). | ||
Foreground(lipgloss.Color("#FFFFFF")). | ||
BorderStyle(lipgloss.RoundedBorder()). | ||
BorderForeground(lipgloss.Color("#670083")). | ||
Padding(1) | ||
var commitRepoNameStyle = lipgloss.NewStyle(). | ||
Foreground(lipgloss.Color("#8922A5")) | ||
var commitAuthorStyle = lipgloss.NewStyle(). | ||
Foreground(lipgloss.Color("#670083")) | ||
var commitAuthorEmailStyle = lipgloss.NewStyle(). | ||
Foreground(lipgloss.Color("#781194")) | ||
var commitDateStyle = lipgloss.NewStyle(). | ||
Foreground(lipgloss.Color("#781194")) | ||
var commitCommentStyle = lipgloss.NewStyle(). | ||
Foreground(lipgloss.Color("#A0A0A0")). | ||
BorderStyle(lipgloss.Border{Left: ">"}). | ||
BorderForeground(lipgloss.Color("#606060")). | ||
PaddingLeft(1). | ||
PaddingBottom(0). | ||
Margin(0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package repo | ||
|
||
import ( | ||
tea "github.com/charmbracelet/bubbletea" | ||
"github.com/go-git/go-git/v5" | ||
) | ||
|
||
type Bubble struct { | ||
repo *git.Repository | ||
} | ||
|
||
func (b *Bubble) Init() tea.Cmd { | ||
return nil | ||
} | ||
|
||
func (b *Bubble) Update(tea.Msg) (tea.Model, tea.Cmd) { | ||
return nil, nil | ||
} | ||
|
||
func (b *Bubble) View() string { | ||
return "repo" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package repo | ||
|
||
import ( | ||
"github.com/charmbracelet/lipgloss" | ||
) | ||
|
||
var commitBoxStyle = lipgloss.NewStyle(). | ||
Foreground(lipgloss.Color("#FFFFFF")). | ||
BorderStyle(lipgloss.RoundedBorder()). | ||
BorderForeground(lipgloss.Color("#670083")). | ||
Padding(1) | ||
var commitRepoNameStyle = lipgloss.NewStyle(). | ||
Foreground(lipgloss.Color("#8922A5")) | ||
var commitAuthorStyle = lipgloss.NewStyle(). | ||
Foreground(lipgloss.Color("#670083")) | ||
var commitAuthorEmailStyle = lipgloss.NewStyle(). | ||
Foreground(lipgloss.Color("#781194")) | ||
var commitDateStyle = lipgloss.NewStyle(). | ||
Foreground(lipgloss.Color("#781194")) | ||
var commitCommentStyle = lipgloss.NewStyle(). | ||
Foreground(lipgloss.Color("#606060")). | ||
BorderStyle(lipgloss.Border{Left: ">"}). | ||
PaddingLeft(1). | ||
PaddingBottom(0). | ||
Margin(0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters