lib/snibbets.rb in snibbets-2.0.32 vs lib/snibbets.rb in snibbets-2.0.33

- old
+ new

@@ -10,10 +10,11 @@ require 'shellwords' require 'tty-reader' require 'tty-which' require 'yaml' require_relative 'snibbets/version' +require_relative 'snibbets/colors' require_relative 'snibbets/config' require_relative 'snibbets/which' require_relative 'snibbets/string' require_relative 'snibbets/hash' require_relative 'snibbets/array' @@ -82,11 +83,11 @@ %(mdfind -onlyin #{folder} #{name_only}'#{@query} filename:.#{ext}' 2>/dev/null) end end if try == 2 && cmd.nil? - puts "No search method available on this system. Please install ripgrep, silver surfer, ack, or grep." + puts "{br}No search method available on this system. Please install ripgrep, silver surfer, ack, or grep.".x Process.exit 1 end res = cmd.nil? ? '' : `#{cmd}`.strip @@ -136,18 +137,18 @@ `open -a "#{editor}" "#{filepath}"` elsif TTY::Which.exist?(editor) editor = TTY::Which.which(editor) system %(#{editor} "#{filepath}") if editor else - puts "No editor configured, or editor is missing" + puts "{br}No editor configured, or editor is missing".x Process.exit 1 end elsif TTY::Which.exist?(editor) editor = TTY::Which.which(editor) system %(#{editor} "#{filepath}") if editor else - puts "No editor configured, or editor is missing" + puts "{br}No editor configured, or editor is missing".x Process.exit 1 end end end @@ -161,34 +162,34 @@ pb = OS.paste.outdent reader = TTY::Reader.new # printf 'What does this snippet do? ' - input = reader.read_line('What does this snippet do? ').strip + input = reader.read_line('{by}What does this snippet do{bw}? '.x).strip # input = $stdin.gets.chomp title = input unless input.empty? # printf 'What language(s) does it use (separate with spaces, full names or file extensions will work)? ' - input = reader.read_line('What language(s) does it use (separate with spaces, full names or file extensions will work)? ').strip + input = reader.read_line('{by}What language(s) does it use ({xw}separate with spaces, full names or file extensions{by}){bw}? '.x).strip # input = $stdin.gets.chomp langs = input.split(/ +/).map(&:strip) unless input.empty? exts = langs.map { |lang| Lexers.lang_to_ext(lang) }.delete_if(&:nil?) tags = langs.map { |lang| Lexers.ext_to_lang(lang) }.concat(langs).delete_if(&:nil?).sort.uniq exts = langs if exts.empty? - filename = "#{title}#{exts.map { |x| ".#{x}"}.join('')}.#{Snibbets.options[:extension]}" + filename = "#{title}#{exts.map { |x| ".#{x}" }.join('')}.#{Snibbets.options[:extension]}" filepath = File.join(File.expand_path(Snibbets.options[:source]), filename) File.open(filepath, 'w') do |f| f.puts "tags: #{tags.join(', ')} ``` #{pb} ```" end - puts "New snippet written to #{filename}." + puts "{bg}New snippet written to {bw}#{filename}.".x open_snippet_in_editor(filepath) if Snibbets.arguments[:edit_snippet] open_snippet_in_nvultra(filepath) if Snibbets.arguments[:nvultra] end @@ -278,12 +279,12 @@ print(snippets.to_json, filepath) else snippets.each do |snip| header = File.basename(filepath, '.md') if $stdout.isatty - puts header - puts '-' * header.length + puts "{bw}#{header}{x}".x + puts "{dw}#{'-' * header.length}{x}".x puts '' end code = snip['code'] lang = snip['language'] @@ -309,21 +310,21 @@ if Snibbets.options[:output] == 'json' print(snippets.to_json, filepath) else if $stdout.isatty header = File.basename(filepath, '.md') - warn header - warn '=' * header.length + warn "{bw}#{header}{x}".x + warn "{dw}#{'=' * header.length}{x}".x warn '' end print_all(snippets, filepath) end elsif Snibbets.options[:output] == 'json' print(answer.to_json, filepath) else if $stdout.isatty - header = "#{File.basename(filepath, '.md')}: #{answer['title']}" + header = "{bw}#{File.basename(filepath, '.md')}: {c}#{answer['title']}{x}".x warn header warn '-' * header.length warn '' end code = answer['code'] @@ -338,10 +339,10 @@ else snippets.each do |snippet| lang = snippet['language'] - puts "### #{snippet['title']} ###" + puts "{dw}### {xbw}#{snippet['title']} {xdw}### {x}".x puts '' print(snippet['code'], filepath, lang) puts end