Module: OllamaChat::KramdownANSI

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

Instance Method Summary collapse

Instance Method Details

#configure_kramdown_ansi_stylesHash

The configure_kramdown_ansi_styles method sets up ANSI styling for Kramdown::ANSI output by checking for specific environment variables and falling back to default styles.

variables or using default settings

Returns:

  • (Hash)

    a hash of ANSI styles configured either from environment



8
9
10
11
12
13
14
# File 'lib/ollama_chat/kramdown_ansi.rb', line 8

def configure_kramdown_ansi_styles
  if env_var = %w[ KRAMDOWN_ANSI_OLLAMA_CHAT_STYLES KRAMDOWN_ANSI_STYLES ].find { ENV.key?(_1) }
    Kramdown::ANSI::Styles.from_env_var(env_var).ansi_styles
  else
    Kramdown::ANSI::Styles.new.ansi_styles
  end
end

#kramdown_ansi_parse(content) ⇒ String

The kramdown_ansi_parse method processes content using Kramdown::ANSI with custom ANSI styles.

This method takes raw content and converts it into formatted ANSI output by applying the instance’s configured ANSI styles. It is used to render content with appropriate terminal formatting based on the application’s styling configuration.

according to the configured styles

Parameters:

  • content (String)

    the raw content to be parsed and formatted

Returns:

  • (String)

    the content formatted with ANSI escape sequences



28
29
30
# File 'lib/ollama_chat/kramdown_ansi.rb', line 28

def kramdown_ansi_parse(content)
  Kramdown::ANSI.parse(content, ansi_styles: @kramdown_ansi_styles)
end