rbtext 0.1.0 → 0.2.0

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: ac75a94bd454a8663a2de94b33bbe9c10e3a5e86d269ef77d16c9fbb221c1dc5
4
- data.tar.gz: 787ef54498a6812bba42840993ce4113b7087ef356ce59dd5dd33097bb8650b3
3
+ metadata.gz: c0e5451aa3736ffcedad724b7bac7ab81d041b0fdd6689dda38fc3f700bb7429
4
+ data.tar.gz: 4795dd7dde116fa9ae34f5da44d55238ac18e829b56de491f652c55a327c5623
5
5
  SHA512:
6
- metadata.gz: 86d72ea937822a41fd2d7987c6af738ea4bfb20d271cb5a91bd632c493e136e0527e35eac6186b03096ee7db4863a071196e2fb2c342eeb23b9fb4a8117c9ea5
7
- data.tar.gz: 3b42b6eedca4db02f8ef8c6ab2498b4ab75049942c9900bb263a9acf4ff84322ee1fe7af02c2f3e129204e0ecb44840dd3066e193947f3265d45f327f50bc089
6
+ metadata.gz: 6ea9d2ea58d11bef5ce07ca67c364e22411be909b56c1637f643a77691b48e5bb5f4f0609670859e1f07f0b86bd9b4a298b7f7cd11f333e51f245f3480c2a37f
7
+ data.tar.gz: 7ea1e21507a58eeee386e0c30dd0af7c4473b0d4a45716455aa33cd8209f0a6bab0d246341ab1dcc1047e219303f57579f3f2629f2963fbd98926ef7d3aa40e8
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,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
- module_function :fg_color_codes, :bg_color_codes, :color, :num_color
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
- module_function :fg_color_codes, :bg_color_codes, :color, :num_color
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
- 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/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
- module_function :clear, :clear_line, :size, :height, :width
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
- module_function :clear, :clear_line, :size, :height, :width
38
+ @@methods.each do |method|
39
+ module_function method
40
+ end
29
41
  end
30
42
  end
data/lib/rbtext.rb CHANGED
@@ -7,7 +7,7 @@ require "io/console"
7
7
 
8
8
  module RBText
9
9
  @ver_1 = 0
10
- @ver_2 = 1
10
+ @ver_2 = 2
11
11
  @ver_3 = 0
12
12
  @ver_4 = ""
13
13
 
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.1.0
4
+ version: 0.2.0
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-23 00:00:00.000000000 Z
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