pry-theme 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +1 -0
- data/.travis.yml +8 -1
- data/CHANGELOG.md +40 -0
- data/Gemfile +1 -1
- data/README.md +26 -48
- data/Rakefile +10 -1
- data/VERSION +1 -0
- data/lib/pry-theme/basic_editor.rb +116 -0
- data/lib/pry-theme/color.rb +431 -0
- data/lib/pry-theme/color_table.rb +39 -0
- data/lib/pry-theme/colors/color16.rb +35 -0
- data/lib/pry-theme/colors/color256.rb +30 -0
- data/lib/pry-theme/colors/color8.rb +31 -0
- data/lib/pry-theme/commands.rb +237 -275
- data/lib/pry-theme/declaration.rb +120 -0
- data/lib/pry-theme/definition.rb +111 -0
- data/lib/pry-theme/formattable.rb +26 -0
- data/lib/pry-theme/hex.rb +76 -0
- data/lib/pry-theme/preview.rb +74 -0
- data/lib/pry-theme/rgb.rb +238 -13
- data/lib/pry-theme/term.rb +66 -0
- data/lib/pry-theme/theme.rb +116 -26
- data/lib/pry-theme/theme_list.rb +52 -0
- data/lib/pry-theme/when_started_hook.rb +25 -27
- data/lib/pry-theme.rb +84 -158
- data/pry-theme.gemspec +14 -18
- data/spec/color_table.rb +53 -0
- data/spec/colors/color16_spec.rb +255 -0
- data/spec/colors/color256_spec.rb +323 -0
- data/spec/colors/color8_spec.rb +254 -0
- data/spec/commands_spec.rb +203 -0
- data/spec/helper.rb +16 -0
- data/spec/hex_spec.rb +52 -0
- data/spec/rgb_spec.rb +81 -0
- data/spec/term_spec.rb +23 -0
- data/spec/theme_spec.rb +486 -0
- data/themes/github.prytheme.rb +49 -0
- data/themes/monokai.prytheme.rb +48 -0
- data/themes/pry-classic-16.prytheme.rb +48 -0
- data/themes/pry-classic-256.prytheme.rb +48 -0
- data/themes/pry-classic-8.prytheme.rb +48 -0
- data/themes/pry-cold.prytheme.rb +49 -0
- data/themes/pry-love-16.prytheme.rb +48 -0
- data/themes/pry-love-8.prytheme.rb +48 -0
- data/themes/pry-modern-16.prytheme.rb +48 -0
- data/themes/pry-modern-256.prytheme.rb +48 -0
- data/themes/pry-modern-8.prytheme.rb +48 -0
- data/themes/pry-monochrome.prytheme.rb +32 -0
- data/themes/pry-siberia-16.prytheme.rb +48 -0
- data/themes/pry-siberia-8.prytheme.rb +48 -0
- data/themes/pry-tepid-16.prytheme.rb +48 -0
- data/themes/pry-tepid-8.prytheme.rb +48 -0
- data/themes/pry-zealand-16.prytheme.rb +48 -0
- data/themes/pry-zealand-8.prytheme.rb +49 -0
- data/themes/railscasts.prytheme.rb +50 -0
- data/themes/solarized.prytheme.rb +48 -0
- data/themes/tomorrow.prytheme.rb +48 -0
- data/themes/twilight.prytheme.rb +48 -0
- data/themes/vim-default.prytheme.rb +50 -0
- data/themes/vim-detailed.prytheme.rb +50 -0
- data/themes/zenburn.prytheme.rb +48 -0
- metadata +56 -41
- data/lib/pry-theme/color_converter.rb +0 -55
- data/lib/pry-theme/helper.rb +0 -87
- data/lib/pry-theme/palette.rb +0 -85
- data/lib/pry-theme/term_notation.rb +0 -17
- data/lib/pry-theme/version.rb +0 -3
- data/test/fixtures/pry-classic.prytheme +0 -38
- data/test/helper.rb +0 -56
- data/test/test_color_converter.rb +0 -38
- data/test/test_commands.rb +0 -55
- data/test/test_helper.rb +0 -45
- data/test/test_palette.rb +0 -11
- data/themes/github.prytheme +0 -43
- data/themes/monokai.prytheme +0 -42
- data/themes/pry-classic.prytheme +0 -43
- data/themes/pry-cold.prytheme +0 -43
- data/themes/pry-modern.prytheme +0 -42
- data/themes/railscasts.prytheme +0 -44
- data/themes/saturday.prytheme +0 -42
- data/themes/solarized.prytheme +0 -43
- data/themes/tomorrow.prytheme +0 -43
- data/themes/twilight.prytheme +0 -42
- data/themes/vim-default.prytheme +0 -42
- data/themes/vim-detailed.prytheme +0 -42
- data/themes/zenburn.prytheme +0 -43
@@ -0,0 +1,66 @@
|
|
1
|
+
module PryTheme
|
2
|
+
# @since 0.2.0
|
3
|
+
# @api private
|
4
|
+
#
|
5
|
+
# Represents a terminal colour (not ANSI). Checks whether a number fits in its
|
6
|
+
# colour model.
|
7
|
+
class TERM
|
8
|
+
|
9
|
+
# @return [Integer] the values are 8, 16 or 256
|
10
|
+
attr_reader :color_model
|
11
|
+
|
12
|
+
# @param [Integer] value
|
13
|
+
# @param [Integer] color_model
|
14
|
+
def initialize(value, color_model = 256)
|
15
|
+
validate_attrs(value, color_model)
|
16
|
+
@value = value
|
17
|
+
@color_model = color_model
|
18
|
+
end
|
19
|
+
|
20
|
+
# @return [String]
|
21
|
+
def inspect
|
22
|
+
"(TERM-#{ @color_model }: #{ @value })"
|
23
|
+
end
|
24
|
+
|
25
|
+
# @return [Integer]
|
26
|
+
def to_i
|
27
|
+
@value
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
# @param [Integer] value
|
33
|
+
# @param [Integer] color_model
|
34
|
+
# @raise [ArgumentError] if the +value+ isn't a valid Integer (not in
|
35
|
+
# +color_model+ range) or provided incorrect +color_model+
|
36
|
+
# @raise [TypeError] if the +value+ or the +color_model+ isn't an Integer
|
37
|
+
# at all
|
38
|
+
# @return [void]
|
39
|
+
def validate_attrs(value, color_model)
|
40
|
+
fixnums = value.is_a?(Fixnum) && color_model.is_a?(Fixnum)
|
41
|
+
correct_term =
|
42
|
+
if fixnums
|
43
|
+
case color_model
|
44
|
+
when 256 then value.between?(0, 255)
|
45
|
+
when 16 then value.between?(0, 15)
|
46
|
+
when 8 then value.between?(0, 7)
|
47
|
+
else raise ArgumentError,
|
48
|
+
'invalid color model for PryTheme::TERM#new(): ' \
|
49
|
+
"\"#{ color_model }\""
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
return true if fixnums && correct_term
|
54
|
+
|
55
|
+
unless fixnums
|
56
|
+
raise TypeError, "can't convert #{ value.class } into PryTheme::TERM"
|
57
|
+
end
|
58
|
+
|
59
|
+
unless correct_term
|
60
|
+
raise ArgumentError,
|
61
|
+
%|invalid TERM number for PryTheme::TERM#new(): "#{ value }"|
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
data/lib/pry-theme/theme.rb
CHANGED
@@ -1,44 +1,134 @@
|
|
1
1
|
module PryTheme
|
2
|
+
|
3
|
+
# Raised when something goes wrong with Pry Theme themes. It's a general
|
4
|
+
# exception for everything that comes into collision in theme files.
|
5
|
+
ThemeError = Class.new(StandardError)
|
6
|
+
|
7
|
+
# @since 0.2.0
|
8
|
+
# @api private
|
9
|
+
# @see PryTheme::create
|
10
|
+
#
|
11
|
+
# Creates a new Pry Theme theme. This class is not meant for the direct
|
12
|
+
# instantiation. Use {PryTheme::create} instead.
|
2
13
|
class Theme
|
3
14
|
|
4
|
-
|
15
|
+
DEFAULT_CONFIG = {
|
16
|
+
:name => "prytheme-#{ rand(1_000_000_000) }",
|
17
|
+
:color_model => 256,
|
18
|
+
:author => 'Unknown Author',
|
19
|
+
:description => '',
|
20
|
+
}
|
5
21
|
|
6
|
-
|
7
|
-
|
22
|
+
# Matches against valid theme name. It must start with a letter. The letter
|
23
|
+
# case is not important.
|
24
|
+
VALID_NAME = /\A[A-z][A-z0-9-]*\z/i
|
8
25
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
26
|
+
# @return [Theme::Definition] the heart of every theme: the colour
|
27
|
+
# definitions
|
28
|
+
attr_reader :definition
|
29
|
+
|
30
|
+
# @return [Boolean] whether this theme is a current theme
|
31
|
+
attr_reader :active
|
32
|
+
alias_method :active?, :active
|
33
|
+
|
34
|
+
# @see PryTheme::create
|
35
|
+
def initialize(config = {}, &block)
|
36
|
+
@config = DEFAULT_CONFIG.merge(config)
|
37
|
+
@authors = [{ :name => @config[:author] }]
|
38
|
+
@default_author = true
|
39
|
+
@active = false
|
40
|
+
|
41
|
+
validate_config
|
42
|
+
|
43
|
+
instance_eval(&block)
|
44
|
+
end
|
14
45
|
|
15
|
-
|
46
|
+
def author(options = nil)
|
47
|
+
if options
|
48
|
+
if options[:name].length > 32
|
49
|
+
raise PryTheme::ThemeError,
|
50
|
+
"author's name must be no longer than 32 characters"
|
51
|
+
end
|
16
52
|
|
17
|
-
|
18
|
-
|
19
|
-
|
53
|
+
if @default_author
|
54
|
+
@default_author = false
|
55
|
+
@authors[0] = options
|
56
|
+
else
|
57
|
+
@authors << options
|
58
|
+
end
|
59
|
+
end
|
60
|
+
@authors
|
61
|
+
end
|
20
62
|
|
21
|
-
|
22
|
-
if
|
23
|
-
if
|
24
|
-
raise
|
63
|
+
def description(text = nil)
|
64
|
+
if text
|
65
|
+
if text.length > 280
|
66
|
+
raise PryTheme::ThemeError,
|
67
|
+
"description must be no longer than 280 characters"
|
25
68
|
end
|
69
|
+
@config[:description] = text
|
26
70
|
end
|
71
|
+
@config[:description]
|
72
|
+
end
|
73
|
+
|
74
|
+
def define_theme(&block)
|
75
|
+
@definition = Definition.new(color_model, &block)
|
76
|
+
end
|
27
77
|
|
28
|
-
|
29
|
-
@
|
78
|
+
def name
|
79
|
+
@config[:name]
|
30
80
|
end
|
31
81
|
|
32
|
-
def
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
82
|
+
def color_model
|
83
|
+
@config[:color_model]
|
84
|
+
end
|
85
|
+
|
86
|
+
def disable
|
87
|
+
@active = false
|
88
|
+
end
|
89
|
+
|
90
|
+
def activate
|
91
|
+
::CodeRay::Encoders::Terminal::TOKEN_COLORS.merge!(to_coderay)
|
92
|
+
@active = true
|
93
|
+
end
|
94
|
+
|
95
|
+
def to_coderay
|
96
|
+
{}.tap do |coderay|
|
97
|
+
@definition.class.instance_methods(false).each { |attr|
|
98
|
+
attr = attr.to_sym
|
99
|
+
val = @definition.__send__(attr) if @definition
|
100
|
+
|
101
|
+
unless val.kind_of?(Color)
|
102
|
+
coderay[attr] = {}
|
103
|
+
ivars = val.instance_variables.delete_if { |v| v =~ /color_model/}
|
104
|
+
ivars.each do |ivar|
|
105
|
+
coderay[attr][ivar.to_s.chomp('_')[1..-1].to_sym] =
|
106
|
+
val.instance_variable_get(ivar).to_ansi
|
107
|
+
end
|
108
|
+
else
|
109
|
+
coderay[attr.to_s.chomp('_').to_sym] = val.to_ansi
|
110
|
+
end
|
111
|
+
}
|
37
112
|
end
|
38
113
|
end
|
39
114
|
|
40
|
-
|
115
|
+
private
|
41
116
|
|
42
|
-
|
43
|
-
|
117
|
+
def validate_config
|
118
|
+
if name !~ VALID_NAME
|
119
|
+
raise PryTheme::ThemeError, 'theme name must start with a letter'
|
120
|
+
end
|
121
|
+
|
122
|
+
if name.length > 18
|
123
|
+
raise PryTheme::ThemeError,
|
124
|
+
'theme name must be no longer than 18 characters'
|
125
|
+
end
|
126
|
+
|
127
|
+
unless [256, 8, 16].include?(color_model)
|
128
|
+
raise PryTheme::ThemeError,
|
129
|
+
'incorrect color model. Available values: 8, 16 or 256'
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
44
134
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module PryTheme
|
2
|
+
module ThemeList
|
3
|
+
|
4
|
+
extend self
|
5
|
+
|
6
|
+
def themes
|
7
|
+
@themes ||= []
|
8
|
+
end
|
9
|
+
|
10
|
+
def add_theme(theme)
|
11
|
+
themes << theme
|
12
|
+
end
|
13
|
+
|
14
|
+
def each(&block)
|
15
|
+
themes.each(&block)
|
16
|
+
end
|
17
|
+
|
18
|
+
def current_theme
|
19
|
+
themes.find { |theme| theme.active? }
|
20
|
+
end
|
21
|
+
|
22
|
+
def activate_theme(name)
|
23
|
+
theme = themes.find { |theme| theme.name == name }
|
24
|
+
|
25
|
+
if theme
|
26
|
+
current_theme.disable if current_theme
|
27
|
+
theme.activate
|
28
|
+
true
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def activate_theme_intelligently
|
33
|
+
if Pry::Helpers::BaseHelpers.windows?
|
34
|
+
activate_theme('pry-classic-16')
|
35
|
+
else
|
36
|
+
case PryTheme.tput_colors
|
37
|
+
when 256 then activate_theme('pry-classic-256')
|
38
|
+
when 16 then activate_theme('pry-classic-16')
|
39
|
+
else activate_theme('pry-classic-8')
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def reload_theme(name, file)
|
45
|
+
@themes.delete_if { |theme| theme.name == name }
|
46
|
+
load file
|
47
|
+
activate_theme(name)
|
48
|
+
true
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
@@ -1,38 +1,36 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
|
3
1
|
module PryTheme
|
4
2
|
class WhenStartedHook
|
5
|
-
include PryTheme::Helper
|
6
|
-
|
7
3
|
def call(target, options, _pry_)
|
8
|
-
|
4
|
+
recreate_user_themes_from_default_ones
|
5
|
+
load_themes
|
6
|
+
|
7
|
+
if Pry.config.theme
|
8
|
+
ThemeList.activate_theme(Pry.config.theme)
|
9
|
+
else
|
10
|
+
ThemeList.activate_theme_intelligently
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
9
15
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
if File.exists?(local_theme(theme))
|
15
|
-
new_version = theme_file_version(default_theme(theme))
|
16
|
-
old_version = theme_file_version(local_theme(theme))
|
16
|
+
# Copy a default theme to theme directory, but only if it isn't there yet.
|
17
|
+
def recreate_user_themes_from_default_ones
|
18
|
+
FileUtils.mkdir_p(USER_THEMES_DIR) unless File.exists?(USER_THEMES_DIR)
|
19
|
+
default_themes = Dir.entries(DEF_THEMES_DIR) - %w{. ..}
|
17
20
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
FileUtils.cp(
|
21
|
+
default_themes.each do |theme|
|
22
|
+
user_theme_path = File.join(USER_THEMES_DIR, theme)
|
23
|
+
unless File.exists?(user_theme_path)
|
24
|
+
def_theme_path = File.join(DEF_THEMES_DIR, theme)
|
25
|
+
FileUtils.cp(def_theme_path, USER_THEMES_DIR)
|
23
26
|
end
|
24
27
|
end
|
28
|
+
end
|
25
29
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
_pry_.output.puts %{Can't find "#{ Pry.config.theme }" theme. Using "#{ DEFAULT_THEME_NAME }"}
|
31
|
-
PryTheme.set_theme(DEFAULT_THEME_NAME)
|
32
|
-
end
|
33
|
-
else
|
34
|
-
_pry_.output.puts %{Can't find `Pry.config.theme` definition in your `~/.pryrc`.\nUsing "#{ DEFAULT_THEME_NAME }" theme now.}
|
35
|
-
PryTheme.set_theme(DEFAULT_THEME_NAME)
|
30
|
+
def load_themes
|
31
|
+
user_themes = Dir[File.join(USER_THEMES_DIR, '*' + PT_EXT)]
|
32
|
+
user_themes.each do |theme|
|
33
|
+
require theme
|
36
34
|
end
|
37
35
|
end
|
38
36
|
|
data/lib/pry-theme.rb
CHANGED
@@ -1,174 +1,100 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
require 'pry-theme/
|
4
|
-
require 'pry-theme/
|
5
|
-
require 'pry-theme/
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
require 'pry-theme/theme_list'
|
4
|
+
require 'pry-theme/when_started_hook'
|
5
|
+
require 'pry-theme/hex'
|
6
6
|
require 'pry-theme/rgb'
|
7
|
-
require 'pry-theme/
|
7
|
+
require 'pry-theme/term'
|
8
|
+
require 'pry-theme/formattable'
|
9
|
+
require 'pry-theme/declaration'
|
10
|
+
require 'pry-theme/definition'
|
11
|
+
require 'pry-theme/theme'
|
12
|
+
require 'pry-theme/preview'
|
13
|
+
require 'pry-theme/color'
|
14
|
+
require 'pry-theme/color_table'
|
15
|
+
require 'pry-theme/basic_editor'
|
8
16
|
require 'pry-theme/commands'
|
9
|
-
require 'pry-theme/when_started_hook'
|
10
|
-
|
11
|
-
require 'yaml'
|
12
17
|
|
13
18
|
module PryTheme
|
14
19
|
|
15
|
-
# The root
|
16
|
-
|
17
|
-
|
18
|
-
# The root path for PryTheme examples.
|
19
|
-
EXAMPLES_ROOT = File.join(ROOT, "..", "themes")
|
20
|
-
|
21
|
-
# The root path for the directory with configuration files for OS you're using.
|
22
|
-
CONFIG_DIR = case RbConfig::CONFIG["host_os"]
|
23
|
-
when /mingw|mswin/
|
24
|
-
File.join(ENV["APPDATA"], "pry-theme")
|
25
|
-
else
|
26
|
-
# /darwin|linux/ and friends.
|
27
|
-
File.join(ENV["HOME"], ".pry")
|
28
|
-
end
|
29
|
-
|
30
|
-
# Pry themes' directory.
|
31
|
-
THEME_DIR = File.join(CONFIG_DIR, "themes")
|
32
|
-
|
33
|
-
# The name of the default theme of Pry Theme.
|
34
|
-
DEFAULT_THEME_NAME = "pry-classic"
|
35
|
-
|
36
|
-
# The URI for GitHub API link to Pry Theme Collection contents.
|
37
|
-
COLLECTION = "https://api.github.com/repos/kyrylo/pry-theme-collection/contents"
|
38
|
-
|
39
|
-
def self.set_theme(theme_name)
|
40
|
-
return unless theme = PryTheme.convert(theme_name)
|
41
|
-
::CodeRay::Encoders::Terminal::TOKEN_COLORS.merge!(theme)
|
42
|
-
@current_theme = theme_name
|
43
|
-
end
|
44
|
-
|
45
|
-
def self.current_theme
|
46
|
-
@current_theme
|
47
|
-
end
|
48
|
-
|
49
|
-
def self.convert(theme_name)
|
50
|
-
begin
|
51
|
-
theme = Theme.new(theme_name)
|
52
|
-
rescue NoThemeError => no_theme_error
|
53
|
-
warn no_theme_error
|
54
|
-
return
|
55
|
-
rescue ThemeDescriptionError => long_descr
|
56
|
-
Pry.output.puts long_descr
|
57
|
-
Pry.output.puts "Using #{DEFAULT_THEME_NAME} theme."
|
58
|
-
return
|
59
|
-
end
|
60
|
-
|
61
|
-
palette = Palette.new(theme.color_depth)
|
62
|
-
scheme = {}
|
20
|
+
# The VERSION file must be in the root directory of the library.
|
21
|
+
VERSION_FILE = File.expand_path('../../VERSION', __FILE__)
|
63
22
|
|
64
|
-
|
65
|
-
|
66
|
-
nested_h = {}
|
23
|
+
VERSION = File.exist?(VERSION_FILE) ?
|
24
|
+
File.read(VERSION_FILE).chomp : '(could not find VERSION file)'
|
67
25
|
|
68
|
-
|
69
|
-
|
70
|
-
end
|
26
|
+
# The root path of Pry Theme source code.
|
27
|
+
ROOT = File.expand_path(File.dirname(__FILE__))
|
71
28
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
29
|
+
# The path of the directory with Pry configuration files.
|
30
|
+
CONFIG_DIR = File.join(ENV['HOME'], '.pry')
|
31
|
+
|
32
|
+
# The path of the default Pry Theme themes.
|
33
|
+
DEF_THEMES_DIR = File.join(ROOT, '..', 'themes')
|
34
|
+
|
35
|
+
# The path where the user should keep their themes.
|
36
|
+
USER_THEMES_DIR = File.join(CONFIG_DIR, 'themes')
|
37
|
+
|
38
|
+
# Every Pry Theme file must end with this extension.
|
39
|
+
PT_EXT = '.prytheme.rb'
|
40
|
+
|
41
|
+
# Pry Theme Collection.
|
42
|
+
PTC = 'https://api.github.com/repos/kyrylo/pry-theme-collection/contents/'
|
43
|
+
|
44
|
+
# The default URL shortener (used for listing themes from PTC).
|
45
|
+
SHORTENER = 'http://is.gd/create.php?format=simple&url='
|
46
|
+
|
47
|
+
# @since 0.2.0
|
48
|
+
# @api public
|
49
|
+
class << self
|
50
|
+
# @see https://github.com/kyrylo/pry-theme/wiki/Creating-a-New-Theme
|
51
|
+
#
|
52
|
+
# Creates a new Pry Theme theme.
|
53
|
+
#
|
54
|
+
# @example
|
55
|
+
# my_theme = PryTheme.create name: 'my-theme', color_model: 8 do
|
56
|
+
# author name: 'John Doe', email: 'johndoe@example.com'
|
57
|
+
# description 'My first theme'
|
58
|
+
#
|
59
|
+
# define_theme do
|
60
|
+
# class_variable 'red'
|
61
|
+
# integer 'black'
|
62
|
+
# method 'white', 'red'
|
63
|
+
# symbol bg: 'yellow'
|
64
|
+
#
|
65
|
+
# string do
|
66
|
+
# content 'blue', 'black'
|
67
|
+
# end
|
68
|
+
# end
|
69
|
+
# end
|
70
|
+
#
|
71
|
+
# my_theme.definition.class_variable.foreground(true) #=> "red"
|
72
|
+
# my_theme.definition.string.content.background(true) #=> "black"
|
73
|
+
#
|
74
|
+
# @param [Hash] config
|
75
|
+
# @option config [String] :name ('prytheme-\d+') The name of the theme. It
|
76
|
+
# must be no longer than 18 characters
|
77
|
+
# @option config [Integer] :color_model (256) The number of colours
|
78
|
+
# available in the theme that is being created. Besides 256, valid
|
79
|
+
# arguments are `8` and `16`
|
80
|
+
def create(config = {}, &block)
|
81
|
+
Theme.new(config, &block)
|
76
82
|
end
|
77
83
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
# Matches "yellow".
|
86
|
-
(
|
87
|
-
(
|
88
|
-
\w+(0[1-9])?
|
89
|
-
)
|
90
|
-
\s?
|
91
|
-
)?
|
92
|
-
|
93
|
-
# Matches "yellow (bu)" or "(bu)".
|
94
|
-
(
|
95
|
-
\(
|
96
|
-
(
|
97
|
-
d?b?u?i? # Order matters.
|
98
|
-
)
|
99
|
-
\)
|
100
|
-
)?
|
101
|
-
|
102
|
-
|
103
|
-
# Matches "yellow (bu) on red" or "on red".
|
104
|
-
(
|
105
|
-
\s?
|
106
|
-
on\s
|
107
|
-
(
|
108
|
-
\w+(0[1-9])?
|
109
|
-
)
|
110
|
-
)?
|
111
|
-
|
112
|
-
\z
|
113
|
-
/x
|
114
|
-
|
115
|
-
if color
|
116
|
-
m = color.match(color_pattern)
|
117
|
-
|
118
|
-
color_fg = find_color($2, palette) { |c| c.term }
|
119
|
-
|
120
|
-
formatting = if $5
|
121
|
-
formatting = $5.each_char.map do |ch|
|
122
|
-
Formatting::ATTRIBUTES[ch]
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
color_bg = find_color($7, palette) do |c|
|
127
|
-
if palette.color_depth == 256
|
128
|
-
"#{ TermNotation::BACKGROUND256 }#{c.term}"
|
129
|
-
else
|
130
|
-
Formatting::BACKGROUNDS[c.human.to_s]
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
# Uh oh :(
|
135
|
-
notation = if !color_fg
|
136
|
-
TermNotation::NO_FOREGROUND
|
137
|
-
elsif palette.notation
|
138
|
-
palette.notation[0..-2]
|
139
|
-
else
|
140
|
-
nil
|
141
|
-
end
|
142
|
-
|
143
|
-
[notation, color_fg, formatting, color_bg].flatten.compact.join(";")
|
144
|
-
else
|
145
|
-
# In cases when a user decided not to provide an argument value in theme,
|
146
|
-
# use default color. Not handling this situation results in CodeRay's
|
147
|
-
# error ("can't convert nil into String" stuff).
|
148
|
-
TermNotation::EMPTY
|
84
|
+
# @return [Integer] the number of supported terminal colours. Always equal
|
85
|
+
# to 16 on Windows.
|
86
|
+
def tput_colors
|
87
|
+
`tput colors`.to_i
|
88
|
+
rescue Errno::ENOENT
|
89
|
+
16
|
149
90
|
end
|
150
|
-
rescue NoColorError => e
|
151
|
-
Pry.output.puts "#{e}: wrong color value: `#{color}`. Typo?"
|
152
|
-
end
|
153
|
-
|
154
|
-
def self.find_color(color, palette, &block)
|
155
|
-
if color
|
156
|
-
c = palette.colors.find do |palette_color|
|
157
|
-
palette_color.human == color.to_sym
|
158
|
-
end
|
159
91
|
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
end
|
92
|
+
# @param [Integer] color
|
93
|
+
# @return [Class] the class, which corresponds to the given +color+
|
94
|
+
def color_const(color)
|
95
|
+
const_get(:"Color#{ color }")
|
165
96
|
end
|
166
97
|
end
|
167
98
|
|
99
|
+
Pry.config.hooks.add_hook(:when_started, :pry_theme, WhenStartedHook.new)
|
168
100
|
end
|
169
|
-
|
170
|
-
# Apply a theme of a user from their theme file.
|
171
|
-
Pry.config.hooks.add_hook(:when_started, :apply_user_theme, PryTheme::WhenStartedHook.new)
|
172
|
-
|
173
|
-
# Import the PryTheme commands.
|
174
|
-
Pry.config.commands.import PryTheme::Commands
|
data/pry-theme.gemspec
CHANGED
@@ -1,24 +1,20 @@
|
|
1
|
-
unless defined? PryTheme::VERSION
|
2
|
-
require File.expand_path('../lib/pry-theme/version', __FILE__)
|
3
|
-
end
|
4
|
-
|
5
1
|
Gem::Specification.new do |s|
|
6
|
-
s.name =
|
7
|
-
s.version =
|
2
|
+
s.name = 'pry-theme'
|
3
|
+
s.version = File.read('VERSION')
|
8
4
|
s.date = Time.now.strftime('%Y-%m-%d')
|
9
|
-
s.summary =
|
10
|
-
s.description =
|
11
|
-
s.author =
|
12
|
-
s.email =
|
13
|
-
s.homepage =
|
14
|
-
s.licenses =
|
5
|
+
s.summary = 'An easy way to customize Pry colors via theme files'
|
6
|
+
s.description = 'The plugin enables color theme support for Pry.'
|
7
|
+
s.author = 'Kyrylo Silin'
|
8
|
+
s.email = 'kyrylosilin@gmail.com'
|
9
|
+
s.homepage = 'https://github.com/kyrylo/pry-theme'
|
10
|
+
s.licenses = 'zlib'
|
15
11
|
|
16
|
-
s.require_path =
|
17
|
-
s.files = `git ls-files`.split
|
12
|
+
s.require_path = 'lib'
|
13
|
+
s.files = `git ls-files`.split("\n")
|
18
14
|
|
19
|
-
s.add_runtime_dependency
|
15
|
+
s.add_runtime_dependency 'json'
|
20
16
|
|
21
|
-
s.add_development_dependency
|
22
|
-
s.add_development_dependency
|
23
|
-
s.add_development_dependency
|
17
|
+
s.add_development_dependency 'bacon'
|
18
|
+
s.add_development_dependency 'rake'
|
19
|
+
s.add_development_dependency 'pry'
|
24
20
|
end
|