palettetown 0.1.0
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.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +4 -0
- data/Rakefile +1 -0
- data/bin/palettetown +4 -0
- data/lib/palettetown.rb +10 -0
- data/lib/palettetown/cli.rb +22 -0
- data/lib/palettetown/color.rb +109 -0
- data/lib/palettetown/rule.rb +21 -0
- data/lib/palettetown/scheme.rb +95 -0
- data/lib/palettetown/version.rb +3 -0
- data/palettetown.gemspec +25 -0
- metadata +100 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a1fde914a1e688407fb65cbc479596395b90984c
|
4
|
+
data.tar.gz: b3cd59e0b9ef02fe2751184a61a961d0a92ad119
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3321f8dab21c377c9e08e1c484d76de94f64b7b635e889ddbc76ad3c7669002012e3364d1ba836d51f61652c669edfb5d5d57281512b5969395c0d8403eb99b2
|
7
|
+
data.tar.gz: 262a4a0b7a826ea7f27c9038eadddefd95c18d755242d201fbdef7f2b6ac2f68cd9babbfb2bdbd9c4a7ec5cbd56c77238002430200693c358fbe37fb2cc3810f
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Peter Lejeck
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/palettetown
ADDED
data/lib/palettetown.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'thor'
|
2
|
+
|
3
|
+
module PaletteTown
|
4
|
+
class CLI < Thor
|
5
|
+
desc "build FILE", "build the PaletteTown in FILE into a beautiful butterfly"
|
6
|
+
option :out, :aliases => [:o], :desc => "Where to output the results. defaults to stdout"
|
7
|
+
def build file
|
8
|
+
path = File.expand_path file
|
9
|
+
if File.exist? path
|
10
|
+
temp = Class.new PaletteTown::Scheme
|
11
|
+
temp.instance_eval(IO.read(path))
|
12
|
+
if options[:out]
|
13
|
+
File.open(File.expand_path(options[:out]), 'w') do |f|
|
14
|
+
f.write(temp.to_s)
|
15
|
+
end
|
16
|
+
else
|
17
|
+
puts temp.to_s
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
module PaletteTown
|
2
|
+
class Color
|
3
|
+
attr_accessor :hue, :sat, :lum
|
4
|
+
def initialize color
|
5
|
+
if color.is_a? String
|
6
|
+
color = self.class.from_hex(color)
|
7
|
+
elsif color.is_a? PaletteTown::Color
|
8
|
+
color = color.to_h
|
9
|
+
elsif color.is_a? Hash
|
10
|
+
if color[:hue].nil? or color[:sat].nil? or color[:lum].nil?
|
11
|
+
raise ArgumentError
|
12
|
+
end
|
13
|
+
end
|
14
|
+
@hue = color[:hue].to_f
|
15
|
+
@sat = color[:sat].to_f
|
16
|
+
@lum = color[:lum].to_f
|
17
|
+
end
|
18
|
+
def to_rgb
|
19
|
+
if @sat == 0
|
20
|
+
r = g = b = @lum
|
21
|
+
else
|
22
|
+
y = if @lum < 0.5
|
23
|
+
@lum * (@sat + 1.0)
|
24
|
+
else
|
25
|
+
@lum + @sat - (@lum * @sat)
|
26
|
+
end
|
27
|
+
x = @lum * 2.0 - y
|
28
|
+
r = self.class.hue_to_rgb(x, y, @hue + 1.0/3.0)
|
29
|
+
g = self.class.hue_to_rgb(x, y, @hue)
|
30
|
+
b = self.class.hue_to_rgb(x, y, @hue - 1.0/3.0)
|
31
|
+
end
|
32
|
+
return {
|
33
|
+
:r => (r * 255).to_i,
|
34
|
+
:g => (g * 255).to_i,
|
35
|
+
:b => (b * 255).to_i
|
36
|
+
}
|
37
|
+
end
|
38
|
+
def to_hex
|
39
|
+
"%<r>02x%<g>02x%<b>02x" % to_rgb
|
40
|
+
end
|
41
|
+
def to_h
|
42
|
+
return {
|
43
|
+
:hue => @hue,
|
44
|
+
:sat => @sat,
|
45
|
+
:lum => @lum
|
46
|
+
}
|
47
|
+
end
|
48
|
+
def to_s
|
49
|
+
"##{to_hex}"
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
def self.from_hex color
|
54
|
+
color.shift if color[0] == '#'
|
55
|
+
r = color[0...2].to_i 16
|
56
|
+
g = color[2...4].to_i 16
|
57
|
+
b = color[4...6].to_i 16
|
58
|
+
|
59
|
+
from_rgb(r, g, b)
|
60
|
+
end
|
61
|
+
def self.from_rgb red, green, blue
|
62
|
+
red /= 255.0
|
63
|
+
green /= 255.0
|
64
|
+
blue /= 255.0
|
65
|
+
|
66
|
+
min = [red, green, blue].min
|
67
|
+
max = [red, green, blue].max
|
68
|
+
|
69
|
+
lum = (max + min) / 2
|
70
|
+
|
71
|
+
if max == min
|
72
|
+
hue = 0
|
73
|
+
sat = 0
|
74
|
+
else
|
75
|
+
delta = max - min
|
76
|
+
|
77
|
+
if lum > 0.5
|
78
|
+
sat = delta / (2 - max - min)
|
79
|
+
else
|
80
|
+
sat = delta / (max + min)
|
81
|
+
end
|
82
|
+
|
83
|
+
case max
|
84
|
+
when red
|
85
|
+
hue = (green - blue) / delta
|
86
|
+
hue += 6 if green < blue
|
87
|
+
when green
|
88
|
+
hue = (blue - red) / delta
|
89
|
+
hue += 2
|
90
|
+
when blue
|
91
|
+
hue = (red - green) / delta
|
92
|
+
hue += 4
|
93
|
+
end
|
94
|
+
hue /= 6
|
95
|
+
end
|
96
|
+
return {hue: hue, sat: sat, lum: lum}
|
97
|
+
end
|
98
|
+
def self.hue_to_rgb x, y, z
|
99
|
+
# Frankly I don't know what this all does
|
100
|
+
# I just ported it from the W3C CSS spec
|
101
|
+
z += 1 if z < 0
|
102
|
+
z -= 1 if z > 1
|
103
|
+
return x + (y - x) * z * 6 if z < 1.0 / 6.0
|
104
|
+
return y if z < 1.0 / 2.0
|
105
|
+
return x + (y - x) * (2.0 / 3.0 - z * 6) if z < 2.0 / 3.0
|
106
|
+
return x
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module PaletteTown
|
2
|
+
class Rule
|
3
|
+
def [] key
|
4
|
+
@keys[key]
|
5
|
+
end
|
6
|
+
def each &block
|
7
|
+
@keys.each(&block)
|
8
|
+
end
|
9
|
+
def initialize rule
|
10
|
+
# TODO: Need to find nearest console color
|
11
|
+
# TODO: Create PaletteTown::TermColor class
|
12
|
+
@keys = {}
|
13
|
+
@keys[:guifg] = PaletteTown::Color.new(rule[:fg])
|
14
|
+
@keys[:ctermfg] = rule[:fg_term]
|
15
|
+
@keys[:guibg] = PaletteTown::Color.new(rule[:bg])
|
16
|
+
@keys[:ctermbg] = rule[:bg_term]
|
17
|
+
@keys[:gui] = rule[:style]
|
18
|
+
@keys[:cterm] = rule[:style_term]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
module PaletteTown
|
2
|
+
class Scheme
|
3
|
+
class << self
|
4
|
+
def name name=nil
|
5
|
+
if name.nil?
|
6
|
+
@name
|
7
|
+
else
|
8
|
+
@name = name
|
9
|
+
end
|
10
|
+
end
|
11
|
+
def author author=nil
|
12
|
+
if author.nil?
|
13
|
+
@author
|
14
|
+
else
|
15
|
+
@author = author
|
16
|
+
end
|
17
|
+
end
|
18
|
+
def description description=nil
|
19
|
+
if description.nil?
|
20
|
+
@description
|
21
|
+
else
|
22
|
+
@description = description
|
23
|
+
end
|
24
|
+
end
|
25
|
+
def lighter color, amount
|
26
|
+
color = PaletteTown::Color.new color unless color.is_a? PaletteTown::Color
|
27
|
+
color.lum += amount / 100.0
|
28
|
+
color
|
29
|
+
end
|
30
|
+
def darker color, amount
|
31
|
+
color = PaletteTown::Color.new color unless color.is_a? PaletteTown::Color
|
32
|
+
color.lum -= amount / 100.0
|
33
|
+
color
|
34
|
+
end
|
35
|
+
def saturate color, amount
|
36
|
+
color = PaletteTown::Color.new color unless color.is_a? PaletteTown::Color
|
37
|
+
color.sat += amount / 100.0
|
38
|
+
color
|
39
|
+
end
|
40
|
+
def desaturate color, amount
|
41
|
+
color = PaletteTown::Color.new color unless color.is_a? PaletteTown::Color
|
42
|
+
color.sat -= amount / 100.0
|
43
|
+
end
|
44
|
+
def spin color, amount
|
45
|
+
color = PaletteTown::Color.new color unless color.is_a? PaletteTown::Color
|
46
|
+
color.hue += amount / 360.0
|
47
|
+
color
|
48
|
+
end
|
49
|
+
def hi rule, *options
|
50
|
+
@rules ||= {}
|
51
|
+
@rules[rule] = PaletteTown::Rule.new(*options)
|
52
|
+
end
|
53
|
+
def to_s
|
54
|
+
out = <<-EOF
|
55
|
+
" Vim color file
|
56
|
+
" Generated by PaletteTown
|
57
|
+
" http://nuckchorris.github.io/palettetown/
|
58
|
+
"
|
59
|
+
" Name: #{name}
|
60
|
+
" Author: #{author}
|
61
|
+
" Notes: #{description}
|
62
|
+
|
63
|
+
hi clear
|
64
|
+
if version > 580
|
65
|
+
if exists("syntax_on")
|
66
|
+
syntax reset
|
67
|
+
endif
|
68
|
+
endif
|
69
|
+
|
70
|
+
let colors_name="#{name}"
|
71
|
+
|
72
|
+
EOF
|
73
|
+
if @rules[:Normal]
|
74
|
+
out << <<-EOF
|
75
|
+
if has("gui_running")
|
76
|
+
set background=#{if @rules[:Normal][:guibg].lum < 0.5 then "dark" else "light" end}
|
77
|
+
endif
|
78
|
+
|
79
|
+
EOF
|
80
|
+
@rules[:Normal][:guibg].lum < 0.5
|
81
|
+
else
|
82
|
+
warn "No Normal hilight found; can't guess background"
|
83
|
+
end
|
84
|
+
@rules.each do |rule, opts|
|
85
|
+
out << "hi #{rule}"
|
86
|
+
opts.each do |key, val|
|
87
|
+
out << " #{key}=#{val}" unless val.nil?
|
88
|
+
end
|
89
|
+
out << "\n"
|
90
|
+
end
|
91
|
+
out
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
data/palettetown.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'palettetown/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "palettetown"
|
8
|
+
spec.version = Palettetown::VERSION
|
9
|
+
spec.authors = ["Peter Lejeck"]
|
10
|
+
spec.email = ["peter.lejeck@gmail.com"]
|
11
|
+
spec.description = %q{A simple ruby DSL for writing vim schemes}
|
12
|
+
spec.summary = %q{A simple ruby DSL for writing vim schemes}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
|
24
|
+
spec.add_dependency "thor"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: palettetown
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Peter Lejeck
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-06-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: thor
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: A simple ruby DSL for writing vim schemes
|
56
|
+
email:
|
57
|
+
- peter.lejeck@gmail.com
|
58
|
+
executables:
|
59
|
+
- palettetown
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- .gitignore
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- bin/palettetown
|
69
|
+
- lib/palettetown.rb
|
70
|
+
- lib/palettetown/cli.rb
|
71
|
+
- lib/palettetown/color.rb
|
72
|
+
- lib/palettetown/rule.rb
|
73
|
+
- lib/palettetown/scheme.rb
|
74
|
+
- lib/palettetown/version.rb
|
75
|
+
- palettetown.gemspec
|
76
|
+
homepage: ''
|
77
|
+
licenses:
|
78
|
+
- MIT
|
79
|
+
metadata: {}
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
requirements: []
|
95
|
+
rubyforge_project:
|
96
|
+
rubygems_version: 2.0.2
|
97
|
+
signing_key:
|
98
|
+
specification_version: 4
|
99
|
+
summary: A simple ruby DSL for writing vim schemes
|
100
|
+
test_files: []
|