colsole 0.8.0 → 0.8.2

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
  SHA256:
3
- metadata.gz: 2fd26345db2525e6804965d0686301be91d7c27d9fe3894550a781e73e1c2f72
4
- data.tar.gz: f44de99c02442edeae3723d405be87fe29d845c130460ee16a23bf0aab254901
3
+ metadata.gz: 277f45ee7c12e0c6090bd41752a275feef3357c38a1d3cbca522f9089ce68d49
4
+ data.tar.gz: f21a9866ce164222627f314c4ffe0c16046d705f5d544783b1d5f3598a54cf18
5
5
  SHA512:
6
- metadata.gz: ff6fb2074275bf9479ab0ba400bec991aa1d5972488c0c21c143ab012851733452aca15549278d770f8427c05ff5bcfad077f53c2649860ceb063934ebe0cba0
7
- data.tar.gz: 8bd0e29dc5216b94ade0bec78636122bf015bbe502061655312cf52aaecd4c3462bac97310bf4e5f35d7ad0a51ad9fe5f4093d806b36968b4597f9df3789574a
6
+ metadata.gz: c74ab05a5fea57685109cbcf2bdc033e0b0ba7f191a5ea491e4d31a1bcee335718d7e74481a031b19e99203e14dd34646542985199a001d15c2dbfc0dd52a8da
7
+ data.tar.gz: af3bcd3c64f66cc5dd5a89c96f4e92946160082ea08e017e68c3eda311525c6de5688759bdfe858d084231dae835d4c091ed9ca6af225f640ef2803a61b0e4d9
data/README.md CHANGED
@@ -9,10 +9,10 @@
9
9
  Utility functions for colorful console applications.
10
10
 
11
11
  > **Upgrade Note**
12
- >
12
+ >
13
13
  > This README is for the latest version of colsole (0.8.x), which is compatible
14
14
  > with older versions. Version 1.x will NOT be compatible.
15
- >
15
+ >
16
16
  > See [Uprading](#upgrading) below.
17
17
 
18
18
  ## Install
@@ -20,7 +20,22 @@ Utility functions for colorful console applications.
20
20
  Add to your Gemfile:
21
21
 
22
22
  ```
23
- $ gem 'colsole', '>= 0.6.0', '< 2.0'
23
+ $ gem 'colsole', '>= 0.8.1', '< 2.0'
24
+ ```
25
+
26
+ ## Usage
27
+
28
+ ```ruby
29
+ require 'colsole'
30
+ include Colsole
31
+ say 'b`Blue` Man Group'
32
+ ```
33
+
34
+ All the methods described below can also be called directly on the `Colsole` module. This is useful when you want to use it at the top level of your project, without namespace contamination:
35
+
36
+ ```ruby
37
+ require 'colsole'
38
+ Colsole.say 'b`Blue` Man Group'
24
39
  ```
25
40
 
26
41
  ## Examples
@@ -60,7 +75,6 @@ say "downloading data... "
60
75
  say "download complete.", replace: true
61
76
  ```
62
77
 
63
-
64
78
  ### `word_wrap " string" [, length]`
65
79
 
66
80
  Wrap long lines while keeping words intact, and keeping indentation based on the
@@ -111,7 +125,6 @@ fallback if it is unable to detect.
111
125
  Returns only the terminal width or height. This is a shortcut to
112
126
  `terminal_size[0]` / terminal_size[1].
113
127
 
114
-
115
128
  ## Colors
116
129
 
117
130
  Strings that are surrounded by backticks, and preceded by a color code and
@@ -123,24 +136,24 @@ say "this is b`blue` and ru`this is red underlined`"
123
136
 
124
137
  The one letter color code is required, followed by up to 3 style code.
125
138
 
126
- | Color Code | Color
127
- |------------|-------
128
- | `n` | no color
129
- | `k` | black
130
- | `r` | red
131
- | `g` | green
132
- | `y` | yellow
133
- | `b` | blue
134
- | `m` | magenta
135
- | `c` | cyan
136
- | `w` | white
137
-
138
- | Style Code | Style
139
- |------------|-------
140
- | `b` | bold
141
- | `u` | underlined
142
- | `i` | inverted
143
- | `z` | terminate
139
+ | Color Code | Color |
140
+ | ---------- | -------- |
141
+ | `n` | no color |
142
+ | `k` | black |
143
+ | `r` | red |
144
+ | `g` | green |
145
+ | `y` | yellow |
146
+ | `b` | blue |
147
+ | `m` | magenta |
148
+ | `c` | cyan |
149
+ | `w` | white |
150
+
151
+ | Style Code | Style |
152
+ | ---------- | ---------- |
153
+ | `b` | bold |
154
+ | `u` | underlined |
155
+ | `i` | inverted |
156
+ | `z` | terminate |
144
157
 
145
158
  ## Upgrading
146
159
 
@@ -150,12 +163,11 @@ markers. For easy transition, it is compatible with older versions.
150
163
  Follow these steps to upgrade:
151
164
 
152
165
  ```ruby
153
-
154
166
  # => Require a more flexible version
155
167
  # change this
156
168
  gem 'colsole'
157
- # to this (to avoid conflicts with other gems that require 0.x)
158
- gem 'colsole', '>= 0.6.0', '< 2.0'
169
+ # to this
170
+ gem 'colsole', '>= 0.8.1', '< 2.0'
159
171
 
160
172
  # => Remove 'say_status'
161
173
  # It will no longer be supported in 1.0.0
@@ -2,6 +2,12 @@
2
2
  # for compatibility with older versions of colsole.
3
3
  # Do not use these methods directly.
4
4
  module Colsole
5
+ module_function
6
+
7
+ def detect_terminal_size(*args)
8
+ terminal_size(*args)
9
+ end
10
+
5
11
  def old_colorize(text)
6
12
  reset = colors['txtrst']
7
13
  reset_called_last = true
@@ -1,3 +1,3 @@
1
1
  module Colsole
2
- VERSION = '0.8.0'
2
+ VERSION = '0.8.2'
3
3
  end
data/lib/colsole.rb CHANGED
@@ -22,6 +22,8 @@ module Colsole
22
22
  'z' => "\e[0m", # terminate
23
23
  }
24
24
 
25
+ module_function
26
+
25
27
  # Output a string with optional color markers to stdout.
26
28
  # If text is ended with a white space, you can call again with replace: true
27
29
  # to replace that line
@@ -119,8 +121,6 @@ module Colsole
119
121
  process_color_markers(compat_string) { |_color, _styles, text| text }
120
122
  end
121
123
 
122
- private
123
-
124
124
  def process_color_markers(string)
125
125
  string.gsub(/([rgybmcn])([ubi]{0,3})`([^`]*)`/) do
126
126
  color = ANSI_COLORS[$1]
@@ -143,8 +143,12 @@ private
143
143
  end
144
144
 
145
145
  def safe_get_tty_size(default = [80, 30])
146
- $stdout.winsize.reverse
147
- rescue Errno::ENOTTY
148
- default
146
+ return default unless IO.console
147
+
148
+ begin
149
+ IO.console.winsize.reverse
150
+ rescue Errno::ENOTTY
151
+ default
152
+ end
149
153
  end
150
154
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: colsole
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.8.2
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: 2023-01-20 00:00:00.000000000 Z
11
+ date: 2023-01-25 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Utility functions for making colorful console applications
14
14
  email: db@dannyben.com
@@ -40,7 +40,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0'
42
42
  requirements: []
43
- rubygems_version: 3.4.3
43
+ rubygems_version: 3.4.5
44
44
  signing_key:
45
45
  specification_version: 4
46
46
  summary: Colorful Console Applications