wasko 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.1.0
@@ -0,0 +1,79 @@
1
+ module Wasko
2
+ # Adds support for [iTerm2](http://code.google.com/p/iterm2/)
3
+ class Iterm
4
+
5
+ # Terminal.app uses a slightly different terminology
6
+ def self.set_normal_text_color(color)
7
+ set_foreground_color color
8
+ end
9
+
10
+ def self.set_bold_text_color(color)
11
+ set_bold_color color
12
+ end
13
+
14
+ def self.method_missing(method_sym, *arguments, &block)
15
+ if method_sym.to_s =~ /^set_(.*)$/
16
+ self.set($1.gsub(/_/, " ") => arguments.first)
17
+ elsif method_sym.to_s =~ /^([a-z]+_[a-z]+(.*))$/
18
+ self.get($1.gsub(/_/, " "))
19
+ else
20
+ super
21
+ end
22
+ end
23
+
24
+ # Pretty big todo, shield this off somewhat.
25
+ def self.respond_to?(method_sym, include_private = false)
26
+ if method_sym.to_s =~ /^set_(.*)$/
27
+ true
28
+ elsif method_sym.to_s =~ /^[a-z]+_[a-z]+(.*)$/
29
+ true
30
+ else
31
+ super
32
+ end
33
+ end
34
+
35
+ protected
36
+
37
+ def self.set(conditions = {})
38
+ Wasko::Applescript.run do
39
+ self.set_script(conditions.keys.first, conditions.values.first)
40
+ end
41
+ end
42
+
43
+ def self.get(object)
44
+ Wasko::Applescript.run do
45
+ self.get_script(object)
46
+ end
47
+ end
48
+
49
+ # ## Utility methods
50
+ #
51
+ # Setter
52
+ #
53
+ # Wasko::Terminal.set_script("background color", "red")
54
+ #
55
+ def self.set_script(object, value)
56
+ unless value =~ /^(\{|\[|\()/
57
+ value = "\"#{value}\""
58
+ end
59
+ <<SCRIPT
60
+ tell application "iTerm"
61
+ set #{object} of current session of current terminal to #{value}
62
+ end tell
63
+ SCRIPT
64
+ end
65
+
66
+ # Getter
67
+ #
68
+ # Wasko::Terminal.get_script("background color")
69
+ #
70
+ def self.get_script(object)
71
+ <<SCRIPT
72
+ tell application "iTerm"
73
+ get #{object} of current session of current terminal
74
+ end tell
75
+ SCRIPT
76
+ end
77
+
78
+ end
79
+ end
data/lib/wasko/palette.rb CHANGED
@@ -47,6 +47,10 @@ module Wasko
47
47
  @base.brightness > 0.5 ? -1 : 1
48
48
  end
49
49
 
50
+ def dark_base_color?
51
+ @base.brightness < 0.5
52
+ end
53
+
50
54
  # Hash of the color palette
51
55
  # TODO: attr_accessible
52
56
  def colors
@@ -85,6 +89,7 @@ module Wasko
85
89
  def mix_base_with(color_name, mix_value = 50, brightness = 30)
86
90
  @base.mix_with(Wasko::Color.color_from_string(color_name), mix_value).adjust_brightness(brightness)
87
91
  end
92
+
88
93
  end
89
94
  end
90
95
  end
@@ -8,6 +8,22 @@ module Wasko
8
8
  # other variants.
9
9
  class Terminal
10
10
 
11
+ # Unsupported calls
12
+ # Since Apple hasn't implemented them, no way to set
13
+ # them, except to fall back to brittle GUI scripting
14
+ # and I'm not really looking forward to doing that.
15
+ #
16
+ # So that's why you should use iTerm2.
17
+ def self.set_selected_text_color(color);end
18
+ def self.set_selection_color(color);end
19
+ def self.set_ansi_black_color(color);end
20
+ def self.set_ansi_red_color(color);end
21
+ def self.set_ansi_green_color(color);end
22
+ def self.set_ansi_yellow_color(color);end
23
+ def self.set_ansi_blue_color(color);end
24
+ def self.set_ansi_magenta_color(color);end
25
+ def self.set_ansi_cyan_color(color);end
26
+ def self.set_ansi_white_color(color);end
11
27
 
12
28
  # # Getters And Setters
13
29
  #
data/lib/wasko.rb CHANGED
@@ -4,6 +4,8 @@ require "yaml"
4
4
  require "wasko/applescript"
5
5
  # [Terminal: Support for Terminal.app](terminal.html)
6
6
  require "wasko/terminal"
7
+ # [iTerm: Support for iTerm.app](iterm.html)
8
+ require "wasko/iterm"
7
9
  # [Color: Small color utilities](color.html)
8
10
  require "wasko/color"
9
11
  # [Palette: Generates a color scheme](palette.html)
@@ -18,7 +20,16 @@ module Wasko
18
20
  # in the future this could be used to support other
19
21
  # Terminals as well.
20
22
  def advanced_typing_apparatus
21
- Wasko::Terminal
23
+ return Wasko::Terminal if current_application =~ /Terminal.app/
24
+ return Wasko::Iterm if current_application =~ /iTerm.app/
25
+ nil
26
+ end
27
+
28
+ # Gets the current active application
29
+ def current_application
30
+ Wasko::Applescript.run do
31
+ "get name of (info for (path to frontmost application))"
32
+ end
22
33
  end
23
34
 
24
35
  # ## Set/Get fonts and colors
@@ -58,6 +69,14 @@ module Wasko
58
69
  advanced_typing_apparatus.set_cursor_color(Wasko::Color.color_from_string(color).to_applescript)
59
70
  end
60
71
 
72
+ def set_selected_text_color(color)
73
+ advanced_typing_apparatus.set_selected_text_color(Wasko::Color.color_from_string(color).to_applescript)
74
+ end
75
+
76
+ def set_selection_color(color)
77
+ advanced_typing_apparatus.set_selection_color(Wasko::Color.color_from_string(color).to_applescript)
78
+ end
79
+
61
80
  def font_name
62
81
  advanced_typing_apparatus.font_name
63
82
  end
@@ -84,6 +103,40 @@ module Wasko
84
103
  set_font_name name
85
104
  end
86
105
 
106
+ # ### Ansi Colors
107
+
108
+ def set_ansi_black_color(color)
109
+ advanced_typing_apparatus.set_ansi_black_color(Wasko::Color.color_from_string(color).to_applescript)
110
+ end
111
+
112
+ def set_ansi_red_color(color)
113
+ advanced_typing_apparatus.set_ansi_red_color(Wasko::Color.color_from_string(color).to_applescript)
114
+ end
115
+
116
+ def set_ansi_green_color(color)
117
+ advanced_typing_apparatus.set_ansi_green_color(Wasko::Color.color_from_string(color).to_applescript)
118
+ end
119
+
120
+ def set_ansi_yellow_color(color)
121
+ advanced_typing_apparatus.set_ansi_yellow_color(Wasko::Color.color_from_string(color).to_applescript)
122
+ end
123
+
124
+ def set_ansi_blue_color(color)
125
+ advanced_typing_apparatus.set_ansi_blue_color(Wasko::Color.color_from_string(color).to_applescript)
126
+ end
127
+
128
+ def set_ansi_magenta_color(color)
129
+ advanced_typing_apparatus.set_ansi_magenta_color(Wasko::Color.color_from_string(color).to_applescript)
130
+ end
131
+
132
+ def set_ansi_cyan_color(color)
133
+ advanced_typing_apparatus.set_ansi_cyan_color(Wasko::Color.color_from_string(color).to_applescript)
134
+ end
135
+
136
+ def set_ansi_white_color(color)
137
+ advanced_typing_apparatus.set_ansi_white_color(Wasko::Color.color_from_string(color).to_applescript)
138
+ end
139
+
87
140
  # ## Palette
88
141
  #
89
142
  # Returns a string representation of the current settings
@@ -105,6 +158,12 @@ module Wasko
105
158
  set_foreground_color p.colors[:foreground].html
106
159
  set_bold_color p.colors[:bold].html
107
160
  set_cursor_color p.colors[:cursor].html
161
+ set_selected_text_color p.colors[:selected].html
162
+ set_selection_color p.colors[:selection].html
163
+
164
+ %w(black red green yellow blue magenta cyan white).each do |color|
165
+ eval "set_ansi_#{color}_color p.colors[:#{color}].html"
166
+ end
108
167
  end
109
168
 
110
169
  end
data/wasko.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{wasko}
8
- s.version = "0.0.1"
8
+ s.version = "0.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["pjaspers"]
12
- s.date = %q{2011-05-31}
12
+ s.date = %q{2011-06-15}
13
13
  s.default_executable = %q{wasko}
14
14
  s.description = %q{Quick tool to set a color palette to your Terminal}
15
15
  s.email = %q{piet@10to1.be}
@@ -38,6 +38,7 @@ Gem::Specification.new do |s|
38
38
  "lib/wasko/applescript.rb",
39
39
  "lib/wasko/color.rb",
40
40
  "lib/wasko/configuration.rb",
41
+ "lib/wasko/iterm.rb",
41
42
  "lib/wasko/palette.rb",
42
43
  "lib/wasko/terminal.rb",
43
44
  "sample_generator.rb",
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wasko
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 0
9
8
  - 1
10
- version: 0.0.1
9
+ - 0
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - pjaspers
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-05-31 00:00:00 +02:00
18
+ date: 2011-06-15 00:00:00 +02:00
19
19
  default_executable: wasko
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -221,6 +221,7 @@ files:
221
221
  - lib/wasko/applescript.rb
222
222
  - lib/wasko/color.rb
223
223
  - lib/wasko/configuration.rb
224
+ - lib/wasko/iterm.rb
224
225
  - lib/wasko/palette.rb
225
226
  - lib/wasko/terminal.rb
226
227
  - sample_generator.rb