Module: OllamaChat::Clipboard

Included in:
Chat
Defined in:
lib/ollama_chat/clipboard.rb

Instance Method Summary collapse

Instance Method Details

#copy_to_clipboardObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/ollama_chat/clipboard.rb', line 2

def copy_to_clipboard
  if message = @messages.last and message.role == 'assistant'
    copy = `which #{config.copy}`.chomp
    if copy.present?
      IO.popen(copy, 'w') do |clipboard|
        clipboard.write(message.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_inputObject



19
20
21
22
# File 'lib/ollama_chat/clipboard.rb', line 19

def paste_from_input
  STDOUT.puts bold { "Paste your content and then press C-d!" }
  STDIN.read
end