Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.DEFAULT_GOAL = build
20000.DEFAULT_GOAL = build

build:
go build -o gh-dash gh-dash.go
Expand Down
Binary file added anim.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 18 additions & 15 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ module github.com/dlvhdr/gh-dash
go 1.17

require (
github.com/charmbracelet/bubbles v0.10.3
github.com/charmbracelet/bubbletea v0.20.0
github.com/charmbracelet/bubbles v0.13.0
github.com/charmbracelet/bubbletea v0.22.1
github.com/charmbracelet/glamour v0.5.0
github.com/charmbracelet/lipgloss v0.5.0
github.com/cli/go-gh v0.0.3
github.com/cli/go-gh v0.1.0
github.com/cli/shurcooL-graphql v0.0.1
github.com/go-playground/validator/v10 v10.11.0
github.com/muesli/termenv v0.12.0
gopkg.in/yaml.v2 v2.4.0
)

Expand All @@ -18,28 +20,29 @@ require (
github.com/aymerick/douceur v0.2.0 // indirect
github.com/cli/safeexec v1.0.0 // indirect
github.com/containerd/console v1.0.3 // indirect
github.com/dlclark/regexp2 v1.4.0 // indirect
github.com/dlclark/regexp2 v1.7.0 // indirect
github.com/go-playground/locales v0.14.0 // indirect
github.com/go-playground/universal-translator v0.18.0 // indirect
github.com/go-playground/validator/v10 v10.11.0 // indirect
github.com/gorilla/css v1.0.0 // indirect
github.com/henvic/httpretty v0.1.0 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/microcosm-cc/bluemonday v1.0.18 // indirect
github.com/microcosm-cc/bluemonday v1.0.19 // indirect
github.com/muesli/ansi v0.0.0-20211031195517-c9f0611b6c70 // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/reflow v0.3.0 // indirect
github.com/muesli/termenv v0.11.1-0.20220212125758-44cd13922739 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/yuin/goldmark v1.4.12 // indirect
github.com/rivo/uniseg v0.3.4 // indirect
github.com/thlib/go-timezone-local v0.0.0-20210907160436-ef149e42d28e // indirect
github.com/yuin/goldmark v1.4.13 // indirect
github.com/yuin/goldmark-emoji v1.0.1 // indirect
golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3 // indirect
golang.org/x/net v0.0.0-20220513224357-95641704303c // indirect
golang.org/x/sys v0.0.0-20220513210249-45d2b4557a2a // indirect
golang.org/x/term v0.0.0-20220411215600-e5f449aeb171 // indirect
golang.org/x/crypto v0.0.0-20220826181053-bd7e27e6170d // indirect
golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b // indirect
golang.org/x/sys v0.0.0-20220825204002-c680a09ffe64 // indirect
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035 // indirect
golang.org/x/text v0.3.7 // indirect
gopkg.in/yaml.v3 v3.0.0-20220512140231-539c8e751b99 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
86 changes: 52 additions & 34 deletions go.sum

Large diffs are not rendered by default.

42 changes: 35 additions & 7 deletions ui/modelUtils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ package ui

import (
"bytes"
"fmt"
"log"
"os"
"os/exec"
"text/template"

tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/dlvhdr/gh-dash/data"
"github.com/dlvhdr/gh-dash/ui/components/section"
"github.com/dlvhdr/gh-dash/ui/markdown"
)

func (m *Model) getCurrSection() section.Section {
Expand Down Expand Up @@ -55,7 +60,7 @@ type CommandTemplateInput struct {
HeadRefName string
}

func (m *Model) executeKeybinding(key string) {
func (m *Model) executeKeybinding(key string) tea.Cmd {
currRowData := m.getCurrRowData()
for _, keybinding := range m.ctx.Config.Keybindings.Prs {
if keybinding.Key != key {
Expand All @@ -64,12 +69,13 @@ func (m *Model) executeKeybinding(key string) {

switch data := currRowData.(type) {
case *data.PullRequestData:
m.runCustomCommand(keybinding.Command, data)
return m.runCustomCommand(keybinding.Command, data)
}
}
return nil
}

func (m *Model) runCustomCommand(commandTemplate string, prData *data.PullRequestData) {
func (m *Model) runCustomCommand(commandTemplate string, prData *data.PullRequestData) tea.Cmd {
cmd, err := template.New("keybinding_command").Parse(commandTemplate)
if err != nil {
log.Fatal(err)
Expand All @@ -88,9 +94,31 @@ func (m *Model) runCustomCommand(commandTemplate string, prData *data.PullReques
log.Fatal(err)
}

job := exec.Command("/bin/sh", "-c", buff.String())
out, err := job.CombinedOutput()
if err != nil {
log.Fatalf("Got an error while executing command: %s. \nError: %v\n%s", job, err, out)
shell := os.Getenv("SHELL")
if shell == "" {
shell = "sh"
}
c := exec.Command(shell, "-c", buff.String())
return tea.ExecProcess(c, func(err error) tea.Msg {
if err != nil {
mdRenderer := markdown.GetMarkdownRenderer(m.ctx.ScreenWidth)
md, mdErr := mdRenderer.Render(fmt.Sprintf("While running: `%s`", buff.String()))
if mdErr != nil {
return errMsg{mdErr}
}
return errMsg{fmt.Errorf(
lipgloss.JoinVertical(lipgloss.Left,
fmt.Sprintf("Whoops, got an error: %s", err),
md,
),
)}
}
return nil
})

// job := exec.Command("/bin/sh", "-c", buff.String())
// out, err := job.CombinedOutput()
// if err != nil {
// log.Fatalf("Got an error while executing command: %s. \nError: %v\n%s", job, err, out)
// }
}
4 changes: 4 additions & 0 deletions ui/styles/styles.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ var (
BorderTop(true).
BorderStyle(lipgloss.NormalBorder()).
BorderForeground(DefaultTheme.PrimaryBorder)

ErrorStyle = FooterStyle.Copy().
Foreground(DefaultTheme.WarningText).
MaxHeight(FooterHeight)
)
16 changes: 10 additions & 6 deletions ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,17 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {

switch msg := msg.(type) {
case tea.KeyMsg:
m.err = nil

if currSection != nil && currSection.IsSearchFocused() {
cmd = m.updateSection(currSection.GetId(), currSection.GetType(), msg)
return m, cmd
}

switch {
case m.isUserDefinedKeybinding(msg):
m.executeKeybinding(msg.String())
cmd = m.executeKeybinding(msg.String())
return m, cmd

case key.Matches(msg, m.keys.PrevSection):
prevSection := m.getSectionAt(m.getPrevSectionId())
Expand Down Expand Up @@ -184,10 +187,6 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}

func (m Model) View() string {
if m.err != nil {
return m.err.Error()
}

if m.ctx.Config == nil {
return "Reading config...\n"
}
Expand All @@ -208,7 +207,12 @@ func (m Model) View() string {
}
s.WriteString(mainContent)
s.WriteString("\n")
s.WriteString(m.help.View(m.ctx))
if m.err != nil {
s.WriteString(styles.ErrorStyle.Render(m.err.Error()))
} else {
s.WriteString(m.help.View(m.ctx))
}

return s.String()
}

Expand Down