clit 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,10 @@
1
+ clit - CLI output
2
+ =================
3
+ clit is a simple library to have nice looking output in Ruby, it's themeable
4
+ and comes with few simple themes.
5
+
6
+ Adding themes
7
+ -------------
8
+ If you want to add new themes just fork and open a pull request adding the
9
+ themes to lib/clit/themes, they are automatically loaded so make sure to name
10
+ the file the same as the name of theme.
data/bin/clit-theme ADDED
@@ -0,0 +1,8 @@
1
+ #! /usr/bin/env ruby
2
+ require 'clit'
3
+
4
+ cli.theme(ARGV.shift.to_sym) unless ARGV.empty?
5
+
6
+ cli.theme.functions.each {|name|
7
+ cli.__send__ name, name, *(1.upto(cli.theme.method(name).arity - 1)).to_a
8
+ }
data/clit.gemspec ADDED
@@ -0,0 +1,16 @@
1
+ Gem::Specification.new {|s|
2
+ s.name = 'clit'
3
+ s.version = '0.0.1'
4
+ s.author = 'meh.'
5
+ s.email = 'meh@schizofreni.co'
6
+ s.homepage = 'http://github.com/meh/ruby-clit'
7
+ s.platform = Gem::Platform::RUBY
8
+ s.summary = 'Library for nice looking CLI output.'
9
+
10
+ s.files = `git ls-files`.split("\n")
11
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
12
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
13
+ s.require_paths = ['lib']
14
+
15
+ s.add_runtime_dependency 'colorb'
16
+ }
data/lib/clit.rb ADDED
@@ -0,0 +1,69 @@
1
+ #--
2
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
3
+ # Version 2, December 2004
4
+ #
5
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
6
+ # TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
7
+ #
8
+ # 0. You just DO WHAT THE FUCK YOU WANT TO.
9
+ #++
10
+
11
+ class Clit < BasicObject
12
+ autoload :Theme, 'clit/theme'
13
+
14
+ def self.themes
15
+ @themes ||= {}
16
+ end
17
+
18
+ def self.define_theme (name, &block)
19
+ if @themes[name]
20
+ raise ArgumentError, "#{name} already exists"
21
+ end
22
+
23
+ @themes[name] = ::Class.new(::Clit::Theme, &block).instance
24
+ end
25
+
26
+ def self.theme (name)
27
+ unless themes[name]
28
+ require "clit/themes/#{name}"
29
+ end
30
+
31
+ unless themes[name]
32
+ raise ::ArgumentError, "#{name} theme not found"
33
+ end
34
+
35
+ themes[name]
36
+ end
37
+
38
+ def initialize (name = :default)
39
+ theme(name)
40
+ end
41
+
42
+ def theme (name = nil)
43
+ name ? @theme = ::Clit.theme(name) : @theme
44
+ end
45
+
46
+ def respond_to_missing? (*args)
47
+ @theme.respond_to?(*args)
48
+ end
49
+
50
+ def method_missing (id, *args, &block)
51
+ if @theme.respond_to? id
52
+ return @theme.__send__ id, *args, &block
53
+ end
54
+
55
+ super
56
+ end
57
+ end
58
+
59
+ module Kernel
60
+ def cli
61
+ @clit ||= Clit.new
62
+ end
63
+
64
+ alias console cli
65
+ end
66
+
67
+ unless STDOUT.tty?
68
+ ENV['NO_COLORS'] = 'true'
69
+ end
data/lib/clit/theme.rb ADDED
@@ -0,0 +1,36 @@
1
+ #--
2
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
3
+ # Version 2, December 2004
4
+ #
5
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
6
+ # TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
7
+ #
8
+ # 0. You just DO WHAT THE FUCK YOU WANT TO.
9
+ #++
10
+
11
+ require 'singleton'
12
+ require 'colorb'
13
+
14
+ class Clit::Theme
15
+ include Singleton
16
+
17
+ def functions
18
+ methods - Object.instance_methods - [:functions]
19
+ end
20
+
21
+ def log (text)
22
+ puts text
23
+ end
24
+
25
+ def info (text)
26
+ puts text
27
+ end
28
+
29
+ def warn (text)
30
+ puts text
31
+ end
32
+
33
+ def error (text)
34
+ $stderr.puts text
35
+ end
36
+ end
@@ -0,0 +1,23 @@
1
+ #--
2
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
3
+ # Version 2, December 2004
4
+ #
5
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
6
+ # TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
7
+ #
8
+ # 0. You just DO WHAT THE FUCK YOU WANT TO.
9
+ #++
10
+
11
+ Clit.define_theme :compatible do
12
+ def info (text)
13
+ super "#{?i.blue} #{text}"
14
+ end
15
+
16
+ def warn (text)
17
+ super "#{?!.yellow} #{text}"
18
+ end
19
+
20
+ def error (text)
21
+ super "#{?x.red} #{text}"
22
+ end
23
+ end
@@ -0,0 +1,12 @@
1
+ #--
2
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
3
+ # Version 2, December 2004
4
+ #
5
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
6
+ # TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
7
+ #
8
+ # 0. You just DO WHAT THE FUCK YOU WANT TO.
9
+ #++
10
+
11
+ Clit.define_theme :default do
12
+ end
@@ -0,0 +1,24 @@
1
+ # encoding: utf-8
2
+ #--
3
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
4
+ # Version 2, December 2004
5
+ #
6
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
7
+ # TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
8
+ #
9
+ # 0. You just DO WHAT THE FUCK YOU WANT TO.
10
+ #++
11
+
12
+ Clit.define_theme :fancy do
13
+ def info (text)
14
+ super "#{?ℹ.blue} #{text}"
15
+ end
16
+
17
+ def warn (text)
18
+ super "#{?⚠.yellow} #{text}"
19
+ end
20
+
21
+ def error (text)
22
+ super "#{?✖.red} #{text}"
23
+ end
24
+ end
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: clit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - meh.
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: colorb
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description:
31
+ email: meh@schizofreni.co
32
+ executables:
33
+ - clit-theme
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - README.md
38
+ - bin/clit-theme
39
+ - clit.gemspec
40
+ - lib/clit.rb
41
+ - lib/clit/theme.rb
42
+ - lib/clit/themes/compatible.rb
43
+ - lib/clit/themes/default.rb
44
+ - lib/clit/themes/fancy.rb
45
+ homepage: http://github.com/meh/ruby-clit
46
+ licenses: []
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ requirements: []
64
+ rubyforge_project:
65
+ rubygems_version: 1.8.24
66
+ signing_key:
67
+ specification_version: 3
68
+ summary: Library for nice looking CLI output.
69
+ test_files: []