module CodeSnippet::CLI::Presenters

CLI Presentation functions

Public Class Methods

list_snippets(snippets) click to toggle source
# File lib/code_snippet/cli/presenters.rb, line 24
def self.list_snippets(snippets)
  result_header = %w[NAME LANG PATH]

  results = TTY::Table.new(
    result_header,
    snippets.map do |snippet|
      [
        snippet.name,
        snippet.ext,
        snippet.path
      ]
    end
  )

  CLI.print_message(results.render(:ascii))
end
pick_from(question, snips) click to toggle source
# File lib/code_snippet/cli/presenters.rb, line 9
def self.pick_from(question, snips)
  prompt = TTY::Prompt.new

  choice = prompt.select(
    question,
    snips.map(&:path)
  )

  snips.find { |snip| snip.path == choice }
end
show(snip) click to toggle source
# File lib/code_snippet/cli/presenters.rb, line 20
def self.show(snip)
  CLI.print_message(snip.content)
end