From 071783d9078d9f52ac73f35c1a777d29052ea0af Mon Sep 17 00:00:00 2001 From: Maas Lalani Date: Fri, 20 Jan 2023 11:06:02 -0500 Subject: feat: copy contents of document (#439) * feat: copy contents of document Co-authored-by: bashbunni * fix: use atotto/clipboard for copying Co-authored-by: bashbunni --- go.mod | 1 + ui/pager.go | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/go.mod b/go.mod index 4dd2577..d09164d 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/ui/pager.go b/ui/pager.go index 0cebdd9..8196761 100644 --- a/ui/pager.go +++ b/ui/pager.go @@ -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" @@ -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 @@ -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", -- cgit v1.2.3