rbtext 0.0.5 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cbf603b0b26d45f84043ab323355140ffce5efc13d9696617678035bb0980b1b
4
- data.tar.gz: c7200c930672811a1db5882134bd899124a0906b350dfbcffa9d5558bedbd15a
3
+ metadata.gz: ac75a94bd454a8663a2de94b33bbe9c10e3a5e86d269ef77d16c9fbb221c1dc5
4
+ data.tar.gz: 787ef54498a6812bba42840993ce4113b7087ef356ce59dd5dd33097bb8650b3
5
5
  SHA512:
6
- metadata.gz: 340e6172cf38c0a5c01602be6a47d78798a992c4027e959ac39159408bbb604333a3e9d61b763d37f759595e696fba1253b0a4e56d98a478fa36e6b932c88e44
7
- data.tar.gz: 80ddbba3f5be56835aaf4fa71f9b3cc96745a2abe9caac32bafb4a89728c9d069ed4649a2a45103e2c2e5c3498a8c99868a1da10a93cf7c10379a530bc08090c
6
+ metadata.gz: 86d72ea937822a41fd2d7987c6af738ea4bfb20d271cb5a91bd632c493e136e0527e35eac6186b03096ee7db4863a071196e2fb2c342eeb23b9fb4a8117c9ea5
7
+ data.tar.gz: 3b42b6eedca4db02f8ef8c6ab2498b4ab75049942c9900bb263a9acf4ff84322ee1fe7af02c2f3e129204e0ecb44840dd3066e193947f3265d45f327f50bc089
data/lib/rbtext/colors.rb CHANGED
@@ -17,7 +17,8 @@ module RBText
17
17
  light_blue: "94",
18
18
  light_magenta: "95",
19
19
  light_cyan: "96",
20
- white: "97"
20
+ white: "97",
21
+ reset: "39"
21
22
  }
22
23
  end
23
24
 
@@ -32,20 +33,28 @@ module RBText
32
33
  end
33
34
 
34
35
  def color(color, type: :fg)
36
+ return "\033[39m\033[49m" if type == :all && color == :reset
37
+
35
38
  if type == :fg
36
39
  color_code = self.fg_color_codes[color.to_sym]
37
40
  elsif type == :bg
38
41
  color_code = self.bg_color_codes[color.to_sym]
42
+ else
43
+ return nil
39
44
  end
40
45
 
41
46
  return "\033[#{color_code}m"
42
47
  end
43
48
 
44
- module_function :fg_color_codes, :bg_color_codes, :color
49
+ def num_color(num, type: :fg)
50
+ return "\033[#{type == :fg ? "38" : "48"};5;#{num}m"
51
+ end
52
+
53
+ module_function :fg_color_codes, :bg_color_codes, :color, :num_color
45
54
  end
46
55
 
47
56
  module C
48
57
  include RBText::Colors
49
- module_function :fg_color_codes, :bg_color_codes, :color
58
+ module_function :fg_color_codes, :bg_color_codes, :color, :num_color
50
59
  end
51
60
  end
data/lib/rbtext/cursor.rb CHANGED
@@ -16,15 +16,20 @@ module RBText
16
16
  print "\033[#{num.to_i}C"
17
17
  end
18
18
 
19
+ def go_to_pos(x, y)
20
+ print "\033[#{y};#{x}H"
21
+ print "\033[#{y};#{x}f"
22
+ end
23
+
19
24
  def beginning_of_line
20
25
  print "\r"
21
26
  end
22
27
 
23
- module_function :up, :down, :left, :right, :beginning_of_line
28
+ module_function :up, :down, :left, :right, :beginning_of_line, :go_to_pos
24
29
  end
25
30
 
26
31
  module Cr
27
32
  include RBText::Cursor
28
- module_function :up, :down, :left, :right, :beginning_of_line
33
+ module_function :up, :down, :left, :right, :beginning_of_line, :go_to_pos
29
34
  end
30
35
  end
@@ -1,7 +1,13 @@
1
1
  module RBText
2
2
  module Formatting
3
- def reset
4
- "\033[0m"
3
+ def reset(f_opt = nil)
4
+ if f_opt
5
+ "\033[#{
6
+ f_opt =~ /^\033\[(1|2)m$/ ? "\033[22m" : "\033[2#{f_opt.gsub(/[^0-9]/, "")}m"
7
+ }"
8
+ else
9
+ "\033[0m"
10
+ end
5
11
  end
6
12
 
7
13
  def bold
@@ -20,11 +26,19 @@ module RBText
20
26
  "\033[4m"
21
27
  end
22
28
 
23
- module_function :reset, :bold, :faint, :italic, :underline
29
+ def blinking
30
+ "\033[5m"
31
+ end
32
+
33
+ def strikethrough
34
+ "\033[9m"
35
+ end
36
+
37
+ module_function :reset, :bold, :faint, :italic, :underline, :blinking, :strikethrough
24
38
  end
25
39
 
26
40
  module F
27
41
  include RBText::Formatting
28
- module_function :reset, :bold, :faint, :italic, :underline
42
+ module_function :reset, :bold, :faint, :italic, :underline, :blinking, :strikethrough
29
43
  end
30
44
  end
data/lib/rbtext/ftext.rb CHANGED
@@ -15,6 +15,10 @@ module RBText
15
15
  @text << RBText::Colors.color(x[1].to_sym)
16
16
  elsif x[0] == "cb"
17
17
  @text << RBText::Colors.color(x[1].to_sym, type: :bg)
18
+ elsif x[0] == "cfn" || x[0] == "cn"
19
+ @text << RBText::Colors.num_color(x[1])
20
+ elsif x[0] == "cbn"
21
+ @text << RBText::Colors.num_color(x[1], type: :bg)
18
22
  elsif x[0] == "f"
19
23
  if x[1] == "reset"
20
24
  @text << RBText::Formatting.reset
@@ -26,6 +30,24 @@ module RBText
26
30
  @text << RBText::Formatting.italic
27
31
  elsif x[1] == "underline"
28
32
  @text << RBText::Formatting.underline
33
+ elsif x[1] == "strikethrough"
34
+ @text << RBText::Formatting.strikethrough
35
+ elsif x[1] == "blinking"
36
+ @text << RBText::Formatting.blinking
37
+ end
38
+ elsif x[0] == "rf"
39
+ if x[1] == "bold"
40
+ @text << RBText::Formatting.reset(R::F.bold)
41
+ elsif x[1] == "faint"
42
+ @text << RBText::Formatting.reset(R::F.faint)
43
+ elsif x[1] == "italic"
44
+ @text << RBText::Formatting.reset(R::F.italic)
45
+ elsif x[1] == "underline"
46
+ @text << RBText::Formatting.reset(R::F.underline)
47
+ elsif x[1] == "strikethrough"
48
+ @text << RBText::Formatting.reset(R::F.strikethrough)
49
+ elsif x[1] == "blinking"
50
+ @text << RBText::Formatting.reset(R::F.blinking)
29
51
  end
30
52
  end
31
53
  else
@@ -47,6 +69,14 @@ module RBText
47
69
  def original_text
48
70
  @original_text
49
71
  end
72
+
73
+ def +(str)
74
+ self.to_s + str
75
+ end
76
+
77
+ def [](num)
78
+ self.to_s[num]
79
+ end
50
80
  end
51
81
 
52
82
  class Ft < RBText::Ftext
@@ -0,0 +1,30 @@
1
+ module RBText
2
+ module Screen
3
+ def clear
4
+ print "\033[2J"
5
+ end
6
+
7
+ def clear_line
8
+ print "\033[2K"
9
+ end
10
+
11
+ def size
12
+ IO.console.winsize
13
+ end
14
+
15
+ def height
16
+ self.size[0]
17
+ end
18
+
19
+ def width
20
+ self.size[1]
21
+ end
22
+
23
+ module_function :clear, :clear_line, :size, :height, :width
24
+ end
25
+
26
+ module S
27
+ include RBText::Screen
28
+ module_function :clear, :clear_line, :size, :height, :width
29
+ end
30
+ end
data/lib/rbtext.rb CHANGED
@@ -2,14 +2,17 @@ require_relative "rbtext/cursor.rb"
2
2
  require_relative "rbtext/colors.rb"
3
3
  require_relative "rbtext/formatting.rb"
4
4
  require_relative "rbtext/ftext.rb"
5
+ require_relative "rbtext/screen.rb"
6
+ require "io/console"
5
7
 
6
8
  module RBText
7
9
  @ver_1 = 0
8
- @ver_2 = 0
9
- @ver_3 = 5
10
+ @ver_2 = 1
11
+ @ver_3 = 0
12
+ @ver_4 = ""
10
13
 
11
14
  def version
12
- "#{@ver_1}.#{@ver_2}.#{@ver_3}"
15
+ "#{@ver_1}.#{@ver_2}.#{@ver_3}#{".#{@ver_4}" if @ver_4.length > 1}"
13
16
  end
14
17
 
15
18
  module_function :version
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbtext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.1.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-19 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2022-03-23 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
29
  executables: []
@@ -21,6 +35,7 @@ files:
21
35
  - lib/rbtext/cursor.rb
22
36
  - lib/rbtext/formatting.rb
23
37
  - lib/rbtext/ftext.rb
38
+ - lib/rbtext/screen.rb
24
39
  homepage: https://github.com/Matthiasclee/RBText
25
40
  licenses:
26
41
  - AGPL-3.0