Skip to content

Commit

Permalink
feat: copy contents of document (#439)
Browse files Browse the repository at this point in the history
* feat: copy contents of document

Co-authored-by: bashbunni <bash@charm.sh>

* fix: use atotto/clipboard for copying

Co-authored-by: bashbunni <bash@charm.sh>
  • Loading branch information
maaslalani and bashbunni authored Jan 20, 2023
1 parent 6ba2683 commit 071783d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/charmbracelet/glow
go 1.16

require (
github.com/atotto/clipboard v0.1.4
github.com/charmbracelet/bubbles v0.14.0
github.com/charmbracelet/bubbletea v0.23.1
github.com/charmbracelet/charm v0.8.6
Expand Down
10 changes: 10 additions & 0 deletions ui/pager.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"
"time"

"github.com/atotto/clipboard"
"github.com/charmbracelet/bubbles/spinner"
"github.com/charmbracelet/bubbles/textinput"
"github.com/charmbracelet/bubbles/viewport"
Expand Down Expand Up @@ -289,6 +290,14 @@ func (m pagerModel) update(msg tea.Msg) (pagerModel, tea.Cmd) {
return m, openEditor(m.currentDocument.localPath)
}

case "c":
err := clipboard.WriteAll(m.currentDocument.Body)
if err != nil {
cmds = append(cmds, m.showStatusMessage("Unable to copy contents"))
} else {
cmds = append(cmds, m.showStatusMessage("Copied contents"))
}

case "s":
if m.common.authStatus != authOK {
break
Expand Down Expand Up @@ -536,6 +545,7 @@ func (m pagerModel) helpView() (s string) {
col1 := []string{
"g/home go to top",
"G/end go to bottom",
"c copy contents",
editOrBlank,
memoOrStash,
"esc back to files",
Expand Down

0 comments on commit 071783d

Please sign in to comment.