rbtext 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/rbtext/colors.rb +46 -0
- data/lib/rbtext/cursor.rb +25 -0
- data/lib/rbtext/formatting.rb +25 -0
- data/lib/rbtext/ftext.rb +49 -0
- data/lib/rbtext.rb +7 -0
- metadata +46 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 900615ce6538a03ee599ca779ff21b38a410beafc6ca4d0be682da20f2fce2eb
|
4
|
+
data.tar.gz: 4cf937b800c97cd5921f534bd8287d02ab03c4696909683d64c7dac648db3bec
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: '098f8361c963b5f9a6039ba4dfd92ee2dbcff148c7be5190a0b30caf8f2241f7d4a9f37e5674a5cffeb3ff6e68e584cdaf8cf9504b0feb0d5ca4cef3d802eec8'
|
7
|
+
data.tar.gz: b437c0dd983b6366fe0b5b55da6dcae7f3b507a6e6ec70546d5169f1215d35b6db9ef38a72694d63bacd7fac84dd27c24301b13a444acdbfec3d9ba9c53c4506
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module RBText
|
2
|
+
module Colors
|
3
|
+
def fg_color_codes
|
4
|
+
{
|
5
|
+
black: "30",
|
6
|
+
red: "31",
|
7
|
+
green: "32",
|
8
|
+
yellow: "33",
|
9
|
+
blue: "34",
|
10
|
+
magenta: "35",
|
11
|
+
cyan: "36",
|
12
|
+
light_gray: "37",
|
13
|
+
gray: "90",
|
14
|
+
light_red: "91",
|
15
|
+
light_green: "92",
|
16
|
+
light_yellow: "93",
|
17
|
+
light_blue: "94",
|
18
|
+
light_magenta: "95",
|
19
|
+
light_cyan: "96",
|
20
|
+
white: "97"
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
def bg_color_codes
|
25
|
+
bg_color_codes = {}
|
26
|
+
|
27
|
+
for c in self.fg_color_codes.keys do
|
28
|
+
bg_color_codes[c] = (self.fg_color_codes[c].to_i + 10).to_s
|
29
|
+
end
|
30
|
+
|
31
|
+
return bg_color_codes
|
32
|
+
end
|
33
|
+
|
34
|
+
def color(color, type: :fg)
|
35
|
+
if type == :fg
|
36
|
+
color_code = self.fg_color_codes[color.to_sym]
|
37
|
+
elsif type == :bg
|
38
|
+
color_code = self.bg_color_codes[color.to_sym]
|
39
|
+
end
|
40
|
+
|
41
|
+
return "\033[#{color_code}m"
|
42
|
+
end
|
43
|
+
|
44
|
+
module_function :fg_color_codes, :bg_color_codes, :color
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module RBText
|
2
|
+
module Cursor
|
3
|
+
def up(num=1)
|
4
|
+
print "\033[#{num.to_i}A"
|
5
|
+
end
|
6
|
+
|
7
|
+
def down(num=1)
|
8
|
+
print "\033[#{num.to_i}B"
|
9
|
+
end
|
10
|
+
|
11
|
+
def left(num=1)
|
12
|
+
print "\033[#{num.to_i}D"
|
13
|
+
end
|
14
|
+
|
15
|
+
def right(num=1)
|
16
|
+
print "\033[#{num.to_i}C"
|
17
|
+
end
|
18
|
+
|
19
|
+
def beginning_of_line
|
20
|
+
print "\r"
|
21
|
+
end
|
22
|
+
|
23
|
+
module_function :up, :down, :left, :right, :beginning_of_line
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module RBText
|
2
|
+
module Formatting
|
3
|
+
def reset
|
4
|
+
"\033[0m"
|
5
|
+
end
|
6
|
+
|
7
|
+
def bold
|
8
|
+
"\033[1m"
|
9
|
+
end
|
10
|
+
|
11
|
+
def faint
|
12
|
+
"\033[2m"
|
13
|
+
end
|
14
|
+
|
15
|
+
def italic
|
16
|
+
"\033[3m"
|
17
|
+
end
|
18
|
+
|
19
|
+
def underline
|
20
|
+
"\033[4m"
|
21
|
+
end
|
22
|
+
|
23
|
+
module_function :reset, :bold, :faint, :italic, :underline
|
24
|
+
end
|
25
|
+
end
|
data/lib/rbtext/ftext.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
module RBText
|
2
|
+
class Ftext
|
3
|
+
def initialize(str)
|
4
|
+
@original_text = str
|
5
|
+
@text = ""
|
6
|
+
|
7
|
+
str = str.split("_")
|
8
|
+
|
9
|
+
for x in str do
|
10
|
+
if x[0] == "." && x[x.length-1] == "." && x.split(":").length == 2
|
11
|
+
x = x.downcase.gsub(".", "").gsub("-","_")
|
12
|
+
x = x.split(":")
|
13
|
+
|
14
|
+
if x[0] == "cf" || x[0] == "c"
|
15
|
+
@text << RBText::Colors.color(x[1].to_sym)
|
16
|
+
elsif x[0] == "cb"
|
17
|
+
@text << RBText::Colors.color(x[1].to_sym, type: :bg)
|
18
|
+
elsif x[0] == "f"
|
19
|
+
if x[1] == "reset"
|
20
|
+
@text << RBText::Formatting.reset
|
21
|
+
elsif x[1] == "bold"
|
22
|
+
@text << RBText::Formatting.bold
|
23
|
+
elsif x[1] == "faint"
|
24
|
+
@text << RBText::Formatting.faint
|
25
|
+
elsif x[1] == "italic"
|
26
|
+
@text << RBText::Formatting.italic
|
27
|
+
elsif x[1] == "underline"
|
28
|
+
@text << RBText::Formatting.underline
|
29
|
+
end
|
30
|
+
end
|
31
|
+
else
|
32
|
+
@text << x
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def to_s
|
38
|
+
@text
|
39
|
+
end
|
40
|
+
|
41
|
+
def normal_text
|
42
|
+
@original_text.gsub(/\_\.([a-z]){1,2}\:([a-z\-])+\.\_/, "")
|
43
|
+
end
|
44
|
+
|
45
|
+
def original_text
|
46
|
+
@original_text
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/rbtext.rb
ADDED
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rbtext
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matthias Lee
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-03-19 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A gem for printing formatted text
|
14
|
+
email: matthias@matthiasclee.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/rbtext.rb
|
20
|
+
- lib/rbtext/colors.rb
|
21
|
+
- lib/rbtext/cursor.rb
|
22
|
+
- lib/rbtext/formatting.rb
|
23
|
+
- lib/rbtext/ftext.rb
|
24
|
+
homepage:
|
25
|
+
licenses: []
|
26
|
+
metadata: {}
|
27
|
+
post_install_message:
|
28
|
+
rdoc_options: []
|
29
|
+
require_paths:
|
30
|
+
- lib
|
31
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
requirements: []
|
42
|
+
rubygems_version: 3.1.6
|
43
|
+
signing_key:
|
44
|
+
specification_version: 4
|
45
|
+
summary: RBText
|
46
|
+
test_files: []
|