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.



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

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

Instance Method Details

#call(response) ⇒ Object



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

def call(response)
  if content = response.response || response.message&.content
    @content << content
    markdown_content = Kramdown::ANSI.parse(@content)
    @output.print clear_screen, move_home, markdown_content
  end
  self
end