ombre 0.0.3 → 1.0.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 +17 -16
- data/lib/ombre.rb +39 -13
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d8a4ddbfcbaa0f408f2bfc24ef443a72c8c66dd4167e2be8d68981ac8b29838
|
4
|
+
data.tar.gz: b69094d4367a287bf35a058b8c9b32f8b4af026a92a49045fb5cdc3a87e820b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 30326d68bfea689327dbb6852fb4cd46fd1cbe84a1fb5e422b58771eb402fccb5c7206116a05c5e6866883be4560bb3249c9e2b167c6613f0273d67cdad86b0d
|
7
|
+
data.tar.gz: 1084d2fecaca0e70de079434a92a54e68f52aa3068e2ab8999c9909f0784bd10113ecc0a0ed431643e8c60a8d5ff652597ce6ad8b96dec258fbbe8d508697f53
|
data/README.md
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
# Ruby Ombre
|
2
2
|
|
3
|
-
Ombre provides gradients for your terminal between any
|
3
|
+
Ombre provides gradients for your terminal between any number of RGB values.
|
4
4
|
|
5
5
|
## Features
|
6
6
|
|
7
|
-
* Horizontal, vertical, and diagonal
|
7
|
+
* Horizontal, vertical, and diagonal gradients for any number of colors.
|
8
8
|
## True Color Support
|
9
9
|
|
10
|
-
This will only look
|
10
|
+
This will only look good on terminals that support 24bit colors, for now.
|
11
11
|
|
12
12
|
## Setup
|
13
13
|
|
@@ -27,25 +27,26 @@ require 'ombre'
|
|
27
27
|
|
28
28
|
## Usage
|
29
29
|
|
30
|
-
There are
|
30
|
+
There are four main functions available for `Ombre`:
|
31
31
|
|
32
32
|
```ruby
|
33
|
-
#
|
33
|
+
# colors in the below functions should be an array of 24 bit hexidecimal RGB values as strings.
|
34
34
|
|
35
35
|
# Returns the block of text marked up with colors to create a horizontal gradient from left to right
|
36
|
-
Ombre.horizontal(
|
37
|
-
Ombre.horizontal("
|
36
|
+
Ombre.horizontal(text, colors)
|
37
|
+
Ombre.horizontal("############\n# #\n# Horiz. ###\n# Ombre ####\n# Test #####\n# From #####\n# Red ######\n# To #######\n# Blue #####\n# #\n############", ["FF0000", "0000FF"])
|
38
38
|
|
39
39
|
# Returns the block of text marked up with colors to create a vertical gradient from top to bottom
|
40
|
-
Ombre.vertical(
|
41
|
-
Ombre.vertical("
|
42
|
-
|
43
|
-
# Returns the block of text marked up with colors to create a diagonal gradient
|
44
|
-
Ombre.diagonal(
|
45
|
-
#
|
46
|
-
|
47
|
-
# from bottom-left to top-right
|
48
|
-
Ombre.
|
40
|
+
Ombre.vertical(text, colors)
|
41
|
+
Ombre.vertical("############\n# #\n# Vertical #\n# Ombre ####\n# Test #####\n# From #####\n# Red ######\n# To #######\n# Blue #####\n# #\n############", ["FF0000", "0000FF"])
|
42
|
+
|
43
|
+
# Returns the block of text marked up with colors to create a diagonal gradient from top-left to bottom-right
|
44
|
+
Ombre.diagonal(text, colors)
|
45
|
+
Ombre.diagonal("############\n# #\n# Diagonal #\n# Ombre ####\n# Test #####\n# From #####\n# Red ######\n# To #######\n# Blue #####\n# #\n############", ["FF0000", "0000FF"])
|
46
|
+
|
47
|
+
# Returns the block of text marked up with colors to create a diagonal gradient from bottom-left to top-right
|
48
|
+
Ombre.diagonal_up(text, colors)
|
49
|
+
Ombre.diagonal_up("############\n# #\n# Diagonal #\n# Ombre ####\n# Test #####\n# From #####\n# Red ######\n# To #######\n# Blue #####\n# #\n############", ["FF0000", "0000FF"])
|
49
50
|
```
|
50
51
|
|
51
52
|
|
data/lib/ombre.rb
CHANGED
@@ -1,51 +1,77 @@
|
|
1
1
|
class Ombre
|
2
|
-
def self.vertical
|
2
|
+
def self.vertical text, colors
|
3
3
|
text.lines.each_with_index.map do |line, i|
|
4
|
-
red, green, blue = get_offset_color
|
4
|
+
red, green, blue = get_offset_color colors, i/text.lines.count.to_f
|
5
5
|
color_text red, green, blue, line
|
6
6
|
end.join
|
7
7
|
end
|
8
8
|
|
9
|
-
def self.horizontal
|
9
|
+
def self.horizontal text, colors
|
10
10
|
text.lines.map do |line|
|
11
11
|
line.chars.each_with_index.map do |char, i|
|
12
|
-
red, green, blue = get_offset_color
|
12
|
+
red, green, blue = get_offset_color colors, i/text.lines.max.length.to_f
|
13
13
|
color_text red, green, blue, char
|
14
14
|
end.join
|
15
15
|
end.join
|
16
16
|
end
|
17
17
|
|
18
|
-
def self.diagonal
|
18
|
+
def self.diagonal text, colors
|
19
19
|
max_y = text.lines.count
|
20
20
|
max_x = text.lines.max.length
|
21
21
|
text.lines.each_with_index.map do |line, y|
|
22
22
|
line.chars.each_with_index.map do |char, x|
|
23
|
-
ratio =
|
24
|
-
red, green, blue = get_offset_color
|
23
|
+
ratio = (y + x)/(max_y + max_x).to_f
|
24
|
+
red, green, blue = get_offset_color colors, ratio
|
25
25
|
color_text red, green, blue, char
|
26
26
|
end.join
|
27
27
|
end.join
|
28
28
|
end
|
29
29
|
|
30
|
+
def self.diagonal_up text, colors
|
31
|
+
max_y = text.lines.count
|
32
|
+
max_x = text.lines.max.length
|
33
|
+
text.lines.each_with_index.map do |line, y|
|
34
|
+
line.chars.each_with_index.map do |char, x|
|
35
|
+
ratio = (max_y - y + x)/(max_y + max_x).to_f
|
36
|
+
red, green, blue = get_offset_color colors, ratio
|
37
|
+
color_text red, green, blue, char
|
38
|
+
end.join
|
39
|
+
end.join
|
40
|
+
end
|
41
|
+
|
30
42
|
private
|
31
43
|
|
32
44
|
def self.get_colors color
|
33
45
|
color = color.gsub('#','')
|
46
|
+
|
34
47
|
red = color[0..1].to_i(16).to_f
|
35
48
|
green = color[2..3].to_i(16).to_f
|
36
49
|
blue = color[4..5].to_i(16).to_f
|
50
|
+
|
37
51
|
[red, green, blue]
|
38
52
|
end
|
39
53
|
|
40
|
-
def self.get_offset_color
|
41
|
-
|
42
|
-
|
43
|
-
|
54
|
+
def self.get_offset_color colors, ratio
|
55
|
+
segment = -1
|
56
|
+
segment += 1 while ratio > (segment + 1)/(colors.count - 1).to_f && segment < colors.count - 2
|
57
|
+
|
58
|
+
color1 = colors[segment]
|
59
|
+
color2 = colors[segment+1]
|
60
|
+
|
61
|
+
percent = (ratio - segment/(colors.count-1).to_f)/(1/(colors.count-1).to_f)
|
62
|
+
|
63
|
+
r1, g1, b1 = get_colors color1
|
64
|
+
r2, g2, b2 = get_colors color2
|
65
|
+
|
66
|
+
r_dist = (r1-r2).abs * percent
|
44
67
|
red = r1 > r2 ? r1 - r_dist : r1 + r_dist
|
45
|
-
|
68
|
+
|
69
|
+
g_dist = (g1-g2).abs * percent
|
46
70
|
green = g1 > g2 ? g1 - g_dist : g1 + g_dist
|
47
|
-
|
71
|
+
|
72
|
+
b_dist = (b1-b2).abs * percent
|
48
73
|
blue = b1 > b2 ? b1 - b_dist : b1 + b_dist
|
74
|
+
|
49
75
|
[red, green, blue]
|
50
76
|
end
|
51
77
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ombre
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Paulson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-04-
|
11
|
+
date: 2022-04-25 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Provides gradient colors for command line output using RGB hex values.
|
14
14
|
email: jpaulson@hey.com
|