Commit 3db907b

mo khan <mo@mokhan.ca>
2026-01-15 00:29:42
feat: add support for rendering markdown
1 parent 9c75fae
lib/elelem/agent.rb
@@ -255,7 +255,11 @@ module Elelem
           return { role: "assistant", content: "[Error: #{e.message}]" }
         end
 
-        terminal.say "\nAssistant> #{content}" unless content.to_s.empty?
+        unless content.to_s.empty?
+          terminal.say "\nAssistant>"
+          terminal.say(content, markdown: true)
+        end
+
         api_tool_calls = tool_calls.any? ? format_tool_calls_for_api(tool_calls) : nil
         turn_context << { role: "assistant", content: content, tool_calls: api_tool_calls }.compact
 
lib/elelem/terminal.rb
@@ -15,9 +15,13 @@ module Elelem
       Reline.readline(prompt, true)&.strip
     end
 
-    def say(message)
+    def say(message, markdown: false)
       stop_spinner
-      $stdout.puts message
+      if markdown
+        $stdout.puts TTY::Markdown.parse(message, symbols: :ascii, mode: 16)
+      else
+        $stdout.puts message
+      end
     end
 
     def write(message)
lib/elelem.rb
@@ -15,6 +15,7 @@ require "reline"
 require "set"
 require "thor"
 require "timeout"
+require "tty/markdown"
 
 require_relative "elelem/agent"
 require_relative "elelem/application"
elelem.gemspec
@@ -55,4 +55,5 @@ Gem::Specification.new do |spec|
   spec.add_dependency "set", "~> 1.0"
   spec.add_dependency "thor", "~> 1.0"
   spec.add_dependency "timeout", "~> 0.1"
+  spec.add_dependency "tty-markdown", "~> 0.7"
 end
Gemfile.lock
@@ -17,6 +17,7 @@ PATH
       set (~> 1.0)
       thor (~> 1.0)
       timeout (~> 0.1)
+      tty-markdown (~> 0.7)
 
 GEM
   remote: https://rubygems.org/
@@ -40,6 +41,8 @@ GEM
     json-schema (6.1.0)
       addressable (~> 2.8)
       bigdecimal (>= 3.1, < 5)
+    kramdown (2.5.1)
+      rexml (>= 3.3.9)
     logger (1.7.0)
     net-hippie (1.4.0)
       base64 (~> 0.1)
@@ -55,6 +58,8 @@ GEM
       uri (~> 1.0)
     open3 (0.2.1)
     openssl (3.3.2)
+    pastel (0.8.0)
+      tty-color (~> 0.5)
     pathname (0.4.0)
     pp (0.6.3)
       prettyprint
@@ -70,6 +75,8 @@ GEM
       tsort
     reline (0.6.3)
       io-console (~> 0.5)
+    rexml (3.4.4)
+    rouge (4.7.0)
     rspec (3.13.2)
       rspec-core (~> 3.13.0)
       rspec-expectations (~> 3.13.0)
@@ -85,9 +92,25 @@ GEM
     rspec-support (3.13.6)
     set (1.1.2)
     stringio (3.2.0)
+    strings (0.2.1)
+      strings-ansi (~> 0.2)
+      unicode-display_width (>= 1.5, < 3.0)
+      unicode_utils (~> 1.4)
+    strings-ansi (0.2.0)
     thor (1.5.0)
     timeout (0.6.0)
     tsort (0.2.0)
+    tty-color (0.6.0)
+    tty-markdown (0.7.2)
+      kramdown (>= 1.16.2, < 3.0)
+      pastel (~> 0.8)
+      rouge (>= 3.14, < 5.0)
+      strings (~> 0.2.0)
+      tty-color (~> 0.5)
+      tty-screen (~> 0.8)
+    tty-screen (0.8.2)
+    unicode-display_width (2.6.0)
+    unicode_utils (1.4.0)
     uri (1.1.1)
 
 PLATFORMS