dag-amazing 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. data/LICENSE +202 -0
  2. data/README.rdoc +72 -0
  3. data/bin/amazing +19 -0
  4. data/lib/amazing.rb +24 -0
  5. data/lib/amazing/awesome.rb +46 -0
  6. data/lib/amazing/cli.rb +66 -0
  7. data/lib/amazing/cli/commands.rb +240 -0
  8. data/lib/amazing/cli/helpers.rb +159 -0
  9. data/lib/amazing/cli/initializers.rb +60 -0
  10. data/lib/amazing/config.rb +66 -0
  11. data/lib/amazing/config/dsl.rb +32 -0
  12. data/lib/amazing/config/dsl/awesome.rb +26 -0
  13. data/lib/amazing/config/dsl/awesome/widget.rb +27 -0
  14. data/lib/amazing/config/yaml.rb +11 -0
  15. data/lib/amazing/helpers/pango_markup.rb +26 -0
  16. data/lib/amazing/numeric.rb +50 -0
  17. data/lib/amazing/options.rb +93 -0
  18. data/lib/amazing/proc_file.rb +59 -0
  19. data/lib/amazing/string.rb +19 -0
  20. data/lib/amazing/widget.rb +140 -0
  21. data/lib/amazing/widgets.rb +37 -0
  22. data/lib/amazing/widgets/ac_adapter.rb +31 -0
  23. data/lib/amazing/widgets/alsa.rb +35 -0
  24. data/lib/amazing/widgets/battery.rb +51 -0
  25. data/lib/amazing/widgets/clock.rb +31 -0
  26. data/lib/amazing/widgets/cpu_info.rb +35 -0
  27. data/lib/amazing/widgets/cpu_usage.rb +50 -0
  28. data/lib/amazing/widgets/file.rb +44 -0
  29. data/lib/amazing/widgets/file_system.rb +42 -0
  30. data/lib/amazing/widgets/gmail.rb +61 -0
  31. data/lib/amazing/widgets/maildir.rb +34 -0
  32. data/lib/amazing/widgets/memory.rb +47 -0
  33. data/lib/amazing/widgets/moc.rb +80 -0
  34. data/lib/amazing/widgets/mpd.rb +146 -0
  35. data/lib/amazing/widgets/net_traffic.rb +50 -0
  36. data/lib/amazing/widgets/noop.rb +24 -0
  37. data/lib/amazing/widgets/pacman.rb +34 -0
  38. data/lib/amazing/widgets/raggle.rb +42 -0
  39. data/lib/amazing/widgets/sup.rb +38 -0
  40. data/lib/amazing/x11.rb +15 -0
  41. data/lib/amazing/x11/display_name.rb +50 -0
  42. metadata +101 -0
data/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
data/README.rdoc ADDED
@@ -0,0 +1,72 @@
1
+ = An amazing widget manager for an awesome window manager
2
+
3
+ * Feeds information to statusbars in the {awesome window manager}[http://awesome.naquadah.org/]
4
+ * Framework for creating widgets
5
+ * Centralized configuration
6
+
7
+ Widgets included in the core:
8
+
9
+ *AcAdapter*:: AC adapter status
10
+ *Alsa*:: Various data for the ALSA mixer
11
+ *Battery*:: Remaining battery power in percentage
12
+ *CpuInfo*:: CPU Information
13
+ *CpuUsage*:: CPU usage
14
+ *Clock*:: Displays date and time
15
+ *File*:: Information for a file
16
+ *FileSystem*:: Various filesystem information
17
+ *Gmail*:: GMail checker
18
+ *Moc*:: Music On Console status
19
+ *Mpd*:: MPD Information
20
+ *Maildir*:: Mail count in maildirs
21
+ *Memory*:: Various memory related data
22
+ *NetTraffic*:: Network traffic information
23
+ *Noop*:: Does nothing
24
+ *Pacman*:: Available upgrades in the Pacman package manager
25
+ *Raggle*:: Unread posts in raggle
26
+ *Sup*:: Mail count in sup for the specified search terms
27
+
28
+ == Installation procedures
29
+
30
+ To install, see <tt>ruby setup.rb --help</tt>. Quick and dirty:
31
+
32
+ # ruby setup.rb all
33
+
34
+ If you wish to install with Rubygems, build the gempackage and install it locally.
35
+
36
+ % gem build amazing.gemspec
37
+ # gem install amazing-0.1.gem
38
+
39
+ You can also install it remotely from the Rubyforge servers (not yet).
40
+
41
+ # gem install amazing
42
+
43
+ == Configuration
44
+
45
+ Configuration of amazing is {documented at the wiki}[http://github.com/dag/amazing/wikis/configuration].
46
+
47
+ == Git repositories
48
+
49
+ *GitHub*:: http://github.com/dag/amazing
50
+ *Gitorious*:: http://gitorious.org/projects/amazing
51
+
52
+ == Mail list
53
+
54
+ <b>amazing-talk</b>:: http://groups.google.com/group/amazing-talk
55
+
56
+ == Issues
57
+ *Lighthouse*:: http://amazing.lighthouseapp.com
58
+
59
+ == Copying
60
+
61
+ Copyright 2008 Dag Odenhall <dag.odenhall@gmail.com>
62
+
63
+ Licensed under the Apache License, Version 2.0 (the "License").
64
+ You may obtain a copy of the License at
65
+
66
+ http://www.apache.org/licenses/LICENSE-2.0
67
+
68
+ Unless required by applicable law or agreed to in writing, software
69
+ distributed under the License is distributed on an "AS IS" BASIS,
70
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
71
+ See the License for the specific language governing permissions and
72
+ limitations under the License.
data/bin/amazing ADDED
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Copyright 2008 Dag Odenhall <dag.odenhall@gmail.com>
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require 'amazing/cli'
18
+
19
+ Amazing::CLI.new(ARGV).run
data/lib/amazing.rb ADDED
@@ -0,0 +1,24 @@
1
+ # Copyright 2008 Dag Odenhall <dag.odenhall@gmail.com>
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'amazing/awesome'
16
+ require 'amazing/cli'
17
+ require 'amazing/config'
18
+ require 'amazing/numeric'
19
+ require 'amazing/options'
20
+ require 'amazing/proc_file'
21
+ require 'amazing/string'
22
+ require 'amazing/widget'
23
+ require 'amazing/widgets'
24
+ require 'amazing/x11'
@@ -0,0 +1,46 @@
1
+ # Copyright 2008 Dag Odenhall <dag.odenhall@gmail.com>
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'socket'
16
+
17
+ module Amazing
18
+
19
+ # Communicate with awesome
20
+ #
21
+ # awesome = Awesome.new
22
+ # awesome.widget_tell(0, widget_id, "Hello, world")
23
+ # awesome = Awesome.new(1)
24
+ # awesome.tag_view(0, 3)
25
+ # Awesome.new.client_zoom
26
+ class Awesome
27
+ attr_accessor :screen, :display
28
+
29
+ def initialize(display=0)
30
+ @display = display
31
+ end
32
+
33
+ def method_missing(uicb, screen=0, *args)
34
+ data = "#{screen} #{uicb} #{args.join(' ')}\n"
35
+ __setup_socket__
36
+ @socket.write(data)
37
+ end
38
+
39
+ private
40
+
41
+ def __setup_socket__
42
+ @socket = Socket.new(Socket::AF_UNIX, Socket::SOCK_DGRAM, 0)
43
+ @socket.connect(Socket.sockaddr_un("#{ENV["HOME"]}/.awesome_ctl.#@display"))
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,66 @@
1
+ # Copyright 2008 Dag Odenhall <dag.odenhall@gmail.com>
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'amazing'
16
+ require 'amazing/cli/commands'
17
+ require 'amazing/cli/helpers'
18
+ require 'amazing/cli/initializers'
19
+ require 'fileutils'
20
+ require 'logger'
21
+ require 'thread'
22
+ require 'timeout'
23
+ require 'yaml'
24
+
25
+ module Amazing
26
+
27
+ # Command line interface runner
28
+ #
29
+ # CLI.new(ARGV).run
30
+ class CLI
31
+ include Initializers
32
+ include Helpers
33
+ include Commands
34
+
35
+ def initialize(args=ARGV)
36
+ @args = args
37
+ initialize_threads
38
+ initialize_encoding
39
+ initialize_logger
40
+ initialize_options
41
+ initialize_display
42
+ initialize_awesome
43
+ initialize_exit
44
+ end
45
+
46
+ def run
47
+ parse_options
48
+ cmd_show_help
49
+ cmd_scaffold
50
+ set_loglevel
51
+ cmd_stop_process
52
+ load_scripts
53
+ cmd_list_widgets
54
+ cmd_test_widget
55
+ parse_config
56
+ wait_for_sockets
57
+ cmd_explicit_updates
58
+ stop_process
59
+ save_pid
60
+ set_traps
61
+ update_non_interval
62
+ cmd_main
63
+ join_threads
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,240 @@
1
+ # Copyright 2008 Dag Odenhall <dag.odenhall@gmail.com>
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ module Amazing
16
+ class CLI
17
+ module Commands
18
+ private
19
+
20
+ def cmd_show_help
21
+ if @options[:help]
22
+ puts @options.help
23
+ exit
24
+ end
25
+ end
26
+
27
+ def cmd_scaffold
28
+ if @options[:scaffold]
29
+ list = {}
30
+ screen, statusbar = nil, nil
31
+
32
+ File.readlines(@options[:scaffold]).each do |line|
33
+ case line
34
+
35
+ when /^\s*screen .*(\d+)/
36
+ screen = $1.to_i
37
+ list[screen] = {}
38
+
39
+ when /^\s*statusbar[" ]*([^"\n ]+)/
40
+ statusbar = $1
41
+ list[screen][statusbar] = []
42
+
43
+ when /^\s*(graph|iconbox|progressbar|textbox)[" ]*([^"\n ]+)/
44
+ list[screen][statusbar] << [$1, $2]
45
+
46
+ when /^\s*data[" ]*([^"\n ]+)/
47
+ list[screen][statusbar][-1] << $1
48
+
49
+ end
50
+ end
51
+
52
+ list.each do |screen, statusbars|
53
+ statusbars.each do |statusbar, widgets|
54
+
55
+ puts "awesome {"
56
+ puts "#{'# ' if screen == 0} set :screen => %s" % screen
57
+ puts "#{'# ' if statusbar == "mystatusbar"} set :statusbar => %s" % statusbar.inspect
58
+ puts
59
+
60
+ widgets.each do |widget|
61
+ type, name, datas = widget[0], widget[1], widget[2..-1]
62
+ noop = !Amazing::Widgets.constants.include?(name.camel_case)
63
+
64
+ puts " widget(%s) {" % name.inspect
65
+ puts " set :module => :noop" if noop
66
+ puts "# set :module => %s" % name.to_sym.inspect unless noop
67
+ puts ' set :property => "image"' if type == "iconbox"
68
+ puts '# set :property => "text"' if type == "textbox"
69
+ puts " set :property => \"data %s\"" % datas[0] if datas.size == 1
70
+ puts " set :interval => 1"
71
+
72
+ Amazing::Widgets.const_get(name.camel_case).options.each do |option, data|
73
+ puts "# set %s => %s" % [option.inspect, data[:default].inspect]
74
+ end unless noop
75
+
76
+ if datas.size > 1
77
+ puts
78
+ datas.each do |data|
79
+ puts " property(\"data %s\") {" % data
80
+ puts " @default"
81
+ puts " }"
82
+ puts unless data == datas.last
83
+ end
84
+ end
85
+
86
+ puts " }"
87
+ puts unless name == widgets.last[1]
88
+ end
89
+
90
+ puts "}"
91
+ puts
92
+ end
93
+ end
94
+
95
+ exit
96
+ end
97
+ end
98
+
99
+ def cmd_stop_process
100
+ if @options[:stop]
101
+ stop_process(false)
102
+ exit
103
+ end
104
+ end
105
+
106
+ def cmd_list_widgets
107
+ if @options[:listwidgets]
108
+ if @options[:listwidgets] == true
109
+ longest_widget_name = Widgets.constants.inject {|a,b| a.length > b.length ? a : b }.length
110
+
111
+ Widgets.constants.sort.each do |widget|
112
+ widget_class = Widgets.const_get(widget)
113
+ puts "%-#{longest_widget_name}s : %s" % [widget, widget_class.description]
114
+ end
115
+
116
+ else
117
+ widget_class = Widgets.const_get(@options[:listwidgets].camel_case)
118
+
119
+ puts
120
+ puts "#{@options[:listwidgets].camel_case} - #{widget_class.description}"
121
+ puts
122
+
123
+ dependencies = widget_class.dependencies
124
+ unless dependencies.empty?
125
+ longest_dependency_name = dependencies.keys.inject {|a,b| a.to_s.length > b.to_s.length ? a : b }.to_s.length
126
+ longest_dependency_name = 10 if longest_dependency_name < 10
127
+ longest_description = dependencies.values.inject {|a,b| a.length > b.length ? a : b }.length
128
+ longest_description = 11 if longest_description < 11
129
+
130
+ puts " %-#{longest_dependency_name}s | DESCRIPTION" % "DEPENDENCY"
131
+ puts "-" * (longest_dependency_name + longest_description + 5)
132
+
133
+ dependencies.keys.sort.each do |dependency|
134
+ puts " %-#{longest_dependency_name}s | #{dependencies[dependency]}" % dependency
135
+ end
136
+
137
+ puts
138
+ end
139
+
140
+ options = widget_class.options
141
+
142
+ unless options.empty?
143
+ longest_option_name = options.keys.inject {|a,b| a.to_s.length > b.to_s.length ? a : b }.to_s.length
144
+ longest_option_name = 6 if longest_option_name < 6
145
+ longest_description = options.values.inject {|a,b| a[:description].length > b[:description].length ? a : b }[:description].length
146
+ longest_description = 11 if longest_description < 11
147
+ longest_default = options.values.inject {|a,b| a[:default].inspect.length > b[:default].inspect.length ? a : b }[:default].inspect.length
148
+ longest_default = 7 if longest_default < 7
149
+
150
+ puts " %-#{longest_option_name}s | %-#{longest_description}s | DEFAULT" % ["OPTION", "DESCRIPTION"]
151
+ puts "-" * (longest_option_name + longest_description + longest_default + 8)
152
+
153
+ options.keys.sort_by {|option| option.to_s }.each do |option|
154
+ puts " %-#{longest_option_name}s | %-#{longest_description}s | %s" % [option, options[option][:description], options[option][:default].inspect]
155
+ end
156
+
157
+ puts
158
+ end
159
+
160
+ fields = widget_class.fields
161
+
162
+ unless fields.empty?
163
+ longest_field_name = fields.keys.inject {|a,b| a.to_s.length > b.to_s.length ? a : b }.to_s.length
164
+ longest_field_name = 5 if longest_field_name < 5
165
+ longest_description = fields.values.inject {|a,b| a[:description].length > b[:description].length ? a : b }[:description].length
166
+ longest_description = 11 if longest_description < 11
167
+ longest_default = fields.values.inject {|a,b| a[:default].inspect.length > b[:default].inspect.length ? a : b }[:default].inspect.length
168
+ longest_default = 7 if longest_default < 7
169
+
170
+ puts " %-#{longest_field_name + 1}s | %-#{longest_description}s | DEFAULT" % ["FIELD", "DESCRIPTION"]
171
+ puts "-" * (longest_field_name + longest_description + longest_default + 9)
172
+
173
+ fields.keys.sort_by {|field| field.to_s }.each do |field|
174
+ puts " @%-#{longest_field_name}s | %-#{longest_description}s | %s" % [field, fields[field][:description], fields[field][:default].inspect]
175
+ end
176
+
177
+ puts
178
+ end
179
+ end
180
+
181
+ exit
182
+ end
183
+ end
184
+
185
+ def cmd_test_widget
186
+ if @options[:test]
187
+ widget = Widgets.const_get(@options[:test].camel_case)
188
+ settings = YAML.load("{#{ARGV[0]}}")
189
+ instance = widget.new(settings)
190
+ longest_field_name = widget.fields.merge({:default => nil}).keys.inject {|a,b| a.to_s.length > b.to_s.length ? a : b }.to_s.length
191
+
192
+ puts "@%-#{longest_field_name}s = %s" % [:default, instance.instance_variable_get(:@default).inspect]
193
+
194
+ widget.fields.keys.sort_by {|field| field.to_s }.each do |field|
195
+ puts "@%-#{longest_field_name}s = %s" % [field, instance.instance_variable_get("@#{field}".to_sym).inspect]
196
+ end
197
+
198
+ exit
199
+ end
200
+ end
201
+
202
+ def cmd_explicit_updates
203
+ if @options[:update] != []
204
+ @config[:awesome].each do |awesome|
205
+ awesome[:widgets].each do |widget|
206
+ locator = "%s/%s/%s" % [widget[:identifier], awesome[:statusbar], awesome[:screen]]
207
+ next unless @options[:update] == :all || @options[:update].include?(locator)
208
+
209
+ @threads << Thread.new(awesome, widget) do |awesome, widget|
210
+ update_widget(awesome[:screen], awesome[:statusbar], widget)
211
+ end
212
+ end
213
+ end
214
+
215
+ @threads.each {|t| t.join }
216
+ exit
217
+ end
218
+ end
219
+
220
+ def cmd_main
221
+ @config[:awesome].each do |awesome|
222
+ awesome[:widgets].each do |widget|
223
+ if widget[:interval]
224
+ @threads << Thread.new(awesome, widget) do |awesome, widget|
225
+ iteration = 1
226
+
227
+ loop do
228
+ Thread.new { update_widget(awesome[:screen], awesome[:statusbar], widget, iteration) }
229
+
230
+ iteration += 1
231
+ sleep widget[:interval]
232
+ end
233
+ end
234
+ end
235
+ end
236
+ end
237
+ end
238
+ end
239
+ end
240
+ end