pry-theme 0.0.1.pre

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ *~
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (C) 2012 Kyrylo Silin
2
+
3
+ This software is provided 'as-is', without any express or implied
4
+ warranty. In no event will the authors be held liable for any damages
5
+ arising from the use of this software.
6
+
7
+ Permission is granted to anyone to use this software for any purpose,
8
+ including commercial applications, and to alter it and redistribute it
9
+ freely, subject to the following restrictions:
10
+
11
+ 1. The origin of this software must not be misrepresented; you must not
12
+ claim that you wrote the original software. If you use this software
13
+ in a product, an acknowledgment in the product documentation would be
14
+ appreciated but is not required.
15
+
16
+ 2. Altered source versions must be plainly marked as such, and must not be
17
+ misrepresented as being the original software.
18
+
19
+ 3. This notice may not be removed or altered from any source distribution.
data/README.md ADDED
@@ -0,0 +1,75 @@
1
+ ![Pry Theme][logo]
2
+
3
+ * [https://github.com/kyrylo/pry-theme/][pt]
4
+
5
+ Warning
6
+ =======
7
+
8
+ The project is in its infancy, so do expect bugs.
9
+
10
+ Description
11
+ -----------
12
+
13
+ Pry Theme is a plugin for [Pry][pry], which helps you to customize your Pry
14
+ colors via `prytheme` files.
15
+
16
+ Installation
17
+ ------------
18
+
19
+ All you need is to install the gem. The `pry-theme` plugin will be detected and
20
+ used automatically.
21
+
22
+ gem install pry-theme
23
+
24
+ Synopsis
25
+ --------
26
+
27
+ ### Configuration file
28
+
29
+ Pry Theme ships only with two themes: `pry-classic` and `pry-modern`. In order
30
+ to set up the desired theme, add the following line to your `.pryrc`:
31
+
32
+ Pry.config.theme = "theme-name"
33
+
34
+ The default theme is `pry-classic` (basically, you won't notice it, because
35
+ it copies the default outlook of Pry, withouth the plugin). Let's change it to
36
+ something more neoteric:
37
+
38
+ Pry.config.theme = "pry-modern"
39
+
40
+ That's all! Launch your Pry and you will see the changes.
41
+
42
+ ### CLI
43
+
44
+ Pry Theme has a command-line interface via Pry. Currently, it can't do much. The
45
+ only thing you can do is to switch themes on the fly. Start Pry and type the
46
+ following:
47
+
48
+ % pry --simple-prompt
49
+ >> pry-theme pry-classic
50
+
51
+ We just temporary changed our current theme to `pry-classic`.
52
+
53
+ ### Creating themes
54
+
55
+ It's not easy now, so let's just skip this paragraph :P
56
+
57
+ ### Adding new themes
58
+
59
+ Theme files should have `.prytheme` extension. All theme files should be in
60
+ `$XDG_CONFIG_HOME/pry-theme` directory. Don't forget to change your `.pryrc`!
61
+
62
+ Limitations
63
+ -----------
64
+
65
+ * GNU/Linux (in future will support other popular platforms);
66
+ * CRuby 1.9.3 (in future will support other implementations).
67
+
68
+ License
69
+ -------
70
+
71
+ The project uses Zlib License. See LICENSE file for more information.
72
+
73
+ [pt]: https://github.com/kyrylo/pry-theme/ "Home page"
74
+ [logo]: http://img-fotki.yandex.ru/get/5107/98991937.a/0_7c6c8_871a1842_orig "Pry Theme"
75
+ [pry]: https://github.com/pry/pry/ "Pry's home page"
@@ -0,0 +1,42 @@
1
+ ---
2
+ meta:
3
+ theme-name : pry-classic
4
+ version : 1
5
+ color-depth : 8
6
+ description : Based on Kornelius Kalnbach's default CodeRay's color theme.
7
+ author : Kyrylo Silin <kyrylosilin@gmail.com>
8
+
9
+ theme:
10
+ binary : magenta (b)
11
+ char:
12
+ self : cyan
13
+ delimiter : blue (b)
14
+ class : magenta (b)
15
+ class_variable : cyan
16
+ comment : blue
17
+ constant : blue (bu)
18
+ doctype : black (b)
19
+ error : yellow (b) on red
20
+ float : magenta (b)
21
+ global_variable : on green
22
+ hex : cyan (b)
23
+ integer : blue (b)
24
+ keyword : red (b)
25
+ method : blue (b)
26
+ predefined_constant : cyan (b)
27
+ regexp:
28
+ self : red
29
+ content : red
30
+ delimiter : red (db)
31
+ modifier : magenta (b)
32
+ function : (db)
33
+ shell:
34
+ self : on green
35
+ content : (db)
36
+ delimiter : white
37
+ string:
38
+ self : green
39
+ modifier : green (b)
40
+ escape : cyan (b)
41
+ delimiter : green (b)
42
+ symbol : green (b)
@@ -0,0 +1,42 @@
1
+ ---
2
+ meta:
3
+ theme-name : pry-modern
4
+ version : 1
5
+ color-depth : 256
6
+ description :
7
+ author : Kyrylo Silin <kyrylosilin@gmail.com>
8
+
9
+ theme:
10
+ binary : magenta (b)
11
+ char:
12
+ self : cyan
13
+ delimiter : blue (b)
14
+ class : fuchsia (b)
15
+ class_variable : robin_egg_blue04
16
+ comment : cerulean_grey01
17
+ constant : klein_blue (bu)
18
+ doctype : black (b)
19
+ error : cerulean_grey02
20
+ float : dark_pink01 (b)
21
+ global_variable : gold
22
+ hex : cyan (b)
23
+ integer : robin_egg_blue01 (b)
24
+ keyword : chestnut01 (b)
25
+ method : grass01 (b)
26
+ predefined_constant : cyan (b)
27
+ regexp:
28
+ self : tangerine
29
+ content : violaceous03
30
+ delimiter : tangerine (db)
31
+ modifier : dark_pink01 (b)
32
+ function : (db)
33
+ shell:
34
+ self : on green
35
+ content : grass01
36
+ delimiter : white
37
+ string:
38
+ self : malachite01
39
+ modifier : malachite01 (b)
40
+ escape : cyan (b)
41
+ delimiter : malachite01 (b)
42
+ symbol : malachite02 (b)
@@ -0,0 +1,19 @@
1
+ module PryTheme
2
+ Commands = Pry::CommandSet.new do
3
+
4
+ create_command "pry-theme", "Manage your Pry themes." do
5
+ banner <<-BANNER
6
+ Usage: pry-theme [OPTIONS]
7
+ Change your theme on the fly.
8
+ e.g.: pry-theme pry-classic
9
+ BANNER
10
+
11
+ def process
12
+ unless args.empty?
13
+ PryTheme::Setter.call(args[0])
14
+ end
15
+ end
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,62 @@
1
+ module PryTheme
2
+ module Formatting
3
+ ATTRIBUTES = {
4
+ "b" => "1", # Bold.
5
+ "u" => "4", # Underline.
6
+ "i" => "7", # Inverse.
7
+ "d" => "10" # Default.
8
+ }
9
+
10
+ BACKGROUNDS = {
11
+ "black" => "40",
12
+ "red" => "41",
13
+ "green" => "42",
14
+ "yellow" => "43",
15
+ "blue" => "44",
16
+ "magenta" => "45",
17
+ "cyan" => "46",
18
+ "white" => "47",
19
+ "default" => "49",
20
+ }
21
+ end
22
+
23
+ # Creates a new color.
24
+ Color = Struct.new(:term, :human)
25
+
26
+ # Color palettes aka set of colors. Use 8 colors for limited terminals (like
27
+ # `linux` or other pithecanthropic crap. Real men's choice is 256 colors).
28
+ class Palette
29
+
30
+ # @return [Array<Color>] The colors in the current palette.
31
+ attr_reader :colors
32
+
33
+ # @return [Integer] The number representing max number of colors in theme.
34
+ attr_reader :color_depth
35
+
36
+ # @param [Integer] colors The number of colors to be used in the palette.
37
+ def initialize(colors=8)
38
+ palette = send("init_#{colors}_colors")
39
+ @colors = palette[:term].zip(palette[:human]).map do |color|
40
+ Color.new(*color)
41
+ end
42
+ @color_depth = colors
43
+ end
44
+
45
+ private
46
+
47
+ def init_8_colors
48
+ {
49
+ :term => [ 30, 31, 32, 33, 34, 35, 36, 37],
50
+ :human => [ :black, :red, :green, :yellow, :blue, :magenta, :cyan, :white ]
51
+ }
52
+ end
53
+
54
+ def init_256_colors
55
+ {
56
+ :term => (0...256).to_a,
57
+ :human => [ :black, :maroon, :toad_in_love, :olive, :navy_blue, :violet_eggplant, :teal, :silver, :gray, :red, :green, :yellow, :blue, :magenta, :cyan, :white, :black, :dark_indigo, :ultramarine01, :ultramarine02, :persian_blue01, :blue, :dark_spring_green, :dark_turquoise, :cerulean_grey01, :denim01, :royal_blue01, :royal_blue02, :toad_in_love01, :sea_green01, :teal01, :cerulean_grey02, :klein_blue, :azure01, :vert_de_pomme01, :jade01, :jade02, :robin_egg_blue01, :bondi_blue, :light_blue01, :vert_de_pomme02, :malachite01, :emerald01, :turquoise, :robin_egg_blue02, :electric01, :green, :spring_green01, :spring_green02, :mint_green01, :aquamarine01, :cyan, :flea_belly, :plum, :indigo, :purple01, :violet01, :persian_blue02, :khaki01, :wet_asphalt01, :seroburomalinovyj01, :denim02, :royal_blue03, :royal_blue04, :olive_drab, :fern_green, :slate_gray, :steel_blue, :cornflower_blue01, :azure02, :grass01, :emerald02, :sea_green02, :robin_egg_blue03, :bluish01, :light_blue02, :vert_de_pomme03, :pale_green01, :emerald03, :aquamarine02, :robin_egg_blue04, :sky01, :bright_green, :malachite02, :spring_green03, :chartreuse01, :aquamarine03, :cyan01, :maroon01, :eggplant01, :violet_eggplant01, :purple02, :violet02, :violet03, :khaki02, :pale_mauve01, :seroburomalinovyj02, :amethyst01, :amethyst02, :heliotrope01, :olive01, :dark_tan, :gray01, :bluish02, :cornflower_blue02, :royal_blue05, :grass02, :asparagus, :swamp_green01, :light_grey01, :bluish03, :cornflower_blue03, :green_yellow01, :pale_green02, :emerald04, :celadon, :pale_blue01, :sky02, :viridian, :vert_de_pomme04, :mint_green02, :chartreuse02, :aquamarine03, :electric02, :bismarck_furious, :eggplant02, :red_violet01, :violet_eggplant02, :bright_violet, :violet04, :ochre, :pale_mauve02, :pale_red_violet01, :orchid01, :amethyst03, :heliotrope02, :dark_goldenrod, :pale_brown, :mountbatten_pink, :lilac01, :wisteria01, :amethyst04, :old_gold, :brass01, :swamp_green02, :light_grey02, :niagara, :wisteria02, :lime01, :pistachio01, :moss_green, :dark_tea_green, :pale_blue02, :pale_conflower_blue, :green_yellow02, :green_yellow03, :pistachio02, :chartreuse03, :aquamarine04, :pale_blue03, :titian, :cerise01, :red_violet02, :hot_pink01, :bright_violet, :magenta01, :tenne, :chestnut01, :pale_red_violet02, :orchid02, :orchid03, :heliotrope03, :siena, :dark_salmon, :puce01, :puce2, :violaceous01, :violaceous02, :dark_pear, :brass02, :tan, :pale_chestnut, :lilac02, :wisteria03, :childs_surprise, :vert_de_peche, :flax, :gray_tea_green, :abdel_kerims_beard01, :periwinkle, :lime02, :pistachio03, :pistachio04, :tea_green01, :tea_green02, :pang, :red, :crimson, :cerise02, :hot_pink02, :hot_pink03, :magenta, :international_orange, :alizarin, :dark_pink01, :dark_pink02, :shocked_star, :fuchsia, :tangerine, :salmon, :chestnut02, :pale_red_violet03, :pale_magenta, :violaceous03, :orange, :pink_orange, :saumon, :pink01, :pink02, :violaceous04, :gold, :mustard01, :mustard02, :dark_peach, :pale_pink, :thistle, :yellow, :corn01, :corn02, :perhydor, :lemon_cream, :white, :black01, :black02, :black03, :bistre, :anthracite, :wet_asphalt02, :wet_asphalt03, :wet_asphalt04, :wet_asphalt05, :wet_asphalt06, :wet_asphalt07, :gray01, :gray, :gray02, :gray03, :gray04, :gray05, :light_grey03, :light_grey04, :silver01, :abdel_kerims_beard02, :abdel_kerims_beard03, :abdel_kerims_beard04, :seashell ]
58
+ }
59
+ end
60
+
61
+ end
62
+ end
@@ -0,0 +1,27 @@
1
+ module PryTheme
2
+ class Theme
3
+
4
+ attr_reader :scheme, :author, :description, :color_depth, :version, :name
5
+
6
+ def initialize(theme_filename)
7
+ theme = Psych.load_file(File.join(THEME_DIR, "#{theme_filename}.prytheme"))
8
+ meta = theme["meta"]
9
+
10
+ @name = meta["theme-name"]
11
+ @version = meta["version"]
12
+ @color_depth = meta["color-depth"].to_i
13
+ @description = meta["description"]
14
+ @author = meta["author"]
15
+ @scheme = theme["theme"]
16
+ end
17
+
18
+ def method_missing(method_name, *args, &block)
19
+ if @scheme.has_key?(method_name.to_s)
20
+ @scheme[method_name.to_s]
21
+ else
22
+ super
23
+ end
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module PryTheme
2
+ VERSION = "0.0.1.pre"
3
+ end
@@ -0,0 +1,20 @@
1
+ require 'fileutils'
2
+
3
+ module PryTheme
4
+ class WhenStartedHook
5
+
6
+ def call(target, options, _pry_)
7
+ Dir.mkdir(THEME_DIR) unless Dir.exists?(THEME_DIR)
8
+
9
+ (Dir.entries("examples") - %w{ . .. }).each do |f|
10
+ unless File.exists?(File.join(THEME_DIR, f))
11
+ FileUtils.cp(File.join("examples", f), THEME_DIR)
12
+ end
13
+ end
14
+
15
+ theme_name = Pry.config.theme || "pry-classic"
16
+ PryTheme::Setter.call(theme_name)
17
+ end
18
+
19
+ end
20
+ end
data/lib/pry-theme.rb ADDED
@@ -0,0 +1,101 @@
1
+ require 'pry-theme/version'
2
+ require 'pry-theme/commands'
3
+ require 'pry-theme/palette'
4
+ require 'pry-theme/theme'
5
+ require 'pry-theme/when_started_hook'
6
+ require 'pry'
7
+ require 'psych'
8
+
9
+ module PryTheme
10
+
11
+ THEME_DIR = File.join(ENV["XDG_CONFIG_HOME"], "pry-theme")
12
+
13
+ Setter = proc do |theme_name|
14
+ ::CodeRay::Encoders::Terminal::TOKEN_COLORS.merge!(PryTheme.convert(theme_name))
15
+ end
16
+
17
+ def self.convert(theme_name)
18
+ theme = Theme.new(theme_name)
19
+ palette = Palette.new(theme.color_depth)
20
+ scheme = {}
21
+
22
+ theme.scheme.each_pair do |k, v|
23
+ if v.is_a?(Hash)
24
+ nested_h = {}
25
+
26
+ v.each_pair do |nested_k, nested_v|
27
+ nested_h[nested_k.to_sym] = color_to_term(nested_v, palette)
28
+ end
29
+
30
+ scheme[k.to_sym] = nested_h
31
+ else
32
+ scheme[k.to_sym] = color_to_term(v, palette)
33
+ end
34
+ end
35
+
36
+ scheme
37
+ end
38
+
39
+ def self.color_to_term(color, palette)
40
+ color_pattern = /
41
+ \A
42
+
43
+ # Matches "yellow".
44
+ (
45
+ (?<fg>
46
+ \w+(0[1-9])?
47
+ )
48
+ \s?
49
+ )?
50
+
51
+ # Matches "yellow (bu)" or "(bu)".
52
+ (
53
+ \(
54
+ (?<attrs>
55
+ d?b?u?i? # Order matters.
56
+ )
57
+ \)
58
+ )?
59
+
60
+
61
+ # Matches "yellow (bu) on red" or "on red".
62
+ (
63
+ \s?
64
+ on\s
65
+ (?<bg>
66
+ [a-z]+(0[1-9])?
67
+ )
68
+ )?
69
+
70
+ \z
71
+ /x
72
+ m = color.match(color_pattern)
73
+
74
+ color_fg = if m[:fg]
75
+ palette.colors.find do |color|
76
+ color.human == m[:fg].to_sym
77
+ end.term
78
+ end
79
+
80
+ formatting = if m[:attrs]
81
+ formatting = m[:attrs].each_char.map do |ch|
82
+ Formatting::ATTRIBUTES[ch]
83
+ end
84
+ end
85
+
86
+ color_bg = if m[:bg]
87
+ Formatting::BACKGROUNDS[m[:bg]]
88
+ end
89
+
90
+ notation = "38;5" if palette.color_depth == 256
91
+
92
+ [notation, color_fg, formatting, color_bg].flatten.compact.join(";")
93
+ end
94
+
95
+ end
96
+
97
+ # Apply a theme of a user from their theme file.
98
+ Pry.config.hooks.add_hook(:when_started, :apply_user_theme, PryTheme::WhenStartedHook.new)
99
+
100
+ # Import the PryTheme commands.
101
+ Pry.config.commands.import PryTheme::Commands
data/pry-theme.gemspec ADDED
@@ -0,0 +1,18 @@
1
+ require "./lib/pry-theme/version"
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "pry-theme"
5
+ s.version = PryTheme::VERSION
6
+ s.date = Time.now.strftime('%Y-%m-%d')
7
+ s.summary = "Easy way to customize your Pry colors"
8
+ s.description = "The plugin enables color theme for your Pry. No more pryrc bustling."
9
+ s.author = "Kyrylo Silin"
10
+ s.email = "kyrylosilin@gmail.com"
11
+ s.homepage = "https://github.com/kyrylo/pry-theme"
12
+ s.licenses = "zlib"
13
+
14
+ s.require_path = "lib"
15
+ s.files = `git ls-files`.split "\n"
16
+
17
+ s.add_runtime_dependency "pry", "~> 0.9"
18
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pry-theme
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.pre
5
+ prerelease: 6
6
+ platform: ruby
7
+ authors:
8
+ - Kyrylo Silin
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-26 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: pry
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '0.9'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '0.9'
30
+ description: The plugin enables color theme for your Pry. No more pryrc bustling.
31
+ email: kyrylosilin@gmail.com
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - .gitignore
37
+ - LICENSE
38
+ - README.md
39
+ - examples/pry-classic.prytheme
40
+ - examples/pry-modern.prytheme
41
+ - lib/pry-theme.rb
42
+ - lib/pry-theme/commands.rb
43
+ - lib/pry-theme/palette.rb
44
+ - lib/pry-theme/theme.rb
45
+ - lib/pry-theme/version.rb
46
+ - lib/pry-theme/when_started_hook.rb
47
+ - pry-theme.gemspec
48
+ homepage: https://github.com/kyrylo/pry-theme
49
+ licenses:
50
+ - zlib
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>'
65
+ - !ruby/object:Gem::Version
66
+ version: 1.3.1
67
+ requirements: []
68
+ rubyforge_project:
69
+ rubygems_version: 1.8.23
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: Easy way to customize your Pry colors
73
+ test_files: []