rbtext 0.2.1 → 0.3.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: d7c05f36445abd449bd35a7f0f70638c19d65ec812b8a821863dbaff69e7a116
4
- data.tar.gz: 8853c53c113ffababc63fbb4225c0a4c75f2ee1ff584072181913dca0ba367b4
3
+ metadata.gz: 5489b31d5f02438507b2bbae6be1d17e716150dda242fc6acb853a2eb3fe339b
4
+ data.tar.gz: 507406a97defe69dddd52e93a4eaf6d19af6f8b42e980c7f27b2772700f064f4
5
5
  SHA512:
6
- metadata.gz: 63b5da77e130a4dfc3fc7c8f6758ca10c31884986aab735c1d746a75b8ca0bc6849e05191d34934df0bc4c401dc855b414158a84c93371e258a2652e27ccf084
7
- data.tar.gz: 2799434338c2448084e19eda4ad4a46dc7a1933877691d2915a57d78c8b01face8bc0955e3df219024760c7017102cc731a06111d1c595a3cc6e025f55a3ee4b
6
+ metadata.gz: 147fc6619b47a74f9b67c9ef5bf94cbd90dc5de51d15ddb455eb62de6c80263b93a668400d8884dfe42cc14008ea690737d8532f780a7a6b8aaad390a5d0137d
7
+ data.tar.gz: 21d5e1b5218407351c1b773a49d5f236c0816b557407f1222a1e14682fddb6538f898351480551d5651d5c9340ffc067b10ed2669c7d77a0c821346999155444
data/bin/ftext CHANGED
@@ -1,6 +1,8 @@
1
- #!/usr/bin/ruby
1
+ #!/usr/bin/env ruby
2
2
  require_relative '../lib/rbtext.rb'
3
3
 
4
+ params = (ARGV[1..ARGV.length-1]).to_a
5
+
4
6
  if $stdin.tty? && ARGV[0]
5
7
  txt = ARGV[0].to_s
6
8
  elsif $stdin.tty?
@@ -18,13 +20,15 @@ else
18
20
  end
19
21
 
20
22
  (0..lines.length-1).each do |l|
21
- txt << "#{"_.f:reset._" if ARGV[1] != "--noreset"}_.#{args[l]}._"+lines[l]
23
+ txt << "#{"_.f:reset._" if !params.include?("--noreset")}_.#{args[l]}._"+lines[l].gsub("_", "\0004")
22
24
  end
23
25
 
24
26
  txt = txt.join
25
27
  else
26
- txt = ARGF.readlines.join
28
+ txt = ARGF.readlines.join.gsub("_", "\0004")
27
29
  end
28
30
  end
29
31
 
30
- print R::Ft.new(txt)
32
+ out = R::Ft.new(txt).to_s.gsub("\0004", "_")
33
+ print out.dump.sub("\"", "").reverse.sub("\"", "").reverse if params.include?("--dump")
34
+ print out if !params.include?("--dump")
data/lib/rbtext/colors.rb CHANGED
@@ -1,13 +1,6 @@
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
-
10
- def fg_color_codes
3
+ def self.fg_color_codes
11
4
  {
12
5
  black: "30",
13
6
  red: "31",
@@ -29,7 +22,7 @@ module RBText
29
22
  }
30
23
  end
31
24
 
32
- def bg_color_codes
25
+ def self.bg_color_codes
33
26
  bg_color_codes = {}
34
27
 
35
28
  for c in self.fg_color_codes.keys do
@@ -39,7 +32,7 @@ module RBText
39
32
  return bg_color_codes
40
33
  end
41
34
 
42
- def color(color, type: :fg, mode: :str)
35
+ def self.color(color, type: :fg, mode: :str)
43
36
  return "\033[39m\033[49m" if type == :all && color == :reset
44
37
 
45
38
  if type == :fg
@@ -54,21 +47,11 @@ module RBText
54
47
  print "\033[#{color_code}m" if mode == :set
55
48
  end
56
49
 
57
- def num_color(num, type: :fg, mode: :str)
50
+ def self.num_color(num, type: :fg, mode: :str)
58
51
  return "\033[#{type == :fg ? "38" : "48"};5;#{num}m" if mode == :str
59
52
  print "\033[#{type == :fg ? "38" : "48"};5;#{num}m" if mode == :set
60
53
  end
61
-
62
- @@methods.each do |method|
63
- module_function method
64
- end
65
- end
66
-
67
- module C
68
- include RBText::Colors
69
-
70
- @@methods.each do |method|
71
- module_function method
72
- end
73
54
  end
74
55
  end
56
+
57
+ RBText::C = RBText::Colors
data/lib/rbtext/cursor.rb CHANGED
@@ -1,32 +1,22 @@
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
-
13
- def up(num=1)
3
+ def self.up(num=1)
14
4
  print "\033[#{num.to_i}A"
15
5
  end
16
6
 
17
- def down(num=1)
7
+ def self.down(num=1)
18
8
  print "\033[#{num.to_i}B"
19
9
  end
20
10
 
21
- def left(num=1)
11
+ def self.left(num=1)
22
12
  print "\033[#{num.to_i}D"
23
13
  end
24
14
 
25
- def right(num=1)
15
+ def self.right(num=1)
26
16
  print "\033[#{num.to_i}C"
27
17
  end
28
18
 
29
- def go_to_pos(x, y=nil)
19
+ def self.go_to_pos(x, y=nil)
30
20
  if x.class == Array && !y
31
21
  y = x[1]
32
22
  x = x[0]
@@ -36,7 +26,7 @@ module RBText
36
26
  print "\033[#{y};#{x}f"
37
27
  end
38
28
 
39
- def pos
29
+ def self.pos
40
30
  res = ''
41
31
  $stdin.raw do |stdin|
42
32
  $stdout << "\e[6n"
@@ -49,19 +39,18 @@ module RBText
49
39
  return [Integer(m[:column]), Integer(m[:row])]
50
40
  end
51
41
 
52
- def beginning_of_line
42
+ def self.beginning_of_line
53
43
  print "\r"
54
44
  end
55
45
 
56
- @@methods.each do |method|
57
- module_function method
46
+ def self.show
47
+ print "\033[?25h"
58
48
  end
59
- end
60
49
 
61
- module Cr
62
- include RBText::Cursor
63
- @@methods.each do |method|
64
- module_function method
50
+ def self.hide
51
+ print "\033[?25l"
65
52
  end
66
53
  end
67
54
  end
55
+
56
+ RBText::Cr = RBText::Cursor
@@ -1,16 +1,6 @@
1
1
  module RBText
2
2
  module Formatting
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)
3
+ def self.reset(f_opt = nil, mode: :str)
14
4
  if f_opt
15
5
  r="\033[#{
16
6
  f_opt =~ /^\033\[(1|2)m$/ ? "\033[22m" : "\033[2#{f_opt.gsub(/[^0-9]/, "")}m"
@@ -22,52 +12,42 @@ module RBText
22
12
  print r if mode == :set
23
13
  end
24
14
 
25
- def bold(mode: :str)
15
+ def self.bold(mode: :str)
26
16
  r="\033[1m"
27
17
  return r if mode == :str
28
18
  print r if mode == :set
29
19
  end
30
20
 
31
- def faint(mode: :str)
21
+ def self.faint(mode: :str)
32
22
  r="\033[2m"
33
23
  return r if mode == :str
34
24
  print r if mode == :set
35
25
  end
36
26
 
37
- def italic(mode: :str)
27
+ def self.italic(mode: :str)
38
28
  r="\033[3m"
39
29
  return r if mode == :str
40
30
  print r if mode == :set
41
31
  end
42
32
 
43
- def underline(mode: :str)
33
+ def self.underline(mode: :str)
44
34
  r="\033[4m"
45
35
  return r if mode == :str
46
36
  print r if mode == :set
47
37
  end
48
38
 
49
- def blinking(mode: :str)
39
+ def self.blinking(mode: :str)
50
40
  r="\033[5m"
51
41
  return r if mode == :str
52
42
  print r if mode == :set
53
43
  end
54
44
 
55
- def strikethrough(mode: :str)
45
+ def self.strikethrough(mode: :str)
56
46
  r="\033[9m"
57
47
  return r if mode == :str
58
48
  print r if mode == :set
59
49
  end
60
-
61
- module_function
62
- @@methods.each do |method|
63
- module_function method
64
- end
65
- end
66
-
67
- module F
68
- include RBText::Formatting
69
- @@methods.each do |method|
70
- module_function method
71
- end
72
50
  end
73
51
  end
52
+
53
+ RBText::F = RBText::Formatting
data/lib/rbtext/ftext.rb CHANGED
@@ -77,6 +77,14 @@ module RBText
77
77
  def [](num)
78
78
  self.to_s[num]
79
79
  end
80
+
81
+ def *(n)
82
+ self.to_s*n
83
+ end
84
+
85
+ def include?(i)
86
+ self.to_s.include?(i)
87
+ end
80
88
  end
81
89
 
82
90
  class Ft < RBText::Ftext
data/lib/rbtext/screen.rb CHANGED
@@ -1,42 +1,29 @@
1
1
  module RBText
2
2
  module Screen
3
- @@methods = [
4
- :clear,
5
- :clear_line,
6
- :size,
7
- :height,
8
- :width
9
- ]
10
-
11
- def clear
3
+ def self.clear
12
4
  print "\033[2J"
13
5
  end
14
6
 
15
- def clear_line
7
+ def self.clear_line
16
8
  print "\033[2K"
17
9
  end
18
10
 
19
- def size
11
+ def self.size
20
12
  IO.console.winsize
21
13
  end
22
14
 
23
- def height
15
+ def self.height
24
16
  self.size[0]
25
17
  end
26
18
 
27
- def width
19
+ def self.width
28
20
  self.size[1]
29
21
  end
30
22
 
31
- @@methods.each do |method|
32
- module_function method
33
- end
34
- end
35
-
36
- module S
37
- include RBText::Screen
38
- @@methods.each do |method|
39
- module_function method
23
+ def self.bell
24
+ print "\a"
40
25
  end
41
26
  end
42
27
  end
28
+
29
+ RBText::S = RBText::Screen
@@ -0,0 +1,36 @@
1
+ require 'rbtext/colors'
2
+ require 'rbtext/formatting'
3
+
4
+ class String
5
+ def color(color, type: :fg)
6
+ RBText::Colors.color(color, type: type) + self + RBText::Colors.color(:reset, type: type)
7
+ end
8
+
9
+ def num_color(color, type: :fg)
10
+ RBText::Colors.num_color(color, type: type) + self + RBText::Colors.color(:reset, type: type)
11
+ end
12
+
13
+ def bold
14
+ RBText::Formatting.bold + self + RBText::Formatting.reset
15
+ end
16
+
17
+ def faint
18
+ RBText::Formatting.faint + self + RBText::Formatting.reset
19
+ end
20
+
21
+ def italic
22
+ RBText::Formatting.italic + self + RBText::Formatting.reset
23
+ end
24
+
25
+ def underline
26
+ RBText::Formatting.underline + self + RBText::Formatting.reset
27
+ end
28
+
29
+ def blinking
30
+ RBText::Formatting.blinking + self + RBText::Formatting.reset
31
+ end
32
+
33
+ def strikethrough
34
+ RBText::Formatting.strikethrough + self + RBText::Formatting.reset
35
+ end
36
+ end
data/lib/rbtext.rb CHANGED
@@ -7,15 +7,13 @@ require "io/console"
7
7
 
8
8
  module RBText
9
9
  @ver_1 = 0
10
- @ver_2 = 2
10
+ @ver_2 = 3
11
11
  @ver_3 = 1
12
12
  @ver_4 = ""
13
13
 
14
- def version
14
+ def self.version
15
15
  "#{@ver_1}.#{@ver_2}.#{@ver_3}#{".#{@ver_4}" if @ver_4.length > 1}"
16
16
  end
17
-
18
- module_function :version
19
17
  end
20
18
 
21
19
  module R
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbtext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.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-30 00:00:00.000000000 Z
11
+ date: 2022-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: io
14
+ name: io-console
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.0.1
19
+ version: 0.5.6
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.0.1
26
+ version: 0.5.6
27
27
  description: A gem for printing formatted text
28
28
  email: matthias@matthiasclee.com
29
29
  executables:
@@ -38,6 +38,7 @@ files:
38
38
  - lib/rbtext/formatting.rb
39
39
  - lib/rbtext/ftext.rb
40
40
  - lib/rbtext/screen.rb
41
+ - lib/rbtext/string_methods.rb
41
42
  homepage: https://github.com/Matthiasclee/RBText
42
43
  licenses:
43
44
  - AGPL-3.0