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
-
#copy_to_clipboard ⇒ NilClass
Copy the last assistant’s message to the system clipboard.
-
#paste_from_input ⇒ String
Paste content from the input.
Instance Method Details
#copy_to_clipboard ⇒ NilClass
Copy the last assistant’s message to the system clipboard.
This method checks if there is a last message from an assistant in the ‘@messages` array and copies its content to the clipboard using the specified command from `config.copy`. If no assistant response is available or the clipboard command is not found, appropriate error messages are displayed.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/ollama_chat/clipboard.rb', line 22 def copy_to_clipboard if = @messages.last and .role == 'assistant' copy = `which #{config.copy}`.chomp if copy.present? IO.popen(copy, 'w') do |clipboard| clipboard.write(.content) end STDOUT.puts "The last response has been copied to the system clipboard." else STDERR.puts "#{config.copy.inspect} command not found in system's path!" end else STDERR.puts "No response available to copy to the system clipboard." end nil end |
#paste_from_input ⇒ String
Paste content from the input.
Prompts the user to paste their content and then press C-d (Ctrl+D) to terminate input. Reads all lines from standard input until Ctrl+D is pressed and returns the pasted content as a string.
46 47 48 49 |
# File 'lib/ollama_chat/clipboard.rb', line 46 def paste_from_input STDOUT.puts bold { "Paste your content and then press C-d!" } STDIN.read end |