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
43 changes: 23 additions & 20 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,21 @@ import (
"runtime/pprof"
"time"

tea "charm.land/bubbletea/v2"
"charm.land/lipgloss/v2"
"charm.land/log/v2"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/fang"
zone "github.com/lrstanley/bubblezone/v2"
"github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/log"
zone "github.com/lrstanley/bubblezone"
"github.com/muesli/termenv"
"github.com/spf13/cobra"

"github.com/dlvhdr/gh-dash/v4/internal/config"
"github.com/dlvhdr/gh-dash/v4/internal/git"
"github.com/dlvhdr/gh-dash/v4/internal/provider"
"github.com/dlvhdr/gh-dash/v4/internal/tui"
"github.com/dlvhdr/gh-dash/v4/internal/tui/constants"
dctx "github.com/dlvhdr/gh-dash/v4/internal/tui/context"
"github.com/dlvhdr/gh-dash/v4/internal/tui/markdown"
)

var (
Expand All @@ -42,9 +45,9 @@ var (
rootCmd = &cobra.Command{
Use: "gh dash",
Long: lipgloss.JoinVertical(lipgloss.Left, logo.Render(),
"A rich terminal UI for GitHub that doesn't break your flow.",
"A rich terminal UI for GitHub/GitLab that doesn't break your flow.",
"Visit https://gh-dash.dev for the docs."),
Short: "A rich terminal UI for GitHub that doesn't break your flow.",
Short: "A rich terminal UI for GitHub/GitLab that doesn't break your flow.",
Version: "",
Example: `
# Running without arguments will either:
Expand All @@ -66,13 +69,8 @@ gh dash -v
)

func Execute() {
if err := fang.Execute(
context.Background(),
rootCmd,
fang.WithVersion(rootCmd.Version),
fang.WithoutCompletions(),
fang.WithoutManpage(),
); err != nil {
if err := fang.Execute(context.Background(), rootCmd, fang.WithVersion(rootCmd.Version),
fang.WithoutCompletions(), fang.WithoutManpage()); err != nil {
os.Exit(1)
}
}
Expand Down Expand Up @@ -131,12 +129,7 @@ func buildVersion(version, commit, date, builtBy string) string {
}
result = fmt.Sprintf("%s\ngoos: %s\ngoarch: %s", result, runtime.GOOS, runtime.GOARCH)
if info, ok := debug.ReadBuildInfo(); ok && info.Main.Sum != "" {
result = fmt.Sprintf(
"%s\nmodule version: %s, checksum: %s",
result,
info.Main.Version,
info.Main.Sum,
)
result = fmt.Sprintf("%s\nmodule version: %s, checksum: %s", result, info.Main.Version, info.Main.Sum)
}

return result
Expand Down Expand Up @@ -183,6 +176,7 @@ func init() {
)

rootCmd.Run = func(_ *cobra.Command, args []string) {
provider.SetProvider(provider.NewGitHubProvider())
var repo string
repos := config.IsFeatureEnabled(config.FF_REPO_VIEW)
if repos && len(args) > 0 {
Expand All @@ -202,6 +196,10 @@ func init() {

zone.NewGlobal()

// see https://github.com/charmbracelet/lipgloss/issues/73
lipgloss.SetHasDarkBackground(termenv.HasDarkBackground())
markdown.InitializeMarkdownStyle(termenv.HasDarkBackground())

model, logger := createModel(config.Location{RepoPath: repo, ConfigFlag: cfgFlag}, debug)
if logger != nil {
defer logger.Close()
Expand All @@ -220,7 +218,12 @@ func init() {
defer pprof.StopCPUProfile()
}

p := tea.NewProgram(model)
p := tea.NewProgram(
model,
tea.WithAltScreen(),
tea.WithReportFocus(),
tea.WithMouseCellMotion(),
)
if _, err := p.Run(); err != nil {
log.Fatal("Failed starting the TUI", err)
}
Expand Down
54 changes: 54 additions & 0 deletions internal/provider/github.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package provider

// GitHubProvider implements the Provider interface for GitHub
// GitHub uses the gh CLI and the existing data package functions
type GitHubProvider struct {
host string
}

// NewGitHubProvider creates a new GitHub provider
func NewGitHubProvider() *GitHubProvider {
return &GitHubProvider{
host: "github.com",
}
}

func (g *GitHubProvider) GetType() ProviderType {
return GitHub
}

func (g *GitHubProvider) GetHost() string {
return g.host
}

func (g *GitHubProvider) GetCLICommand() string {
return "gh"
}

// FetchPullRequests is not implemented for GitHub provider
// The data package handles GitHub directly
func (g *GitHubProvider) FetchPullRequests(query string, limit int, pageInfo *PageInfo) (PullRequestsResponse, error) {
// This should not be called - data package handles GitHub directly
panic("GitHubProvider.FetchPullRequests should not be called directly")
}

// FetchPullRequest is not implemented for GitHub provider
// The data package handles GitHub directly
func (g *GitHubProvider) FetchPullRequest(prUrl string) (EnrichedPullRequestData, error) {
// This should not be called - data package handles GitHub directly
panic("GitHubProvider.FetchPullRequest should not be called directly")
}

// FetchIssues is not implemented for GitHub provider
// The data package handles GitHub directly
func (g *GitHubProvider) FetchIssues(query string, limit int, pageInfo *PageInfo) (IssuesResponse, error) {
// This should not be called - data package handles GitHub directly
panic("GitHubProvider.FetchIssues should not be called directly")
}

// GetCurrentUser is not implemented for GitHub provider
// The data package handles GitHub directly
func (g *GitHubProvider) GetCurrentUser() (string, error) {
// This should not be called - data package handles GitHub directly
panic("GitHubProvider.GetCurrentUser should not be called directly")
}
39 changes: 39 additions & 0 deletions internal/provider/instance.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package provider

import (
"sync"
)

var (
currentProvider Provider
providerMu sync.RWMutex
)

// SetProvider sets the global provider instance
func SetProvider(p Provider) {
providerMu.Lock()
defer providerMu.Unlock()
currentProvider = p
}

// GetProvider returns the current provider instance
// Defaults to GitHub if not set
func GetProvider() Provider {
providerMu.RLock()
defer providerMu.RUnlock()
if currentProvider == nil {
return NewGitHubProvider()
}
return currentProvider
}

// IsGitHub returns true if the current provider is GitHub
func IsGitHub() bool {
p := GetProvider()
return p.GetType() == GitHub
}

// GetCLICommand returns the CLI command for the current provider
func GetCLICommand() string {
return GetProvider().GetCLICommand()
}
Loading