Class: Ollama::Handlers::Markdown

Inherits:
Object
  • Object
show all
Includes:
Concern, Term::ANSIColor
Defined in:
lib/ollama/handlers/markdown.rb

Instance Attribute Summary

Attributes included from Concern

#output, #result

Instance Method Summary collapse

Methods included from Concern

#to_proc

Constructor Details

#initialize(output: $stdout) ⇒ Markdown

Returns a new instance of Markdown.



7
8
9
10
11
# File 'lib/ollama/handlers/markdown.rb', line 7

def initialize(output: $stdout)
  super
  @output.sync = true
  @content = ''
end

Instance Method Details

#call(response) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/ollama/handlers/markdown.rb', line 13

def call(response)
  if content = response.response || response.message&.content
    @content << content
    markdown_content = Ollama::Utils::ANSIMarkdown.parse(@content)
    @output.print clear_screen, move_home, markdown_content
  end
  response.done and @output.puts
  self
end