rbtext 0.0.7 → 0.2.1

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: 8c7aca79a52e20d6e7d51024f1029cc8ed92a2e870f796026463005acfa28d37
4
- data.tar.gz: 8ed901117befbb3899c7a5f1ef9b64c03bec6e0cbe43da498295b6e7e3e4576e
3
+ metadata.gz: d7c05f36445abd449bd35a7f0f70638c19d65ec812b8a821863dbaff69e7a116
4
+ data.tar.gz: 8853c53c113ffababc63fbb4225c0a4c75f2ee1ff584072181913dca0ba367b4
5
5
  SHA512:
6
- metadata.gz: 3de37ec9edf252ac34d556b57a52dd5a83fdf8ab43c6099369fc73d30fb43cae5a95084eda353e8789e87064689e204b7dcc9eaed9214744851ffbcf1a988b75
7
- data.tar.gz: 9255ebee6de279081a194c964096c6c5eaf1e35c3101d1304a2e2cefc0cf5ab4763c87feb8c0385f95703ee916598c4efa6dfb03f750906fc381e37ebbfe0960
6
+ metadata.gz: 63b5da77e130a4dfc3fc7c8f6758ca10c31884986aab735c1d746a75b8ca0bc6849e05191d34934df0bc4c401dc855b414158a84c93371e258a2652e27ccf084
7
+ data.tar.gz: 2799434338c2448084e19eda4ad4a46dc7a1933877691d2915a57d78c8b01face8bc0955e3df219024760c7017102cc731a06111d1c595a3cc6e025f55a3ee4b
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]
22
+ end
23
+
24
+ txt = txt.join
25
+ else
26
+ txt = ARGF.readlines.join
27
+ end
28
+ end
29
+
30
+ print R::Ft.new(txt)
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,25 +39,36 @@ 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)
43
+ return "\033[39m\033[49m" if type == :all && color == :reset
44
+
36
45
  if type == :fg
37
46
  color_code = self.fg_color_codes[color.to_sym]
38
47
  elsif type == :bg
39
48
  color_code = self.bg_color_codes[color.to_sym]
49
+ else
50
+ return nil
40
51
  end
41
52
 
42
- return "\033[#{color_code}m"
53
+ return "\033[#{color_code}m" if mode == :str
54
+ print "\033[#{color_code}m" if mode == :set
43
55
  end
44
56
 
45
- def num_color(num, type: :fg)
46
- 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
47
60
  end
48
61
 
49
- module_function :fg_color_codes, :bg_color_codes, :color, :num_color
62
+ @@methods.each do |method|
63
+ module_function method
64
+ end
50
65
  end
51
66
 
52
67
  module C
53
68
  include RBText::Colors
54
- module_function :fg_color_codes, :bg_color_codes, :color, :num_color
69
+
70
+ @@methods.each do |method|
71
+ module_function method
72
+ end
55
73
  end
56
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
- module_function :up, :down, :left, :right, :beginning_of_line, :go_to_pos
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
- module_function :up, :down, :left, :right, :beginning_of_line, :go_to_pos
63
+ @@methods.each do |method|
64
+ module_function method
65
+ end
34
66
  end
35
67
  end
@@ -1,44 +1,73 @@
1
1
  module RBText
2
2
  module Formatting
3
- def reset(f_opt = nil)
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
- module_function :reset, :bold, :faint, :italic, :underline, :blinking, :strikethrough
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
- module_function :reset, :bold, :faint, :italic, :underline, :blinking, :strikethrough
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
@@ -69,6 +69,14 @@ module RBText
69
69
  def original_text
70
70
  @original_text
71
71
  end
72
+
73
+ def +(str)
74
+ self.to_s + str
75
+ end
76
+
77
+ def [](num)
78
+ self.to_s[num]
79
+ end
72
80
  end
73
81
 
74
82
  class Ft < RBText::Ftext
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
@@ -8,11 +16,27 @@ module RBText
8
16
  print "\033[2K"
9
17
  end
10
18
 
11
- module_function :clear, :clear_line
19
+ def size
20
+ IO.console.winsize
21
+ end
22
+
23
+ def height
24
+ self.size[0]
25
+ end
26
+
27
+ def width
28
+ self.size[1]
29
+ end
30
+
31
+ @@methods.each do |method|
32
+ module_function method
33
+ end
12
34
  end
13
35
 
14
36
  module S
15
37
  include RBText::Screen
16
- module_function :clear, :clear_line
38
+ @@methods.each do |method|
39
+ module_function method
40
+ end
17
41
  end
18
42
  end
data/lib/rbtext.rb CHANGED
@@ -3,11 +3,12 @@ require_relative "rbtext/colors.rb"
3
3
  require_relative "rbtext/formatting.rb"
4
4
  require_relative "rbtext/ftext.rb"
5
5
  require_relative "rbtext/screen.rb"
6
+ require "io/console"
6
7
 
7
8
  module RBText
8
9
  @ver_1 = 0
9
- @ver_2 = 0
10
- @ver_3 = 7
10
+ @ver_2 = 2
11
+ @ver_3 = 1
11
12
  @ver_4 = ""
12
13
 
13
14
  def version
metadata CHANGED
@@ -1,21 +1,37 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbtext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.2.1
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-20 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2022-03-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: io
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.0.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.0.1
13
27
  description: A gem for printing formatted text
14
28
  email: matthias@matthiasclee.com
15
- executables: []
29
+ executables:
30
+ - ftext
16
31
  extensions: []
17
32
  extra_rdoc_files: []
18
33
  files:
34
+ - bin/ftext
19
35
  - lib/rbtext.rb
20
36
  - lib/rbtext/colors.rb
21
37
  - lib/rbtext/cursor.rb