notice 0.0.1

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.
Files changed (2) hide show
  1. data/lib/notice.rb +48 -0
  2. metadata +64 -0
@@ -0,0 +1,48 @@
1
+ class Notice
2
+ @@STACK = {}
3
+ @@width = nil
4
+
5
+ STATES = {
6
+ :busy => "\x1B[1m[\x1B[0m\x1B[34mBUSY\x1B[0m\x1B[1m]\x1B[0m",
7
+ :fail => "\x1B[1m[\x1B[0m\x1B[1;31mFAIL\x1B[0m\x1B[1m]\x1B[0m",
8
+ :done => "\x1B[1m[\x1B[0m\x1B[1;32mDONE\x1B[0m\x1B[1m]\x1B[0m"
9
+ }
10
+
11
+ def initialize(name, &block)
12
+ @@width ||= get_width
13
+ line = create_line(name.dup)
14
+ @@STACK[name.to_s] ||= lambda { true }
15
+ @@STACK[name.to_s] = block if block
16
+ STDOUT.print line + STATES[:busy]
17
+ STDOUT.print "\r#{line}#{(@@STACK[name.to_s].call ? STATES[:done] : STATES[:fail])}\n"
18
+ end
19
+
20
+ def create_line(name)
21
+ name = if name.size > (@@width - 10)
22
+ name.gsub(/^(.{#{@@width - 10}}).*$/, '\1...')
23
+ else
24
+ name.ljust(@@width - 10, ' ')
25
+ end
26
+ " \x1B[1;34m::\x1B[0m \x1B[1m#{name}\x1B[0m"
27
+ end
28
+
29
+ def get_width
30
+ default = 80
31
+ begin
32
+ tiocgwinsz = 0x5413
33
+ data = [0, 0, 0, 0].pack('SSSS')
34
+ if STDOUT.ioctl(tiocgwinsz, data) >= 0
35
+ rows, cols, xpixels, ypixels = data.unpack('SSSS')
36
+ (cols >= 0 ? cols : default)
37
+ else
38
+ default
39
+ end
40
+ rescue Exception => e
41
+ default
42
+ end
43
+ end
44
+ end
45
+
46
+ def notice(name, &block)
47
+ Notice.new(name, &block)
48
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: notice
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - shura
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-10-07 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: Notify status of a block
22
+ email: shura1991@gmail.com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files: []
28
+
29
+ files:
30
+ - lib/notice.rb
31
+ has_rdoc: true
32
+ homepage: http://github.com/shurizzle/ruby-notice
33
+ licenses: []
34
+
35
+ post_install_message:
36
+ rdoc_options: []
37
+
38
+ require_paths:
39
+ - lib
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ segments:
46
+ - 0
47
+ version: "0"
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ segments:
54
+ - 0
55
+ version: "0"
56
+ requirements: []
57
+
58
+ rubyforge_project:
59
+ rubygems_version: 1.3.7
60
+ signing_key:
61
+ specification_version: 3
62
+ summary: Notify status of a block
63
+ test_files: []
64
+