pipetext 0.1.5 → 0.1.6

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: 8913bda36e869217758103b0ceb485ec76b5ebac30ae1b126bcad79ed7f4c4cc
4
- data.tar.gz: 5b1dcc7770082b825b962fa3a7b2ab46dec40105eb61604ff3a27b0987190ee9
3
+ metadata.gz: 8ca1788110ca471e3592a78b3f91285af91338551836a6b39addf9f6a4b4049c
4
+ data.tar.gz: db0162ba573ac6498c0356d0f91264998f460aa1b903a79a1d9edccdfd1ce923
5
5
  SHA512:
6
- metadata.gz: 0eff6ce751e2fc0a8043db2ce0e31071a17e6b3ccefeaca9e72decad10cada1dcd778f94c1d28d84351ee4870ada2ac46d6dbd0dd0b067b8bd967aaed8b8ff02
7
- data.tar.gz: d6f716f80d88ed75811ac841398dcb5bbfad125a61aebd13c8a07edf8c8665523157270cae8411163cdb9d91a87b3ab81d144a61bf33fbdde72258e24e04e6f7
6
+ metadata.gz: b197769b04cb90d36106524f18d7e8459ad0dd96358a6a7bbc350c3c4572fcd204ff25834f67c730b0676a4e4f3b55462a120367a9e23d5e93e93fd3a8754aba
7
+ data.tar.gz: 27a1232cfb0ad1be0d5d6b641ee633e44846200a1ba69c42f28f997c5cf6b0769923171aee4bb764f9aab6f0a58be973fcb8b3a6d403e06431d053fbcc8eef05
data/bin/pipetext CHANGED
@@ -33,6 +33,7 @@ pipetext_example = '|| pipe |||| && ampersand &&&& Toggle (&) backgrou
33
33
  |G&rbright green with red background&n |n||G&&r |xCrossed out|x ||x
34
34
  |n&nnormal color and background ||n&&n Escape sequence ||\\
35
35
 
36
+ Center text using current position and line end number ||{text to center}
36
37
  Add spaces to line end ||; Set line end ||]#
37
38
  Set current x,y cursor position ||[x,y] Terminal bell ||[bell]
38
39
  Move cursor up 1 line ||^ Hide cursor ||h
@@ -78,7 +79,7 @@ if(ARGV[0] == nil && STDIN.tty? == true)
78
79
  puts
79
80
  puts "pipetext '|-|50-'"
80
81
  puts
81
- puts "pipetext '|]50Insert spaces until end (50)|;Add After'"
82
+ puts "pipetext '|]50Insert spaces until end (50)|W|{centered}|n|;Add After'"
82
83
  puts
83
84
  puts "pipetext '|10~ &r|----|O> ALL YOUR |kBASE|n |3\\~ARE|3\\~ BELONG TO US. <|----|O&n|\\n~|n'"
84
85
  puts
@@ -25,6 +25,9 @@ module PipeText
25
25
  'num' => 0, # Number of times to repeat pattern
26
26
  'end_capture' => false, # Used to capture the end column number
27
27
  'end' => 0, # Number which current denotes the end of the column
28
+ 'position' => 0, # Number which current position in the column
29
+ 'center_capture' => false, # Used to capture text for centering
30
+ 'center' => String.new, # Text to be centered
28
31
  'emoji_capture' => false, # Used to capture emoji description or bell/move to position
29
32
  'emoji' => String.new, # Used to capture emoji description or bell/move to position
30
33
  'unicode_capture' => 0, # Used to capture Unicode using 6 character UTF-16 hex format
@@ -44,6 +47,11 @@ module PipeText
44
47
  new_text = String.new
45
48
  text.chars.each do |character|
46
49
  process_character(character, new_text, attributes)
50
+ if(new_text =~ /\n(.*)$/)
51
+ attributes['position'] = printable_length($1)
52
+ else
53
+ attributes['position'] += printable_length(new_text)
54
+ end
47
55
  end
48
56
  # Clean up in case we've captured something we didn't process yet
49
57
  if(attributes['color_capture'] > 0)
@@ -54,6 +62,8 @@ module PipeText
54
62
  emit_unicode(new_text, attributes)
55
63
  elsif(attributes['emoji_capture'] == true)
56
64
  new_text << "|[" + attributes['emoji']
65
+ elsif(attributes['center_capture'] == true)
66
+ new_text << "|{" + attributes['center']
57
67
  end
58
68
  return new_text
59
69
  end
@@ -62,13 +72,49 @@ module PipeText
62
72
  pipe(text, pipetext_init(box_mode, ampersand_mode))
63
73
  end
64
74
 
75
+ # Immediate output to screen, no string buffer
76
+ def fastpipe(text, attributes)
77
+ new_text = String.new
78
+ text.chars.each do |character|
79
+ process_character(character, new_text, attributes)
80
+ if(new_text != "")
81
+ print(new_text)
82
+ if(new_text =~ /\n(.*)$/)
83
+ attributes['position'] = printable_length($1)
84
+ else
85
+ attributes['position'] += printable_length(new_text)
86
+ end
87
+ new_text = String.new
88
+ end
89
+ end
90
+ # Clean up in case we've captured something we didn't process yet
91
+ if(attributes['color_capture'] > 0)
92
+ emit_color(new_text, attributes)
93
+ elsif(attributes['palette_capture'] > 0)
94
+ emit_palette_color(new_text, attributes)
95
+ elsif(attributes['unicode_capture'] > 0)
96
+ emit_unicode(new_text, attributes)
97
+ elsif(attributes['emoji_capture'] == true)
98
+ new_text << "|[" + attributes['emoji']
99
+ elsif(attributes['center_capture'] == true)
100
+ new_text << "|{" + attributes['center']
101
+ end
102
+ print(new_text)
103
+ end
104
+
105
+ def fastpipetext(text, box_mode=true, ampersand_mode=false)
106
+ fastpipe(text, pipetext_init(box_mode, ampersand_mode))
107
+ end
108
+
65
109
  def write(text, box_mode=true, ampersand_mode=false)
66
- puts(pipetext(text, box_mode, ampersand_mode))
110
+ fastpipetext(text, box_mode, ampersand_mode)
111
+ puts
67
112
  end
68
113
 
69
114
  # Defaults to using & for background colors
70
115
  def paint(text, box_mode=true, ampersand_mode=true)
71
- puts(pipetext(text, box_mode, ampersand_mode))
116
+ fastpipetext(text, box_mode, ampersand_mode)
117
+ puts
72
118
  end
73
119
 
74
120
  def ignored_character(character, ignored_characters)
@@ -170,6 +216,12 @@ module PipeText
170
216
  capture_color(character, new_text, attributes)
171
217
  elsif(attributes['palette_capture'] > 0 && character =~ /[0-9,A-F,a-f]/)
172
218
  capture_palette_color(character, new_text, attributes)
219
+ elsif(attributes['center_capture'] == true)
220
+ if(character == '}')
221
+ emit_center(new_text, attributes)
222
+ else
223
+ attributes['center'] << character
224
+ end
173
225
  elsif(attributes['emoji_capture'] == true)
174
226
  if(character == ']')
175
227
  if(attributes['emoji'] =~ /bell/)
@@ -254,6 +306,19 @@ module PipeText
254
306
  attributes['unicode'] = String.new
255
307
  end
256
308
 
309
+ def emit_center(new_text, attributes)
310
+ spaces = attributes['end'] - attributes['position'] - printable_length(attributes['center'])
311
+ if(spaces > 0)
312
+ spaces /= 2
313
+ spaces.times do
314
+ new_text << " "
315
+ end
316
+ end
317
+ new_text << attributes['center']
318
+ attributes['center_capture'] = false
319
+ attributes['center'] = String.new
320
+ end
321
+
257
322
  def emit_emoji(new_text, attributes)
258
323
  emoji = String.new
259
324
  match_length = 0
@@ -629,12 +694,10 @@ module PipeText
629
694
  else # We didn't find the next character
630
695
  attributes['found'] = false
631
696
  end
697
+ when '{' # center
698
+ attributes['center_capture'] = true
632
699
  when ';' # extend to end column with spaces
633
- if(new_text =~ /\n?(.*)\Z/)
634
- spaces = attributes['end'] - printable_length($1)
635
- else
636
- spaces = attributes['end']
637
- end
700
+ spaces = attributes['end'] - attributes['position']
638
701
  spaces.times do
639
702
  new_text << " "
640
703
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pipetext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Minaswan Nakamoto
@@ -31,7 +31,8 @@ description: "== Easily add colors, boxes, repetitions and emojis to your termin
31
31
  \ Italics |~\n bright red with blue background |R&b Bold |+\n
32
32
  \ green with yellow background |g&y Faint |.\n bright green
33
33
  with red background |G&r Crossed out |x\n normal color and background
34
- \ |n&n Escape Sequence |\\\n\n Add spaces to line end |;
34
+ \ |n&n Escape Sequence |\\\n\n Center text using current position and
35
+ line end number |{text to center}\n Add spaces to line end |;
35
36
  \ Set line end |]#\n Set current x,y cursor position |[x,y] Terminal
36
37
  bell |[bell]\n Move cursor up 1 line |^ Hide cursor |h\n
37
38
  \ Move cursor down 1 line |v Unhide cursor |H\n Move cursor