encrust 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3685e61c950b2154ef3c868f5a0073f8580e1c41b5dbdb43bcc91866b2c3ec43
4
+ data.tar.gz: 3d056f617c3f2673c4be37a9599a8a0ae7fb62c70d1ac080364b5f5a5a5d8acd
5
+ SHA512:
6
+ metadata.gz: 1dfb83c30a5efa93e4558ab6d46079a0304c5aae3a6344fb1dc87009934b6780c601d121b1f6860d92f97f9450c86029783dd55608f96772eb4c011ed8d7f9c7
7
+ data.tar.gz: ef05089855eaa62b1ff12347c5f55621214e2bfbd9cf6cdaf19b7bf52fb848eac04c3f86dc02273de356f2a43f06bf01331f8165bd603df15144392cdc78b2c2
@@ -0,0 +1,12 @@
1
+ Gemfile\.lock
2
+ /.bundle/
3
+ /.yardoc
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.0
7
+ before_install: gem install bundler -v 2.0.1
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at mkg@fastmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in encrust.gemspec
4
+ gemspec
@@ -0,0 +1,49 @@
1
+ # «encrust»
2
+
3
+ encrust is a command line tool that converts iTerm2 color files (`*.itermcolors`) to color files usable by Dwarf Fortress.
4
+
5
+ ## Installation
6
+
7
+ encrust requires Ruby. If you have a current version of Ruby installed, it's as simple as:
8
+
9
+ $ gem install encrust
10
+
11
+ Otherwise, head on over to [Ruby's website](https://www.ruby-lang.org/en/downloads/) and find a version that works for your machine.
12
+
13
+ ## Usage
14
+
15
+ ### Security considerations
16
+
17
+ encrust uses the [plist gem](https://github.com/patsplat/plist). Please only feed it files you trust, and check out [plist's security considerations section](https://github.com/patsplat/plist#security-considerations) for more information.
18
+
19
+ ### encrusting with gems
20
+
21
+ Just point encrust at the files you'd like converted:
22
+
23
+ $ encrust gruvbox-dark-soft.itermcolors
24
+
25
+ It handles multiple files just fine:
26
+
27
+ $ encrust elflord.itermcolors Earthsong.itermcolors
28
+
29
+ Your Dwarf Fortress color files will be generated in the directory where you ran the command, and encrust will tell you where Dwarf Fortress expects its active color file to be.
30
+
31
+ If you want to try out your new color schemes without having to wait for your fortresses to open and close, try uploading the generated files to the [Dwarf Fortress Color Generator](https://manmademagic.github.io/DFColorGen/). DFColorGen also works great for small adjustments to your color schemes.
32
+
33
+ ## Why iTerm?
34
+
35
+ I chose `itermcolors` as my input format primarily because it supports 24-bit color and is easy to read.
36
+
37
+ iTerm2 is also pretty popular, and dozens if not hundreds of color schemes for it can be easily found online.
38
+
39
+ ## Support Bay 12 Games!
40
+
41
+ If you like Dwarf Fortress, consider supporting Bay 12 Games either through their [patreon](https://www.patreon.com/bay12games) or directly through their [website](http://bay12games.com/support.html).
42
+
43
+ ## Contributing
44
+
45
+ Bug reports and pull requests are welcome on GitHub at https://github.com/smoochbot/encrust. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
46
+
47
+ ## Code of Conduct
48
+
49
+ Everyone interacting in the Encrust project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/smoochbot/encrust/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,25 @@
1
+ This is free and unencumbered software released into the public domain.
2
+
3
+ Anyone is free to copy, modify, publish, use, compile, sell, or
4
+ distribute this software, either in source code form or as a compiled
5
+ binary, for any purpose, commercial or non-commercial, and by any
6
+ means.
7
+
8
+ In jurisdictions that recognize copyright laws, the author or authors
9
+ of this software dedicate any and all copyright interest in the
10
+ software to the public domain. We make this dedication for the benefit
11
+ of the public at large and to the detriment of our heirs and
12
+ successors. We intend this dedication to be an overt act of
13
+ relinquishment in perpetuity of all present and future rights to this
14
+ software under copyright law.
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 NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ For more information, please refer to <http://unlicense.org/>
25
+
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "encrust"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,29 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "encrust/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "encrust"
8
+ spec.version = Encrust::VERSION
9
+ spec.authors = ["Margaret K. Geiger"]
10
+ spec.email = ["mkg@fastmail.com"]
11
+
12
+ spec.summary = %q{Converts iTerm2 color schemes to Dwarf Fortress color files.}
13
+ spec.homepage = "https://github.com/smoochbot/encrust"
14
+
15
+ # Specify which files should be added to the gem when it is released.
16
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
17
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
18
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_runtime_dependency "plist", "~> 3.5"
25
+
26
+ spec.add_development_dependency "bundler", "~> 2.0"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rspec", "~> 3.0"
29
+ end
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'encrust/cli'
4
+ Encrust::CLI.start
5
+
@@ -0,0 +1,4 @@
1
+ require 'encrust/version'
2
+ require 'encrust/converter'
3
+
4
+ module Encrust; end
@@ -0,0 +1,96 @@
1
+ require 'encrust'
2
+
3
+ module Encrust
4
+ class CLI
5
+ class << self
6
+ def start
7
+ paths = ARGV.map(&:freeze)
8
+ puts greeting(paths)
9
+ errors = convert(paths)
10
+ puts error_message(errors) if errors.any?
11
+ puts instructions if paths.size > errors.size
12
+ puts exit_message
13
+ end
14
+
15
+ private
16
+
17
+ def convert(files)
18
+ puts
19
+ errors = []
20
+ files.each do |path|
21
+ print " ☼ #{File.basename(path)} -> "
22
+ begin
23
+ colors = Converter.iterm_to_df(path)
24
+ rescue ArgumentError => e
25
+ STDERR.puts "ERROR \e[31;1m✕\e[0m"
26
+ errors << path
27
+ else
28
+ file = "#{File.basename(path, ".*").tr(' ', '_')}.txt"
29
+ File.write(file, colors)
30
+ puts "«#{file}» \e[32;1m✓\e[0m"
31
+ end
32
+ end
33
+ errors
34
+ end
35
+
36
+ def greeting(paths)
37
+ if paths.count == 1
38
+ "Converting an iterm2 color scheme to a Dwarf Fortress color file."
39
+ else
40
+ "Converting #{paths.count} iTerm2 color schemes " \
41
+ "to Dwarf Fortress color files."
42
+ end
43
+ end
44
+
45
+ def instructions
46
+ <<~DWARF
47
+
48
+ To use your colors in Dwarf Fortress, move your chosen file to:
49
+
50
+ <your_dwarf_fortress_path>/data/init/colors.txt
51
+
52
+ Consider backing up the existing colors.txt file first.
53
+ DWARF
54
+ end
55
+
56
+ def error_message(paths_with_errors)
57
+ plural = paths_with_errors.size > 1 ? 's' : nil
58
+ <<~DWARF
59
+
60
+ Error#{plural} while parsing file#{plural} at path#{plural}:
61
+
62
+ #{paths_with_errors.map { |p| " #{p}" }.join("\n")}
63
+
64
+ Please make sure to use valid, suitable iTerm2 color files:
65
+ ☼ They should be in PLIST (XML) format and contain <dict> tags.
66
+ ☼ They should specify RGB values for all ANSI colors from 0 to 15,
67
+ with each color's key formatted like e.g. `Ansi 0 Color` for 0.
68
+ ☼ Each RGB value should lie between 0 and 1, both inclusive.
69
+ DWARF
70
+ end
71
+
72
+ def exit_message
73
+ <<~DWARF
74
+
75
+ To support the development of Dwarf Fortress, go to:
76
+ ☼ Bay 12 Games's patreon: #{patreon}
77
+ ☼ Bay 12 Games's website: #{bay_12_site}
78
+
79
+ Thanks for using encrust, and remember: Losing is fun!
80
+ DWARF
81
+ end
82
+
83
+ def patreon
84
+ underline("https://www.patreon.com/bay12games")
85
+ end
86
+
87
+ def bay_12_site
88
+ underline("http://bay12games.com/support.html")
89
+ end
90
+
91
+ def underline(text)
92
+ "\e[4m#{text}\e[0m"
93
+ end
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,78 @@
1
+ require 'plist'
2
+
3
+ module Encrust
4
+ class Converter
5
+ class << self
6
+ def iterm_to_df(path)
7
+ header << colors(path) << footer(path)
8
+ end
9
+
10
+ private
11
+
12
+ # ANSI Color 3 ("yellow") is called "BROWN" in Dwarf Fortress,
13
+ # while ANSI Color 11 ("bright yellow") is simply called "YELLOW".
14
+ # ANSI Color 7 ("white") is called "LGRAY" in Dwarf Fortress,
15
+ # ANSI Color 8 ("bright black") is called "DGRAY", and
16
+ # ANSI Color 15 ("bright white") is called "WHITE".
17
+ def df_color_names
18
+ %i[BLACK RED GREEN BROWN BLUE MAGENTA CYAN LGRAY
19
+ DGRAY LRED LGREEN YELLOW LBLUE LMAGENTA LCYAN WHITE]
20
+ end
21
+
22
+ def parse(path)
23
+ begin
24
+ Plist.parse_xml(path)
25
+ rescue RuntimeError => e
26
+ msg = "Failed to parse file at path: #{path}"
27
+ raise ArgumentError.new(msg)
28
+ end
29
+ end
30
+
31
+ def colors(path)
32
+ iterm_colors = parse(path)
33
+ df_color_names.each_with_index.reduce("") do |df_colors, (color, i)|
34
+ iterm_rgb = iterm_colors["Ansi #{i} Color"]
35
+ if iterm_rgb.nil?
36
+ msg = "Missing color definition for #{color} (DF) / #{i} (ANSI)"
37
+ raise ArgumentError.new(msg)
38
+ end
39
+ df_colors << generate_df_color(color, iterm_rgb)
40
+ end
41
+ end
42
+
43
+ def generate_df_color(color, iterm_rgb)
44
+ red = (iterm_rgb['Red Component'] * 255).to_i
45
+ green = (iterm_rgb['Green Component'] * 255).to_i
46
+ blue = (iterm_rgb['Blue Component'] * 255).to_i
47
+
48
+ if [red, green, blue].any? { |x| x > 255 || 0 > x }
49
+ msg = "RGB value for #{color} (DF) out of valid range."
50
+ raise ArgumentError.new(msg)
51
+ end
52
+
53
+ <<~DWARF
54
+ [#{color}_R:#{red}]
55
+ [#{color}_G:#{green}]
56
+ [#{color}_B:#{blue}]
57
+ DWARF
58
+ end
59
+
60
+ def header
61
+ <<~DWARF
62
+ These are the display colors in RGB. \
63
+ The game is actually displaying extended \
64
+ ASCII characters in OpenGL, so you can modify the colors.
65
+
66
+ DWARF
67
+ end
68
+
69
+ def footer(path)
70
+ <<~DWARF
71
+
72
+ Converted from `#{File.basename(path)}` using encrust:
73
+ https://github.com/smoochbot/encrust
74
+ DWARF
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,3 @@
1
+ module Encrust
2
+ VERSION = "1.0.0"
3
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: encrust
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Margaret K. Geiger
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-05-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: plist
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.5'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description:
70
+ email:
71
+ - mkg@fastmail.com
72
+ executables:
73
+ - encrust
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".travis.yml"
80
+ - CODE_OF_CONDUCT.md
81
+ - Gemfile
82
+ - README.md
83
+ - Rakefile
84
+ - UNLICENSE
85
+ - bin/console
86
+ - bin/setup
87
+ - encrust.gemspec
88
+ - exe/encrust
89
+ - lib/encrust.rb
90
+ - lib/encrust/cli.rb
91
+ - lib/encrust/converter.rb
92
+ - lib/encrust/version.rb
93
+ homepage: https://github.com/smoochbot/encrust
94
+ licenses: []
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubygems_version: 3.0.1
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: Converts iTerm2 color schemes to Dwarf Fortress color files.
115
+ test_files: []