colsole 0.7.1 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +93 -61
- data/lib/colsole/compat.rb +55 -0
- data/lib/colsole/version.rb +2 -2
- data/lib/colsole.rb +100 -129
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2fd26345db2525e6804965d0686301be91d7c27d9fe3894550a781e73e1c2f72
|
4
|
+
data.tar.gz: f44de99c02442edeae3723d405be87fe29d845c130460ee16a23bf0aab254901
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff6fb2074275bf9479ab0ba400bec991aa1d5972488c0c21c143ab012851733452aca15549278d770f8427c05ff5bcfad077f53c2649860ceb063934ebe0cba0
|
7
|
+
data.tar.gz: 8bd0e29dc5216b94ade0bec78636122bf015bbe502061655312cf52aaecd4c3462bac97310bf4e5f35d7ad0a51ad9fe5f4093d806b36968b4597f9df3789574a
|
data/README.md
CHANGED
@@ -1,41 +1,37 @@
|
|
1
|
-
Colsole
|
2
|
-
==================================================
|
1
|
+
# Colsole
|
3
2
|
|
4
3
|
[![Gem Version](https://badge.fury.io/rb/colsole.svg)](https://badge.fury.io/rb/colsole)
|
5
|
-
[![Build Status](https://
|
4
|
+
[![Build Status](https://github.com/DannyBen/colsole/workflows/Test/badge.svg)](https://github.com/DannyBen/colsole/actions?query=workflow%3ATest)
|
6
5
|
[![Maintainability](https://api.codeclimate.com/v1/badges/0556015f7cd2080531a1/maintainability)](https://codeclimate.com/github/DannyBen/colsole/maintainability)
|
7
|
-
[![Test Coverage](https://api.codeclimate.com/v1/badges/0556015f7cd2080531a1/test_coverage)](https://codeclimate.com/github/DannyBen/colsole/test_coverage)
|
8
6
|
|
9
7
|
---
|
10
8
|
|
11
9
|
Utility functions for colorful console applications.
|
12
10
|
|
13
|
-
|
11
|
+
> **Upgrade Note**
|
12
|
+
>
|
13
|
+
> This README is for the latest version of colsole (0.8.x), which is compatible
|
14
|
+
> with older versions. Version 1.x will NOT be compatible.
|
15
|
+
>
|
16
|
+
> See [Uprading](#upgrading) below.
|
14
17
|
|
18
|
+
## Install
|
15
19
|
|
16
|
-
|
17
|
-
--------------------------------------------------
|
20
|
+
Add to your Gemfile:
|
18
21
|
|
19
22
|
```
|
20
|
-
$ gem
|
23
|
+
$ gem 'colsole', '>= 0.6.0', '< 2.0'
|
21
24
|
```
|
22
25
|
|
23
|
-
|
24
|
-
--------------------------------------------------
|
25
|
-
|
26
|
-
- Print colored messages
|
27
|
-
- Color parts of a message
|
28
|
-
- Print neatly aligned status messages
|
29
|
-
- Word wrap with indentation consideration
|
26
|
+
## Examples
|
30
27
|
|
31
|
-
See the [Examples file]
|
28
|
+
See the [Examples file](https://github.com/DannyBen/colsole/blob/master/example.rb).
|
32
29
|
|
33
|
-
Primary Functions
|
34
|
-
--------------------------------------------------
|
30
|
+
## Primary Functions
|
35
31
|
|
36
32
|
### `say "anything"`
|
37
33
|
|
38
|
-
An alternative to puts.
|
34
|
+
An alternative to puts with line wrapping, colors and more.
|
39
35
|
|
40
36
|
```ruby
|
41
37
|
say "Hello"
|
@@ -48,30 +44,27 @@ say "appears in "
|
|
48
44
|
say "one line"
|
49
45
|
```
|
50
46
|
|
51
|
-
Embed color markers in the string:
|
47
|
+
Embed [color markers](#colors) in the string:
|
52
48
|
|
53
49
|
```ruby
|
54
|
-
say "
|
50
|
+
say "This is r`red`, and this gu`entire phrase is green underlined`"
|
55
51
|
```
|
56
52
|
|
57
|
-
|
58
|
-
|
59
|
-
Print a message with a colored status
|
53
|
+
Provide the `replace: true` option after a space terminated "said" string to
|
54
|
+
rewrite the line:
|
60
55
|
|
61
56
|
```ruby
|
62
|
-
|
57
|
+
# space terminated string to say it without a newline
|
58
|
+
say "downloading data... "
|
59
|
+
# long process here...
|
60
|
+
say "download complete.", replace: true
|
63
61
|
```
|
64
62
|
|
65
|
-
You can provide a color in the regulat 6 letter code:
|
66
|
-
|
67
|
-
```ruby
|
68
|
-
say_status :error, "does not compute", :txtred
|
69
|
-
```
|
70
63
|
|
71
64
|
### `word_wrap " string" [, length]`
|
72
65
|
|
73
|
-
Wrap long lines while keeping words intact, and keeping
|
74
|
-
|
66
|
+
Wrap long lines while keeping words intact, and keeping indentation based on the
|
67
|
+
leading spaces in your string:
|
75
68
|
|
76
69
|
```ruby
|
77
70
|
say word_wrap(" one two three four five", 15)
|
@@ -85,37 +78,21 @@ say word_wrap(" one two three four five", 15)
|
|
85
78
|
If `length` is not provided, `word_wrap` will attempt to determine it
|
86
79
|
automatically based on the width of the terminal.
|
87
80
|
|
88
|
-
|
89
|
-
### `resay "anything"`
|
90
|
-
|
91
|
-
Use resay after a space terminated "said" string to rewrite the line
|
92
|
-
|
93
|
-
```ruby
|
94
|
-
say "downloading... "
|
95
|
-
# long process here...
|
96
|
-
resay "downloaded."
|
97
|
-
```
|
98
|
-
|
99
|
-
|
100
81
|
### `say! "anything to stderr"`
|
101
82
|
|
102
83
|
Use say! to output to stderr with color markers:
|
103
84
|
|
104
85
|
```ruby
|
105
|
-
|
86
|
+
# red inverted ERROR
|
87
|
+
say! "ri` ERROR ` This just did not work"
|
106
88
|
```
|
107
89
|
|
108
|
-
Utility / Support Functions
|
109
|
-
--------------------------------------------------
|
90
|
+
## Utility / Support Functions
|
110
91
|
|
111
|
-
### `colorize "
|
92
|
+
### `colorize "string"`
|
112
93
|
|
113
94
|
Parses and returns a color-flagged string.
|
114
95
|
|
115
|
-
Respects pipe and auto terminates colored strings.
|
116
|
-
|
117
|
-
Call without text to see a list/demo of all available colors.
|
118
|
-
|
119
96
|
### `terminal?`
|
120
97
|
|
121
98
|
Returns true if we are running in an interactive terminal
|
@@ -124,21 +101,76 @@ Returns true if we are running in an interactive terminal
|
|
124
101
|
|
125
102
|
Checks if the provided string is a command in the path.
|
126
103
|
|
127
|
-
### `
|
104
|
+
### `terminal_size [fallback_cols, fallback_rows]`
|
128
105
|
|
129
106
|
Returns an array `[width, height]` of the terminal, or the supplied
|
130
|
-
|
107
|
+
fallback if it is unable to detect.
|
108
|
+
|
109
|
+
### `terminal_width` / `terminal_height`
|
110
|
+
|
111
|
+
Returns only the terminal width or height. This is a shortcut to
|
112
|
+
`terminal_size[0]` / terminal_size[1].
|
131
113
|
|
132
|
-
### `terminal_width`
|
133
114
|
|
134
|
-
|
135
|
-
`detect_terminal_size[0]`.
|
115
|
+
## Colors
|
136
116
|
|
117
|
+
Strings that are surrounded by backticks, and preceded by a color code and
|
118
|
+
optional styling markers will be converted to the respective ANSI color.
|
119
|
+
|
120
|
+
```ruby
|
121
|
+
say "this is b`blue` and ru`this is red underlined`"
|
122
|
+
```
|
137
123
|
|
138
|
-
|
139
|
-
--------------------------------------------------
|
124
|
+
The one letter color code is required, followed by up to 3 style code.
|
140
125
|
|
141
|
-
|
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
|
142
137
|
|
138
|
+
| Style Code | Style
|
139
|
+
|------------|-------
|
140
|
+
| `b` | bold
|
141
|
+
| `u` | underlined
|
142
|
+
| `i` | inverted
|
143
|
+
| `z` | terminate
|
143
144
|
|
144
|
-
|
145
|
+
## Upgrading
|
146
|
+
|
147
|
+
Version 0.8.x changes several things, including the syntax of the color
|
148
|
+
markers. For easy transition, it is compatible with older versions.
|
149
|
+
|
150
|
+
Follow these steps to upgrade:
|
151
|
+
|
152
|
+
```ruby
|
153
|
+
|
154
|
+
# => Require a more flexible version
|
155
|
+
# change this
|
156
|
+
gem 'colsole'
|
157
|
+
# to this (to avoid conflicts with other gems that require 0.x)
|
158
|
+
gem 'colsole', '>= 0.6.0', '< 2.0'
|
159
|
+
|
160
|
+
# => Remove 'say_status'
|
161
|
+
# It will no longer be supported in 1.0.0
|
162
|
+
say_status "text"
|
163
|
+
|
164
|
+
# => Replace 'resay'
|
165
|
+
# 'resay' is replaced with 'say replace: true'
|
166
|
+
# change this
|
167
|
+
resay "text"
|
168
|
+
# to this
|
169
|
+
say "text", replace: true
|
170
|
+
|
171
|
+
# => Change color markers syntax
|
172
|
+
# replace this
|
173
|
+
say "the !txtblu!blue"
|
174
|
+
# with this
|
175
|
+
say "the b`blue`"
|
176
|
+
```
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# This file contains methods that are called by the main Colsole module
|
2
|
+
# for compatibility with older versions of colsole.
|
3
|
+
# Do not use these methods directly.
|
4
|
+
module Colsole
|
5
|
+
def old_colorize(text)
|
6
|
+
reset = colors['txtrst']
|
7
|
+
reset_called_last = true
|
8
|
+
|
9
|
+
out = text.gsub(/!([a-z]{6})!/) do
|
10
|
+
reset_called_last = $1 == 'txtrst'
|
11
|
+
colors[$1]
|
12
|
+
end
|
13
|
+
|
14
|
+
reset_called_last or out = "#{out}#{reset}"
|
15
|
+
out
|
16
|
+
end
|
17
|
+
|
18
|
+
def old_strip_colors(text)
|
19
|
+
text.gsub(/!([a-z]{6})!/, '')
|
20
|
+
end
|
21
|
+
|
22
|
+
def resay(text)
|
23
|
+
say text, replace: true
|
24
|
+
end
|
25
|
+
|
26
|
+
def say_status(status, message = nil, color = nil)
|
27
|
+
color ||= (message ? :txtgrn : :txtblu)
|
28
|
+
say "!#{color}!#{status.to_s.rjust 12} !txtrst! #{message}".strip
|
29
|
+
end
|
30
|
+
|
31
|
+
def colors
|
32
|
+
@colors ||= begin
|
33
|
+
esc = 27.chr
|
34
|
+
pattern = "#{esc}[%{decor};%{fg}m"
|
35
|
+
|
36
|
+
decors = { txt: 0, bld: 1, und: 4, rev: 7 }
|
37
|
+
color_codes = { blk: 0, red: 1, grn: 2, ylw: 3, blu: 4, pur: 5, cyn: 6, wht: 7 }
|
38
|
+
colors = {}
|
39
|
+
|
40
|
+
decors.each do |dk, dv|
|
41
|
+
color_codes.each do |ck, cv|
|
42
|
+
key = "#{dk}#{ck}"
|
43
|
+
val = pattern % { decor: dv, fg: "3#{cv}" }
|
44
|
+
colors[key] = val
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
colors['txtbld'] = "#{esc}[1m"
|
49
|
+
colors['txtund'] = "#{esc}[4m"
|
50
|
+
colors['txtrev'] = "#{esc}[7m"
|
51
|
+
colors['txtrst'] = "#{esc}[0m"
|
52
|
+
colors
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/lib/colsole/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module Colsole
|
2
|
-
VERSION =
|
3
|
-
end
|
2
|
+
VERSION = '0.8.0'
|
3
|
+
end
|
data/lib/colsole.rb
CHANGED
@@ -1,111 +1,99 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
# Colsole - Colorful Console Applications
|
4
|
-
#
|
5
|
-
# This class provides several utility functions for console application
|
6
|
-
# developers.
|
7
|
-
#
|
8
|
-
# - #colorize string - return a colorized strings
|
9
|
-
# - #say string - print a string with colors
|
10
|
-
# - #say! string - print a string with colors to stderr
|
11
|
-
# - #resay string - same as say, but overwrite current line
|
12
|
-
# - #say_status symbol, string [, color] - print a message with status
|
13
|
-
# - #word_wrap string - wrap a string and maintain indentation
|
14
|
-
# - #detect_terminal_size
|
15
|
-
# - #terminal_width
|
16
|
-
#
|
17
|
-
# Credits:
|
18
|
-
# terminal width detection by Gabrial Horner https://github.com/cldwalker
|
1
|
+
require 'io/console'
|
2
|
+
require 'colsole/compat'
|
19
3
|
|
4
|
+
# Utility functions for colorful console applications.
|
20
5
|
module Colsole
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
6
|
+
ANSI_COLORS = {
|
7
|
+
'n' => '', # no color
|
8
|
+
'k' => "\e[30m", # black
|
9
|
+
'r' => "\e[31m", # red
|
10
|
+
'g' => "\e[32m", # green
|
11
|
+
'y' => "\e[33m", # yellow
|
12
|
+
'b' => "\e[34m", # blue
|
13
|
+
'm' => "\e[35m", # magenta
|
14
|
+
'c' => "\e[36m", # cyan
|
15
|
+
'w' => "\e[37m", # white
|
16
|
+
}
|
17
|
+
|
18
|
+
ANSI_STYLES = {
|
19
|
+
'b' => "\e[1m", # bold
|
20
|
+
'u' => "\e[4m", # underlined
|
21
|
+
'i' => "\e[7m", # inverted
|
22
|
+
'z' => "\e[0m", # terminate
|
23
|
+
}
|
24
|
+
|
25
|
+
# Output a string with optional color markers to stdout.
|
26
|
+
# If text is ended with a white space, you can call again with replace: true
|
27
|
+
# to replace that line
|
28
|
+
def say(text, replace: false)
|
29
|
+
internal_say text, $stdout, replace: replace
|
30
|
+
end
|
31
|
+
|
32
|
+
# Output a string with optional color markers to stderr.
|
33
|
+
# Behaves similarly to `#say`.
|
34
|
+
def say!(text, replace: false)
|
35
|
+
internal_say text, $stderr, replace: replace
|
36
|
+
end
|
37
|
+
|
38
|
+
# Returns true if stdout/stderr are a terminal
|
39
|
+
def terminal?(stream = $stdout)
|
40
|
+
case ENV['TTY']
|
41
|
+
when 'on' then true
|
42
|
+
when 'off' then false
|
28
43
|
else
|
29
|
-
|
44
|
+
stream.tty?
|
30
45
|
end
|
31
46
|
end
|
32
47
|
|
33
|
-
#
|
34
|
-
# Use color flags (like !txtred!) to change color in the string.
|
35
|
-
def say!(text, force_color=false)
|
36
|
-
$stderr.puts colorize(text, force_color, :stderr)
|
37
|
-
end
|
38
|
-
|
39
|
-
# Erase the current output line, and say a new string.
|
40
|
-
# This should be used after a space terminated say().
|
41
|
-
def resay(text, force_color=false)
|
42
|
-
text = "\033[2K\r#{text}" if terminal?
|
43
|
-
say text, force_color
|
44
|
-
end
|
45
|
-
|
46
|
-
# Prints a line with a colored status and message.
|
47
|
-
# Status can be a symbol or a string. Color is optional, defaults to
|
48
|
-
# green (:txtgrn) when there is a message, and to blue (:txtblu) when
|
49
|
-
# there is only a status
|
50
|
-
def say_status(status, message=nil, color=nil)
|
51
|
-
color ||= (message ? :txtgrn : :txtblu)
|
52
|
-
say "!#{color}!#{status.to_s.rjust 12} !txtrst! #{message}".strip
|
53
|
-
end
|
54
|
-
|
55
|
-
# Returns true if stdout/stderr is interactive terminal
|
56
|
-
def terminal?(stream=:stdout)
|
57
|
-
stream == :stdout ? out_terminal? : err_terminal?
|
58
|
-
end
|
59
|
-
|
60
|
-
# Returns true if stdout is interactive terminal
|
61
|
-
def out_terminal?
|
62
|
-
ENV['TTY'] == 'on' ? true : ENV['TTY'] == 'off' ? false : $stdout.tty?
|
63
|
-
end
|
64
|
-
|
65
|
-
# Returns true if stderr is interactive terminal
|
66
|
-
def err_terminal?
|
67
|
-
ENV['TTY'] == 'on' ? true : ENV['TTY'] == 'off' ? false : $stderr.tty?
|
68
|
-
end
|
69
|
-
|
70
|
-
# Determines if a shell command exists.
|
48
|
+
# Returns true if the command exists in the path
|
71
49
|
def command_exist?(command)
|
72
50
|
ENV['PATH'].split(File::PATH_SEPARATOR).any? do |dir|
|
73
51
|
File.exist?(File.join dir, command) or File.exist?(File.join dir, "#{command}.exe")
|
74
52
|
end
|
75
53
|
end
|
76
54
|
|
77
|
-
# Returns
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
55
|
+
# Returns true if we can and should use colors in this stream
|
56
|
+
def use_colors?(stream = $stdout)
|
57
|
+
ENV['FORCE_COLOR'] || (!ENV['NO_COLOR'] && terminal?(stream))
|
58
|
+
end
|
59
|
+
|
60
|
+
# Returns the terminal size as [columns, rows].
|
61
|
+
# Environment variables can be used to cheat.
|
62
|
+
def terminal_size(default = [80, 30])
|
63
|
+
result = if (ENV['COLUMNS'] =~ /^\d+$/) && (ENV['LINES'] =~ /^\d+$/)
|
64
|
+
[ENV['COLUMNS'].to_i, ENV['LINES'].to_i]
|
86
65
|
else
|
66
|
+
safe_get_tty_size default
|
67
|
+
end
|
68
|
+
|
69
|
+
unless result[0].is_a?(Integer) && result[1].is_a?(Integer) && result[0].positive? && result[1].positive?
|
87
70
|
result = default
|
88
71
|
end
|
89
|
-
|
72
|
+
|
90
73
|
result
|
91
74
|
end
|
92
75
|
|
93
|
-
# Returns
|
76
|
+
# Returns the columns part of the `#terminal_size`
|
94
77
|
def terminal_width
|
95
|
-
|
78
|
+
terminal_size[0]
|
79
|
+
end
|
80
|
+
|
81
|
+
# Returns the rows part of the `#terminal_size`
|
82
|
+
def terminal_height
|
83
|
+
terminal_size[1]
|
96
84
|
end
|
97
85
|
|
98
86
|
# Converts a long string to be wrapped keeping words in tact.
|
99
|
-
# If the string starts with one or more spaces, they will be
|
100
|
-
#
|
101
|
-
def word_wrap(text, length=nil)
|
87
|
+
# If the string starts with one or more spaces, they will be preserved in
|
88
|
+
# all subsequent lines (i.e., remain indented).
|
89
|
+
def word_wrap(text, length = nil)
|
102
90
|
length ||= terminal_width
|
103
91
|
lead = text[/^\s*/]
|
104
92
|
text.strip!
|
105
93
|
length -= lead.length
|
106
94
|
text.split("\n").collect! do |line|
|
107
95
|
if line.length > length
|
108
|
-
line.gsub!(/([^\s]{#{length}})([^\s$])/,
|
96
|
+
line.gsub!(/([^\s]{#{length}})([^\s$])/, '\\1 \\2')
|
109
97
|
line.gsub(/(.{1,#{length}})(\s+|$)/, "#{lead}\\1\n").rstrip
|
110
98
|
else
|
111
99
|
"#{lead}#{line}"
|
@@ -113,67 +101,50 @@ module Colsole
|
|
113
101
|
end * "\n"
|
114
102
|
end
|
115
103
|
|
116
|
-
#
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
104
|
+
# Convert color markers to ansi colors.
|
105
|
+
def colorize(string)
|
106
|
+
# compatibility later
|
107
|
+
compat_string = old_colorize string
|
108
|
+
|
109
|
+
process_color_markers compat_string do |color, styles, text|
|
110
|
+
"#{styles}#{color}#{text}#{ANSI_STYLES['z']}"
|
111
|
+
end
|
123
112
|
end
|
124
113
|
|
125
|
-
|
114
|
+
# Remove color markers.
|
115
|
+
def strip_colors(string)
|
116
|
+
# compatibility layer
|
117
|
+
compat_string = old_strip_colors string
|
126
118
|
|
127
|
-
|
128
|
-
@colors ||= prepare_colors
|
119
|
+
process_color_markers(compat_string) { |_color, _styles, text| text }
|
129
120
|
end
|
130
121
|
|
131
|
-
|
132
|
-
reset = colors['txtrst']
|
133
|
-
reset_called_last = true
|
122
|
+
private
|
134
123
|
|
135
|
-
|
136
|
-
|
137
|
-
|
124
|
+
def process_color_markers(string)
|
125
|
+
string.gsub(/([rgybmcn])([ubi]{0,3})`([^`]*)`/) do
|
126
|
+
color = ANSI_COLORS[$1]
|
127
|
+
styles = $2.chars.map { |a| ANSI_STYLES[a] }.join
|
128
|
+
text = $3
|
129
|
+
yield color, styles, text
|
138
130
|
end
|
139
|
-
|
140
|
-
reset_called_last or out = "#{out}#{reset}";
|
141
|
-
out
|
142
131
|
end
|
143
132
|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
# pattern_full = "#{esc}[%{decor};%{fg};%{bg}m"
|
149
|
-
pattern_fg = "#{esc}[%{decor};%{fg}m"
|
150
|
-
pattern_reset = "#{esc}[0m"
|
151
|
-
|
152
|
-
decors = { txt: 0, bld: 1, und: 4, rev: 7 }
|
153
|
-
color_codes = { blk: 0, red: 1, grn: 2, ylw: 3, blu: 4, pur: 5, cyn: 6, wht: 7 }
|
154
|
-
colors = {}
|
155
|
-
|
156
|
-
decors.each do |dk, dv|
|
157
|
-
color_codes.each do |ck, cv|
|
158
|
-
key = "#{dk}#{ck}"
|
159
|
-
val = pattern_fg % { decor: dv, fg: "3#{cv}" }
|
160
|
-
colors[key] = val
|
161
|
-
end
|
162
|
-
end
|
163
|
-
colors['txtrst'] = pattern_reset
|
164
|
-
colors
|
165
|
-
end
|
133
|
+
def internal_say(text, stream, replace: false)
|
134
|
+
text = "\033[2K\r#{text}" if replace && terminal?
|
135
|
+
last = text[-1, 1]
|
136
|
+
handler = use_colors?(stream) ? :colorize : :strip_colors
|
166
137
|
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
i -= 1
|
138
|
+
if terminal? && ((last == ' ') || (last == '\t'))
|
139
|
+
stream.print send(handler, text)
|
140
|
+
else
|
141
|
+
stream.print send(handler, "#{text}\n")
|
172
142
|
end
|
173
143
|
end
|
174
144
|
|
175
|
-
def
|
176
|
-
|
145
|
+
def safe_get_tty_size(default = [80, 30])
|
146
|
+
$stdout.winsize.reverse
|
147
|
+
rescue Errno::ENOTTY
|
148
|
+
default
|
177
149
|
end
|
178
|
-
|
179
150
|
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.
|
4
|
+
version: 0.8.0
|
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:
|
11
|
+
date: 2023-01-20 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Utility functions for making colorful console applications
|
14
14
|
email: db@dannyben.com
|
@@ -18,11 +18,13 @@ extra_rdoc_files: []
|
|
18
18
|
files:
|
19
19
|
- README.md
|
20
20
|
- lib/colsole.rb
|
21
|
+
- lib/colsole/compat.rb
|
21
22
|
- lib/colsole/version.rb
|
22
23
|
homepage: https://github.com/DannyBen/colsole
|
23
24
|
licenses:
|
24
25
|
- MIT
|
25
|
-
metadata:
|
26
|
+
metadata:
|
27
|
+
rubygems_mfa_required: 'true'
|
26
28
|
post_install_message:
|
27
29
|
rdoc_options: []
|
28
30
|
require_paths:
|
@@ -31,14 +33,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
31
33
|
requirements:
|
32
34
|
- - ">="
|
33
35
|
- !ruby/object:Gem::Version
|
34
|
-
version: 2.
|
36
|
+
version: 2.6.0
|
35
37
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
38
|
requirements:
|
37
39
|
- - ">="
|
38
40
|
- !ruby/object:Gem::Version
|
39
41
|
version: '0'
|
40
42
|
requirements: []
|
41
|
-
rubygems_version: 3.
|
43
|
+
rubygems_version: 3.4.3
|
42
44
|
signing_key:
|
43
45
|
specification_version: 4
|
44
46
|
summary: Colorful Console Applications
|