Module: OllamaChat::Clipboard
- Included in:
- Chat
- Defined in:
- lib/ollama_chat/clipboard.rb
Overview
A module that provides clipboard functionality for copying and pasting chat messages.
This module enables users to copy the last assistant message to the system clipboard and paste content from input, facilitating easy transfer of conversation content between different applications and contexts.
Instance Method Summary collapse
-
#perform_copy_to_clipboard(text: nil, content: false) ⇒ Object
Copies the last assistant message to the system clipboard.
-
#perform_paste_from_clipboard ⇒ String
Performs the actual clipboard paste operation.
Instance Method Details
#perform_copy_to_clipboard(text: nil, content: false) ⇒ Object
Copies the last assistant message to the system clipboard.
This method finds the most recent message from the assistant and writes its content to the system clipboard using the command specified in the configuration (config.copy).
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ollama_chat/clipboard.rb', line 21 def perform_copy_to_clipboard(text: nil, content: false) text ||= (content:) if text copy = `which #{config.copy}`.chomp if copy.present? IO.popen(copy, 'w') do |clipboard| clipboard.write(text) end true else raise OllamaChat::OllamaChatError, "#{config.copy.inspect} command not found in system's path!" end else raise OllamaChat::OllamaChatError, "No text available to copy to the system clipboard." end end |
#perform_paste_from_clipboard ⇒ String
Performs the actual clipboard paste operation.
This method executes the configured clipboard paste command to retrieve content from the system clipboard. It uses the command specified in the configuration (‘config.paste`) to fetch clipboard content.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/ollama_chat/clipboard.rb', line 54 def perform_paste_from_clipboard paste = `which #{config.paste}`.chomp if paste.present? IO.popen(paste, 'r') do |clipboard| text = clipboard.read if text.empty? raise OllamaChat::OllamaChatError, "No content available to paste from the system clipboard." else return text end end else raise OllamaChat::OllamaChatError, "#{config.paste.inspect} command not found in system's path!" end end |