Skip to content

Instantly share code, notes, and snippets.

@SaladFork
Created August 7, 2017 22:23
Show Gist options
  • Save SaladFork/6845b69539e06e68a3a731d1f280a777 to your computer and use it in GitHub Desktop.
Save SaladFork/6845b69539e06e68a3a731d1f280a777 to your computer and use it in GitHub Desktop.
Powerline-like prompt for Pry
class Pry
class Prompt
SEPARATOR = "\ue0b0".freeze
def self.powerline_prompt(obj, nest_level, pry, wait)
[
Pry::Helpers::Text.cyan(" #{pry.input_array.size} "),
Pry::Helpers::Text.black_on_blue(SEPARATOR),
Pry::Helpers::Text.black_on_blue(" #{Pry.config.prompt_name} "),
Pry::Helpers::Text.blue_on_green(SEPARATOR),
Pry::Helpers::Text.black_on_green(" #{RUBY_ENGINE}-#{RUBY_VERSION} "),
Pry::Helpers::Text.green_on_yellow(SEPARATOR),
Pry::Helpers::Text.black_on_yellow(" #{Pry.view_clip(obj)}#{":#{nest_level}" unless nest_level.zero?} "),
(Pry::Helpers::Text.yellow_on_black(SEPARATOR) unless wait),
].join('')
end
end
module Helpers
module Text
extend self
COLORS.each do |fg_color, fg_value|
# FIXME: n^2 :(
COLORS.each do |bg_color, bg_value|
define_method :"#{fg_color}_on_#{bg_color}" do |text|
"\033[0;#{30 + fg_value};#{40 + bg_value}m#{text}\033[0m"
end
end
end
end
end
end
Pry.prompt = [
proc { |*args| "#{Pry::Prompt.powerline_prompt(*args, false)} " },
proc { |*args| "#{Pry::Prompt.powerline_prompt(*args, true)} " }
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment