rbtext 0.1.0 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/ftext +30 -0
- data/lib/rbtext/colors.rb +20 -6
- data/lib/rbtext/cursor.rb +35 -3
- data/lib/rbtext/formatting.rb +46 -17
- data/lib/rbtext/ftext.rb +1 -1
- data/lib/rbtext/screen.rb +14 -2
- data/lib/rbtext.rb +2 -2
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 66d505848f874fa734dc012e8715d1ce3e0ec7f044676f129e416a4a2fef595a
|
4
|
+
data.tar.gz: e253f36f8229fe50764c82454b3ef049094d8a1b0623cf73d4d7364d37cf7551
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f06db194fadc7aa7e7958d7d31d1c41d13e04073406480526c26668e076618e1da8b70a30fbd814827ea66aaed66ad2cabad8e61ae9047844f1920f8ef0ad37d
|
7
|
+
data.tar.gz: 6c89641d22ce70ac9e8f83b6d2d0a64b2d77b43f2f7925f65908a4256e32bdfd17f5a4a2bd9d1100e245d2d147315a83b1d3892e0395cf80033682a47a417f19
|
data/bin/ftext
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
require_relative '../lib/rbtext.rb'
|
3
|
+
|
4
|
+
if $stdin.tty? && ARGV[0]
|
5
|
+
txt = ARGV[0].to_s
|
6
|
+
elsif $stdin.tty?
|
7
|
+
return
|
8
|
+
else
|
9
|
+
if ARGV[0]
|
10
|
+
txt = []
|
11
|
+
|
12
|
+
args = ARGV[0].split(',')
|
13
|
+
lines = STDIN.each_line.to_a
|
14
|
+
|
15
|
+
if args.length < lines.length
|
16
|
+
x = lines.length/args.length
|
17
|
+
args = args * (x+1)
|
18
|
+
end
|
19
|
+
|
20
|
+
(0..lines.length-1).each do |l|
|
21
|
+
txt << "#{"_.f:reset._" if ARGV[1] != "--noreset"}_.#{args[l]}._"+lines[l].gsub("_", "\0004")
|
22
|
+
end
|
23
|
+
|
24
|
+
txt = txt.join
|
25
|
+
else
|
26
|
+
txt = ARGF.readlines.join.gsub("_", "\0004")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
print R::Ft.new(txt).to_s.gsub("\0004", "_")
|
data/lib/rbtext/colors.rb
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
module RBText
|
2
2
|
module Colors
|
3
|
+
@@methods = [
|
4
|
+
:fg_color_codes,
|
5
|
+
:bg_color_codes,
|
6
|
+
:color,
|
7
|
+
:num_color
|
8
|
+
]
|
9
|
+
|
3
10
|
def fg_color_codes
|
4
11
|
{
|
5
12
|
black: "30",
|
@@ -32,7 +39,7 @@ module RBText
|
|
32
39
|
return bg_color_codes
|
33
40
|
end
|
34
41
|
|
35
|
-
def color(color, type: :fg)
|
42
|
+
def color(color, type: :fg, mode: :str)
|
36
43
|
return "\033[39m\033[49m" if type == :all && color == :reset
|
37
44
|
|
38
45
|
if type == :fg
|
@@ -43,18 +50,25 @@ module RBText
|
|
43
50
|
return nil
|
44
51
|
end
|
45
52
|
|
46
|
-
return "\033[#{color_code}m"
|
53
|
+
return "\033[#{color_code}m" if mode == :str
|
54
|
+
print "\033[#{color_code}m" if mode == :set
|
47
55
|
end
|
48
56
|
|
49
|
-
def num_color(num, type: :fg)
|
50
|
-
return "\033[#{type == :fg ? "38" : "48"};5;#{num}m"
|
57
|
+
def num_color(num, type: :fg, mode: :str)
|
58
|
+
return "\033[#{type == :fg ? "38" : "48"};5;#{num}m" if mode == :str
|
59
|
+
print "\033[#{type == :fg ? "38" : "48"};5;#{num}m" if mode == :set
|
51
60
|
end
|
52
61
|
|
53
|
-
|
62
|
+
@@methods.each do |method|
|
63
|
+
module_function method
|
64
|
+
end
|
54
65
|
end
|
55
66
|
|
56
67
|
module C
|
57
68
|
include RBText::Colors
|
58
|
-
|
69
|
+
|
70
|
+
@@methods.each do |method|
|
71
|
+
module_function method
|
72
|
+
end
|
59
73
|
end
|
60
74
|
end
|
data/lib/rbtext/cursor.rb
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
module RBText
|
2
2
|
module Cursor
|
3
|
+
@@methods = [
|
4
|
+
:up,
|
5
|
+
:down,
|
6
|
+
:left,
|
7
|
+
:right,
|
8
|
+
:beginning_of_line,
|
9
|
+
:go_to_pos,
|
10
|
+
:pos
|
11
|
+
]
|
12
|
+
|
3
13
|
def up(num=1)
|
4
14
|
print "\033[#{num.to_i}A"
|
5
15
|
end
|
@@ -16,20 +26,42 @@ module RBText
|
|
16
26
|
print "\033[#{num.to_i}C"
|
17
27
|
end
|
18
28
|
|
19
|
-
def go_to_pos(x, y)
|
29
|
+
def go_to_pos(x, y=nil)
|
30
|
+
if x.class == Array && !y
|
31
|
+
y = x[1]
|
32
|
+
x = x[0]
|
33
|
+
end
|
34
|
+
|
20
35
|
print "\033[#{y};#{x}H"
|
21
36
|
print "\033[#{y};#{x}f"
|
22
37
|
end
|
23
38
|
|
39
|
+
def pos
|
40
|
+
res = ''
|
41
|
+
$stdin.raw do |stdin|
|
42
|
+
$stdout << "\e[6n"
|
43
|
+
$stdout.flush
|
44
|
+
while (c = stdin.getc) != 'R'
|
45
|
+
res << c if c
|
46
|
+
end
|
47
|
+
end
|
48
|
+
m = res.match /(?<row>\d+);(?<column>\d+)/
|
49
|
+
return [Integer(m[:column]), Integer(m[:row])]
|
50
|
+
end
|
51
|
+
|
24
52
|
def beginning_of_line
|
25
53
|
print "\r"
|
26
54
|
end
|
27
55
|
|
28
|
-
|
56
|
+
@@methods.each do |method|
|
57
|
+
module_function method
|
58
|
+
end
|
29
59
|
end
|
30
60
|
|
31
61
|
module Cr
|
32
62
|
include RBText::Cursor
|
33
|
-
|
63
|
+
@@methods.each do |method|
|
64
|
+
module_function method
|
65
|
+
end
|
34
66
|
end
|
35
67
|
end
|
data/lib/rbtext/formatting.rb
CHANGED
@@ -1,44 +1,73 @@
|
|
1
1
|
module RBText
|
2
2
|
module Formatting
|
3
|
-
|
3
|
+
@@methods = [
|
4
|
+
:reset,
|
5
|
+
:bold,
|
6
|
+
:faint,
|
7
|
+
:italic,
|
8
|
+
:underline,
|
9
|
+
:blinking,
|
10
|
+
:strikethrough
|
11
|
+
]
|
12
|
+
|
13
|
+
def reset(f_opt = nil, mode: :str)
|
4
14
|
if f_opt
|
5
|
-
"\033[#{
|
15
|
+
r="\033[#{
|
6
16
|
f_opt =~ /^\033\[(1|2)m$/ ? "\033[22m" : "\033[2#{f_opt.gsub(/[^0-9]/, "")}m"
|
7
17
|
}"
|
8
18
|
else
|
9
|
-
"\033[0m"
|
19
|
+
r="\033[0m"
|
10
20
|
end
|
21
|
+
return r if mode == :str
|
22
|
+
print r if mode == :set
|
11
23
|
end
|
12
24
|
|
13
|
-
def bold
|
14
|
-
"\033[1m"
|
25
|
+
def bold(mode: :str)
|
26
|
+
r="\033[1m"
|
27
|
+
return r if mode == :str
|
28
|
+
print r if mode == :set
|
15
29
|
end
|
16
30
|
|
17
|
-
def faint
|
18
|
-
"\033[2m"
|
31
|
+
def faint(mode: :str)
|
32
|
+
r="\033[2m"
|
33
|
+
return r if mode == :str
|
34
|
+
print r if mode == :set
|
19
35
|
end
|
20
36
|
|
21
|
-
def italic
|
22
|
-
"\033[3m"
|
37
|
+
def italic(mode: :str)
|
38
|
+
r="\033[3m"
|
39
|
+
return r if mode == :str
|
40
|
+
print r if mode == :set
|
23
41
|
end
|
24
42
|
|
25
|
-
def underline
|
26
|
-
"\033[4m"
|
43
|
+
def underline(mode: :str)
|
44
|
+
r="\033[4m"
|
45
|
+
return r if mode == :str
|
46
|
+
print r if mode == :set
|
27
47
|
end
|
28
48
|
|
29
|
-
def blinking
|
30
|
-
"\033[5m"
|
49
|
+
def blinking(mode: :str)
|
50
|
+
r="\033[5m"
|
51
|
+
return r if mode == :str
|
52
|
+
print r if mode == :set
|
31
53
|
end
|
32
54
|
|
33
|
-
def strikethrough
|
34
|
-
"\033[9m"
|
55
|
+
def strikethrough(mode: :str)
|
56
|
+
r="\033[9m"
|
57
|
+
return r if mode == :str
|
58
|
+
print r if mode == :set
|
35
59
|
end
|
36
60
|
|
37
|
-
|
61
|
+
module_function
|
62
|
+
@@methods.each do |method|
|
63
|
+
module_function method
|
64
|
+
end
|
38
65
|
end
|
39
66
|
|
40
67
|
module F
|
41
68
|
include RBText::Formatting
|
42
|
-
|
69
|
+
@@methods.each do |method|
|
70
|
+
module_function method
|
71
|
+
end
|
43
72
|
end
|
44
73
|
end
|
data/lib/rbtext/ftext.rb
CHANGED
@@ -4,7 +4,7 @@ module RBText
|
|
4
4
|
@original_text = str
|
5
5
|
@text = ""
|
6
6
|
|
7
|
-
str = str.split("_")
|
7
|
+
str = str.gsub("_.", "\0001").gsub("._", "\0002").gsub("_", "\0000").gsub("\0001", "_.").gsub("\0002", "._").split("_").map{|x|x.gsub("\0000", "_")}
|
8
8
|
|
9
9
|
for x in str do
|
10
10
|
if x[0] == "." && x[x.length-1] == "." && x.split(":").length == 2
|
data/lib/rbtext/screen.rb
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
module RBText
|
2
2
|
module Screen
|
3
|
+
@@methods = [
|
4
|
+
:clear,
|
5
|
+
:clear_line,
|
6
|
+
:size,
|
7
|
+
:height,
|
8
|
+
:width
|
9
|
+
]
|
10
|
+
|
3
11
|
def clear
|
4
12
|
print "\033[2J"
|
5
13
|
end
|
@@ -20,11 +28,15 @@ module RBText
|
|
20
28
|
self.size[1]
|
21
29
|
end
|
22
30
|
|
23
|
-
|
31
|
+
@@methods.each do |method|
|
32
|
+
module_function method
|
33
|
+
end
|
24
34
|
end
|
25
35
|
|
26
36
|
module S
|
27
37
|
include RBText::Screen
|
28
|
-
|
38
|
+
@@methods.each do |method|
|
39
|
+
module_function method
|
40
|
+
end
|
29
41
|
end
|
30
42
|
end
|
data/lib/rbtext.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rbtext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthias Lee
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-03-
|
11
|
+
date: 2022-03-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: io
|
@@ -26,10 +26,12 @@ dependencies:
|
|
26
26
|
version: 0.0.1
|
27
27
|
description: A gem for printing formatted text
|
28
28
|
email: matthias@matthiasclee.com
|
29
|
-
executables:
|
29
|
+
executables:
|
30
|
+
- ftext
|
30
31
|
extensions: []
|
31
32
|
extra_rdoc_files: []
|
32
33
|
files:
|
34
|
+
- bin/ftext
|
33
35
|
- lib/rbtext.rb
|
34
36
|
- lib/rbtext/colors.rb
|
35
37
|
- lib/rbtext/cursor.rb
|