Skip to content

Commit

Permalink
handle error on copy to clipboard
Browse files Browse the repository at this point in the history
  • Loading branch information
dlvhdr committed Feb 16, 2024
1 parent 702b0a6 commit 1b6ddd5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 21 deletions.
15 changes: 1 addition & 14 deletions ui/components/search/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/charmbracelet/bubbles/textinput"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"

"github.com/dlvhdr/gh-dash/ui/context"
)

Expand Down Expand Up @@ -83,20 +84,6 @@ func getInputWidth(ctx *context.ProgramContext, prompt string) int {
return ctx.MainContentWidth - lipgloss.Width(prompt) - 6
}

type SearchCancelled struct {
}

func (m Model) cancelSearch() tea.Msg {
return SearchCancelled{}
}

type SearchSubmitted struct {
}

func (m Model) submitSearch() tea.Msg {
return SearchSubmitted{}
}

func (m Model) Value() string {
return m.textInput.Value()
}
4 changes: 2 additions & 2 deletions ui/components/section/section.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,7 @@ func (m *Model) GetMainContent() string {
}

func (m *Model) View() string {
var search string
search = m.SearchBar.View(*m.Ctx)
search := m.SearchBar.View(*m.Ctx)

return m.Ctx.Styles.Section.ContainerStyle.Copy().Render(
lipgloss.JoinVertical(
Expand Down Expand Up @@ -345,6 +344,7 @@ func (m *Model) GetPagerContent() string {
pager := m.Ctx.Styles.ListViewPort.PagerStyle.Copy().Render(pagerContent)
return pager
}

func (m *Model) GetPromptConfirmation() string {
if m.IsPromptConfirmationShown {
var prompt string
Expand Down
19 changes: 14 additions & 5 deletions ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ type Model struct {
footer footer.Model
prs []section.Section
issues []section.Section
ready bool
tabs tabs.Model
ctx context.ProgramContext
taskSpinner spinner.Model
Expand Down Expand Up @@ -313,14 +312,24 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {

case key.Matches(msg, m.keys.CopyNumber):
number := fmt.Sprint(m.getCurrRowData().GetNumber())
clipboard.WriteAll(number)
cmd := m.notify(fmt.Sprintf("Copied %s to clipboard", number))
err := clipboard.WriteAll(number)
var cmd tea.Cmd
if err != nil {
cmd = m.notify(fmt.Sprintf("Failed copying to clipboard %v", err))
} else {
cmd = m.notify(fmt.Sprintf("Copied %s to clipboard", number))
}
return m, cmd

case key.Matches(msg, m.keys.CopyUrl):
url := m.getCurrRowData().GetUrl()
clipboard.WriteAll(url)
cmd := m.notify(fmt.Sprintf("Copied %s to clipboard", url))
err := clipboard.WriteAll(url)
var cmd tea.Cmd
if err != nil {
cmd = m.notify(fmt.Sprintf("Failed copying to clipboard %v", err))
} else {
cmd = m.notify(fmt.Sprintf("Copied %s to clipboard", url))
}
return m, cmd

case key.Matches(msg, m.keys.Quit):
Expand Down

0 comments on commit 1b6ddd5

Please sign in to comment.