diff --git a/cmd/nubi.go b/cmd/nubi.go index f56e164..4a35381 100644 --- a/cmd/nubi.go +++ b/cmd/nubi.go @@ -13,6 +13,7 @@ import ( "syscall" "time" + "github.com/atotto/clipboard" "github.com/briandowns/spinner" "github.com/c-bata/go-prompt" "github.com/charmbracelet/glamour" @@ -35,6 +36,7 @@ var suggestions = []prompt.Suggest{ {Text: "/agents", Description: "List available agents"}, {Text: "/tools", Description: "List available tools"}, {Text: "/functions", Description: "List available functions"}, + {Text: "/copy", Description: "Copy the last response to clipboard"}, {Text: "/exit", Description: "Exit the Nubi shell"}, } @@ -159,6 +161,7 @@ type nubiShell struct { history []string waitingMessageID string waitingAgentID string + lastResponse string } type MessageConfig struct { @@ -239,6 +242,8 @@ func (s *nubiShell) executor(in string) { return } + s.lastResponse = response + if status == "WAITING" { fmt.Println(response) } else { @@ -414,6 +419,16 @@ func (s *nubiShell) handleSlashCommand(in string) { {Header: "VARIABLES", Field: "Variables"}, }, }) + case "/copy": + if s.lastResponse == "" { + fmt.Println("Nothing to copy.") + return + } + if err := clipboard.WriteAll(s.lastResponse); err != nil { + fmt.Printf("Error copying to clipboard: %v\n", err) + } else { + fmt.Println("Copied to clipboard!") + } case "/exit": fmt.Println("Goodbye!") os.Exit(0) diff --git a/go.mod b/go.mod index f82b636..b2fcc3b 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module github.com/nudgebee/nbctl go 1.25.1 require ( + github.com/atotto/clipboard v0.1.4 github.com/briandowns/spinner v1.23.2 github.com/c-bata/go-prompt v0.2.6 github.com/charmbracelet/glamour v0.10.0 diff --git a/go.sum b/go.sum index d35cd85..fcb80c6 100644 --- a/go.sum +++ b/go.sum @@ -4,6 +4,8 @@ github.com/alecthomas/chroma/v2 v2.14.0 h1:R3+wzpnUArGcQz7fCETQBzO5n9IMNi13iIs46 github.com/alecthomas/chroma/v2 v2.14.0/go.mod h1:QolEbTfmUHIMVpBqxeDnNBj2uoeI4EbYP4i6n68SG4I= github.com/alecthomas/repr v0.4.0 h1:GhI2A8MACjfegCPVq9f1FLvIBS+DrQ2KQBFZP1iFzXc= github.com/alecthomas/repr v0.4.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4= +github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4= +github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI= github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k= github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8= github.com/aymanbagabas/go-udiff v0.2.0 h1:TK0fH4MteXUDspT88n8CKzvK0X9O2xu9yQjWpi6yML8=