colsole 0.2.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d67b1de96558e878ebcca6575739a8ebf21859c1
4
- data.tar.gz: 177aa67473468527ee9cf9130a434cf03ec71f50
3
+ metadata.gz: b7915e753b4e367195f53df50fc430e2d40cffba
4
+ data.tar.gz: 70a32292b7d7cbc5432d5cf0882d77e76502ff4e
5
5
  SHA512:
6
- metadata.gz: c1fd6648989d636eea3ac9f665e24ca06b4bfe5654ed98ed51376cd40e3f0798563b529b179f7c0488ce6be60e53598aaeeec5235463967c55dfc889d00cc7b1
7
- data.tar.gz: 9a398e1d8bbafea7c87f2459524791d2227664d09f1b7b35f559b8cbe605425b9cfed7ec5d4e4337519d958e0feb16ea34735e98b9b42854d66b33c8a0bb39f9
6
+ metadata.gz: 78437a93f891e3798ddd1dbaf5c29b94b6f73fe95b3560a49978b4ee5dc70e3d1e47fa5fbbc549e028469e5a34011959ea396cb6af55da4b88df623086904387
7
+ data.tar.gz: 0ffb93928c7386adbdb25d1dec4a75d47a5b31e24a136ca16860840ecf45732727383a254769f433a8142646299049ae833e90612c22833d6cc08868d44cb900
data/README.md ADDED
@@ -0,0 +1,96 @@
1
+ Colsole
2
+ =======
3
+
4
+ [![Gem Version](https://badge.fury.io/rb/colsole.svg)](http://badge.fury.io/rb/colsole)
5
+ [![Build Status](https://travis-ci.org/DannyBen/colsole.svg?branch=master)](https://travis-ci.org/DannyBen/colsole)
6
+ [![Code Climate](https://codeclimate.com/github/DannyBen/colsole/badges/gpa.svg)](https://codeclimate.com/github/DannyBen/colsole)
7
+ [![Gem](https://img.shields.io/gem/dt/colsole.svg)](https://rubygems.org/gems/colsole)
8
+
9
+
10
+ Utility functions for colorful console applications.
11
+
12
+ ## Install
13
+
14
+ $ gem install colsole
15
+
16
+ ## Primary Functions
17
+
18
+ ### `say "anything"`
19
+
20
+ An alternative to puts.
21
+
22
+ ```ruby
23
+ say "Hello"
24
+ ```
25
+
26
+ Leave a trailing space to keep the cursor at the same line
27
+
28
+ ```ruby
29
+ say "appears in "
30
+ say "one line"
31
+ ```
32
+
33
+ Embed color markers in the string:
34
+
35
+ ```ruby
36
+ say "!txtred!I am RED !txtgrn!I am GREEN"
37
+ ```
38
+
39
+ ### `word_wrap " string"`
40
+
41
+ Wrap long lines while keeping words intact, and keeping
42
+ indentation based on the leading spaces in your string:
43
+
44
+ ```ruby
45
+ say word_wrap(" one two three four five", 15)
46
+
47
+ # output:
48
+ # one two
49
+ # three four
50
+ # five
51
+ ```
52
+
53
+
54
+ ### `resay "anything"`
55
+
56
+ Use resay after a space terminated "said" string to rewrite the line
57
+
58
+ ```ruby
59
+ say "downloading... "
60
+ # long process here...
61
+ resay "downloaded."
62
+ ```
63
+
64
+
65
+ ### `say! "anything to stderr"`
66
+
67
+ Use say! to output to stderr with color markers:
68
+
69
+ ```ruby
70
+ say! "!txtred!Error!txtrst!: This just did not work"
71
+ ```
72
+
73
+ ## Utility / Support Functions
74
+
75
+ ### `colorize "!txtred!Hello"`
76
+
77
+ Parses and returns a color-flagged string.
78
+
79
+ Respects pipe and auto terminates colored strings.
80
+
81
+ Call without text to see a list/demo of all available colors.
82
+
83
+
84
+ ### `terminal?`
85
+
86
+ Returns true if we are running in an interactive terminal
87
+
88
+ ### `command_exist? "some_executable"`
89
+
90
+ Checks if the provided string is a command in the path.
91
+
92
+ ### `detect_terminal_size fallback_value`
93
+
94
+ Returns an array [width, height] of the terminal, or the supplied
95
+ `fallback_value` if it is unable to detect.
96
+
data/lib/colsole.rb CHANGED
@@ -1,4 +1,6 @@
1
- # Colsole - Coloful Console Applications
1
+ require "colsole/version"
2
+
3
+ # Colsole - Colorful Console Applications
2
4
  #
3
5
  # This class provides several utility functions for console
4
6
  # appliucation developers.
@@ -13,28 +15,33 @@
13
15
  # terminal width detection by Gabrial Horner https://github.com/cldwalker
14
16
 
15
17
  module Colsole
16
-
17
18
  # Prints a color-flagged string.
18
19
  # Use color flags (like !txtred!) to change color in the string.
19
20
  # Space terminated strings will leave the cursor at the same line.
20
21
  def say(text, force_color=false)
21
22
  last = text[-1, 1]
22
23
  if last == ' ' or last == '\t'
23
- print colorize text, force_color
24
+ print colorize(text, force_color)
24
25
  else
25
- print colorize "#{text}\n", force_color;
26
+ print colorize("#{text}\n", force_color)
26
27
  end
27
28
  end
28
29
 
30
+ # Prints a color-flagged string to STDERR
31
+ # Use color flags (like !txtred!) to change color in the string.
32
+ def say!(text, force_color=false)
33
+ $stderr.puts colorize(text, force_color)
34
+ end
35
+
29
36
  # Erase the current output line, and say a new string.
30
37
  # This should be used after a space terminated say().
31
38
  def resay(text, force_color=false)
32
- is_terminal and text = "\033[2K\r#{text}"
39
+ terminal? and text = "\033[2K\r#{text}"
33
40
  say text, force_color
34
41
  end
35
42
 
36
43
  # Returns true if interactive terminal, false if piped.
37
- def is_terminal
44
+ def terminal?
38
45
  STDOUT.tty?
39
46
  end
40
47
 
@@ -82,7 +89,7 @@ module Colsole
82
89
  end
83
90
 
84
91
  reset = colors['txtrst']
85
- if is_terminal or force_color
92
+ if terminal? or force_color
86
93
  reset_called_last = true
87
94
 
88
95
  out = text.gsub(/\!([a-z]{6})\!/) do |m|
@@ -0,0 +1,3 @@
1
+ module Colsole
2
+ VERSION = "0.3.1"
3
+ end
metadata CHANGED
@@ -1,22 +1,108 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: colsole
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Ben Shitrit
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-17 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2015-12-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: runfile
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: run-gem-dev
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.2'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.8'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.8'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest-reporters
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.1'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.4'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.4'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.10'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.10'
13
97
  description: Utility functions for making colorful console applications
14
98
  email: db@dannyben.com
15
99
  executables: []
16
100
  extensions: []
17
101
  extra_rdoc_files: []
18
102
  files:
103
+ - README.md
19
104
  - lib/colsole.rb
105
+ - lib/colsole/version.rb
20
106
  homepage: https://github.com/DannyBen/colsole
21
107
  licenses:
22
108
  - MIT
@@ -42,4 +128,3 @@ signing_key:
42
128
  specification_version: 4
43
129
  summary: Colorful Console Applications
44
130
  test_files: []
45
- has_rdoc: