pipetext 0.2.2 → 0.2.4

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: c79619e754a795072b47b34cf152a56f01308c347e8b7ceb9a74d2fac3a9d407
4
- data.tar.gz: 27f7cd8b4cad98f95bd888c56b1bf9793c5c083276f947be6f69c37619e2fcfa
3
+ metadata.gz: 59d39270d503c77ab782442902e45e8a7b9390801e19aa639510c450c60eee1f
4
+ data.tar.gz: af2c501cff8611be392dddce15232149a5063de5724ab0f05e36b45219490a93
5
5
  SHA512:
6
- metadata.gz: cd2794bef8842d24f2a9d558adc654fd2b66de4fd242d7edcebb6731441ebdccfac57d1187d61f56b93b47b4f490a6777cea0ee8c1de7405e3373f254bc4faee
7
- data.tar.gz: 96eb07179f6936b55f480f3860e11e4a190457b7159835666f14d2bdc53f24d65c4de393fa82c9242959281b1a3429bb30e02981b0a58ded387bff5a6815d103
6
+ metadata.gz: eb9731040f1749bd24c3f7b2c7073700e59bff29c4cb39431c917e1ce436cebca25cf09aa2815d10fc8c6610698e33ca2571939bcdb479b45fc68fc25315641d
7
+ data.tar.gz: 9bf71d085a9d59b059841d967907386ce6da673417f23a531b4adee57e2f858b1caaea914cfb0ec3f91a53a387ee62ea1c1112268dc4745b0a198e5c3788e0f0
data/bin/pipetext CHANGED
@@ -23,7 +23,7 @@ pipetext_example = '|| pipe |||| && ampersand &&&& Toggle (&) backgrou
23
23
  |yyellow |n||y |Ybright yellow |n||Y &yyellow background&n &&y
24
24
  |mmagenta |n||m |Mbright magenta |n||M &mmagenta background&n &&m
25
25
  |#FFFFFF&#555555Hex RGB color codes:|n&n Foreground ||#RRGGBB Background &&#RRGGBB
26
- |p33&pF8Palette colors (256) using Hex:|n&n ||p33&&pF8 Clear screen ||!
26
+ |pC1&pF8Palette colors (256) |Rusing Hex|pC1:|n&n ||pC1&&pF8 Clear screen ||!
27
27
  |K&wblack with white background&n |n||K&&w |@Blink|@ing ||@
28
28
  |w&mwhite with magenta background&n |n||w&&m |w&mi|invert&n|i ||i
29
29
  |s&gsmoke with green background&n |n||s&&g |_Underline|_d ||_
@@ -45,6 +45,8 @@ Add to variable ||(variable name+=data) Subtract from variable ||(variab
45
45
  Multiple variable ||(variable name*=data) Divide variable ||(variable name/=data)
46
46
  Copy variable to current number ||(#variable name)
47
47
 
48
+ ||$ toggles \[ and \] around empty sequences automatically for bash command prompts
49
+
48
50
  Emojis: https://unicode.org/emoji/charts/full-emoji-list.html
49
51
  ||[Abbreviated CLDR Short Name] |[smiling face with heart-eyes] ||[smiling face with heart-eyes] or
50
52
  |[gear] ||[gear] |[zzz] ||[zzz] |[man] ||[man] |[sm f w he e] ||[sm f w he e]
@@ -87,6 +89,9 @@ if(ARGV[0] == nil && STDIN.tty? == true)
87
89
  puts "pipetext '|(test=15)Print 10 stars: |(#test-=5)* and 20 hashes: |(#test+=5)#'"
88
90
  puts "pipetext '|10~ &r|----|O> ALL YOUR |kBASE|n |3\\~ARE|3\\~ BELONG TO US. <|----|O&n|\\n~|n'"
89
91
  puts
92
+ puts "Set your bash prompt:"
93
+ puts "PS1=$(pipetext '|g\\u|n@|g\\h|n:|g\\w|n$ ')"
94
+ puts
90
95
  pipe.paint("version |c#{PipeText::VERSION}|n\n")
91
96
  else
92
97
  if(STDIN.tty? == false)
@@ -42,7 +42,8 @@ module PipeText
42
42
  'g' => String.new,
43
43
  'b' => String.new,
44
44
  'fg' => String.new, # Needed to restore after background change
45
- 'bg' => String.new # Needed to restore after foreground change
45
+ 'bg' => String.new, # Needed to restore after foreground change
46
+ 'shell_prompt' => false # Used to add \[ and \] around non-printables for prompts
46
47
  }
47
48
  attributes['variables']['height'] = `tput lines`.chomp
48
49
  attributes['variables']['width'] = `tput cols`.chomp
@@ -53,7 +54,7 @@ module PipeText
53
54
  new_text = String.new
54
55
  text.chars.each do |character|
55
56
  process_character(character, new_text, attributes)
56
- if(new_text =~ /\n(.*)$/)
57
+ if(new_text =~ /.*\n(.*)$/m)
57
58
  attributes['position'] = printable_length($1)
58
59
  else
59
60
  attributes['position'] += printable_length(new_text)
@@ -165,7 +166,7 @@ module PipeText
165
166
  return count + offset
166
167
  end
167
168
 
168
- # This is not entirely accurate because of emojis
169
+ # This is not entirely accurate because of emojis, which we assume are 2 characters
169
170
  def printable_length(string)
170
171
  length = 0
171
172
  escape = false
@@ -175,6 +176,8 @@ module PipeText
175
176
  elsif(character.ord >= 32)
176
177
  if(escape == true && character.ord == 109)
177
178
  escape = false
179
+ elsif(character.ord > 9600) # ~ Emoji / Unicode - double wide characters start
180
+ length += 2
178
181
  elsif(escape == false)
179
182
  length += 1
180
183
  end
@@ -250,7 +253,11 @@ module PipeText
250
253
  attributes['emoji'] = String.new
251
254
  attributes['emoji_capture'] = false
252
255
  elsif(attributes['emoji'] =~ /^([0-9]*)[,;]([0-9]*)$/)
253
- new_text << "\e[#{$1};#{$2}H"
256
+ if(attributes['shell_prompt'] == true)
257
+ new_text << "\\[\e[#{$1};#{$2}H\\]"
258
+ else
259
+ new_text << "\e[#{$1};#{$2}H"
260
+ end
254
261
  attributes['emoji'] = String.new
255
262
  attributes['emoji_capture'] = false
256
263
  elsif(attributes['emoji'] =~ /^([0-9]*)s$/i) # Sleep in seconds
@@ -309,10 +316,18 @@ module PipeText
309
316
  g = attributes['g'].to_i(16).to_s
310
317
  b = attributes['b'].to_i(16).to_s
311
318
  if(attributes['ampersand'] == true) # Background Color
312
- new_text << "\e[48;2;#{r};#{g};#{b}m"
319
+ if(attributes['shell_prompt'] == true)
320
+ new_text << "\\[\e[48;2;#{r};#{g};#{b}m\\]"
321
+ else
322
+ new_text << "\e[48;2;#{r};#{g};#{b}m"
323
+ end
313
324
  attributes['ampersand'] = false
314
325
  else # Foreground Color
315
- new_text << "\e[38;2;#{r};#{g};#{b}m"
326
+ if(attributes['shell_prompt'] == true)
327
+ new_text << "\\[\e[38;2;#{r};#{g};#{b}m\\]"
328
+ else
329
+ new_text << "\e[38;2;#{r};#{g};#{b}m"
330
+ end
316
331
  end
317
332
  attributes['color_capture'] = 0
318
333
  attributes['r'] = String.new
@@ -323,10 +338,18 @@ module PipeText
323
338
  def emit_palette_color(new_text, attributes)
324
339
  p = attributes['p'].to_i(16).to_s
325
340
  if(attributes['ampersand'] == true) # Background Color
326
- new_text << "\e[48;5;#{p}m"
341
+ if(attributes['shell_prompt'] == true)
342
+ new_text << "\\[\e[48;5;#{p}m\\]"
343
+ else
344
+ new_text << "\e[48;5;#{p}m"
345
+ end
327
346
  attributes['ampersand'] = false
328
347
  else # Foreground Color
329
- new_text << "\e[38;5;#{p}m"
348
+ if(attributes['shell_prompt'] == true)
349
+ new_text << "\\[\e[38;5;#{p}m\\]"
350
+ else
351
+ new_text << "\e[38;5;#{p}m"
352
+ end
330
353
  end
331
354
  attributes['palette_capture'] = 0
332
355
  attributes['p'] = String.new
@@ -571,6 +594,9 @@ module PipeText
571
594
  end
572
595
 
573
596
  def update_attributes(new_text, attributes)
597
+ if(attributes['shell_prompt'] == true)
598
+ new_text << "\\["
599
+ end
574
600
  if(attributes['bold'] == true)
575
601
  new_text << "\e[1m"
576
602
  end
@@ -592,6 +618,9 @@ module PipeText
592
618
  if(attributes['crossed_out'] == true)
593
619
  new_text << "\e[9m"
594
620
  end
621
+ if(attributes['shell_prompt'] == true)
622
+ new_text << "\\]"
623
+ end
595
624
  end
596
625
 
597
626
  def process_piped_character(character, new_text, attributes)
@@ -606,8 +635,15 @@ module PipeText
606
635
  end
607
636
  attributes['pipe'] = false
608
637
  when '!' # |! - Clear screen
609
- new_text << "\e[H\e[J"
638
+ if(attributes['shell_prompt'] == true)
639
+ new_text << "\\[\e[H\e[J\\]"
640
+ else
641
+ new_text << "\e[H\e[J"
642
+ end
610
643
  when '+' # |+ - Bold
644
+ if(attributes['shell_prompt'] == true)
645
+ new_text << "\\["
646
+ end
611
647
  if(attributes['bold'] == false)
612
648
  new_text << "\e[1m"
613
649
  attributes['bold'] = true
@@ -615,7 +651,13 @@ module PipeText
615
651
  new_text << "\e[22m"
616
652
  attributes['bold'] = false
617
653
  end
654
+ if(attributes['shell_prompt'] == true)
655
+ new_text << "\\]"
656
+ end
618
657
  when '.' # |. - Faint / Dim
658
+ if(attributes['shell_prompt'] == true)
659
+ new_text << "\\["
660
+ end
619
661
  if(attributes['faint'] == false)
620
662
  new_text << "\e[2m"
621
663
  attributes['faint'] = true
@@ -623,7 +665,13 @@ module PipeText
623
665
  new_text << "\e[22m"
624
666
  attributes['faint'] = false
625
667
  end
668
+ if(attributes['shell_prompt'] == true)
669
+ new_text << "\\]"
670
+ end
626
671
  when '~' # |~ - Italic
672
+ if(attributes['shell_prompt'] == true)
673
+ new_text << "\\["
674
+ end
627
675
  if(attributes['italic'] == false)
628
676
  new_text << "\e[3m"
629
677
  attributes['italic'] = true
@@ -631,7 +679,13 @@ module PipeText
631
679
  new_text << "\e[23m"
632
680
  attributes['italic'] = false
633
681
  end
682
+ if(attributes['shell_prompt'] == true)
683
+ new_text << "\\]"
684
+ end
634
685
  when '_' # |_ - Underline
686
+ if(attributes['shell_prompt'] == true)
687
+ new_text << "\\["
688
+ end
635
689
  if(attributes['underline'] == false)
636
690
  new_text << "\e[4m"
637
691
  attributes['underline'] = true
@@ -639,7 +693,13 @@ module PipeText
639
693
  new_text << "\e[24m"
640
694
  attributes['underline'] = false
641
695
  end
696
+ if(attributes['shell_prompt'] == true)
697
+ new_text << "\\]"
698
+ end
642
699
  when '@' # |@ - Blink
700
+ if(attributes['shell_prompt'] == true)
701
+ new_text << "\\["
702
+ end
643
703
  if(attributes['blink'] == false)
644
704
  new_text << "\e[5m"
645
705
  attributes['blink'] = true
@@ -647,6 +707,9 @@ module PipeText
647
707
  new_text << "\e[25m"
648
708
  attributes['blink'] = false
649
709
  end
710
+ if(attributes['shell_prompt'] == true)
711
+ new_text << "\\]"
712
+ end
650
713
  when '^' # |^ - Move up 1 line
651
714
  new_text << "\e[A"
652
715
  when 'v', 'V' # |v - Move down 1 line
@@ -656,10 +719,21 @@ module PipeText
656
719
  when '<' # |< - Move back 1 character
657
720
  new_text << "\e[D"
658
721
  when 'h' # |h - Hide cursor
659
- new_text << "\e[?25l"
722
+ if(attributes['shell_prompt'] == true)
723
+ new_text << "\\[\e[?25l\\]"
724
+ else
725
+ new_text << "\e[?25l"
726
+ end
660
727
  when 'H' # |H - Unhide cursor
661
- new_text << "\e[?25h"
728
+ if(attributes['shell_prompt'] == true)
729
+ new_text << "\\[\e[?25h\\]"
730
+ else
731
+ new_text << "\e[?25h"
732
+ end
662
733
  when 'i', 'I' # |i - Inverse
734
+ if(attributes['shell_prompt'] == true)
735
+ new_text << "\\["
736
+ end
663
737
  if(attributes['inverse'] == false)
664
738
  new_text << "\e[7m"
665
739
  attributes['inverse'] = true
@@ -667,7 +741,13 @@ module PipeText
667
741
  new_text << "\e[27m"
668
742
  attributes['inverse'] = false
669
743
  end
744
+ if(attributes['shell_prompt'] == true)
745
+ new_text << "\\]"
746
+ end
670
747
  when 'x', 'X' # |x - Crossed Out
748
+ if(attributes['shell_prompt'] == true)
749
+ new_text << "\\["
750
+ end
671
751
  if(attributes['crossed_out'] == false)
672
752
  new_text << "\e[9m"
673
753
  attributes['crossed_out'] = true
@@ -675,6 +755,9 @@ module PipeText
675
755
  new_text << "\e[29m"
676
756
  attributes['crossed_out'] = false
677
757
  end
758
+ if(attributes['shell_prompt'] == true)
759
+ new_text << "\\]"
760
+ end
678
761
  when '#' # |#RRGGBB
679
762
  attributes['color_capture'] = 1
680
763
  when 'P', 'p' # |P or |p - 2 character hex format color (256 colors)
@@ -683,108 +766,176 @@ module PipeText
683
766
  attributes['unicode_capture'] = 1
684
767
  when 'K', 'k' # |K or |k - Foreground text black
685
768
  attributes['fg'] = "\e[30m"
686
- new_text << "\e[0;30m"
769
+ if(attributes['shell_prompt'] == true)
770
+ new_text << "\\[\e[0;30m\\]"
771
+ else
772
+ new_text << "\e[0;30m"
773
+ end
687
774
  attributes['bold'] = false
688
775
  update_attributes(new_text, attributes)
689
776
  new_text << attributes['bg'] == "\e[0m" ? "" : attributes['bg']
690
777
  when 'S', 's' # |S or |s - Foreground text smoke
691
778
  attributes['fg'] = "\e[1;30m"
692
- new_text << "\e[1;30m"
779
+ if(attributes['shell_prompt'] == true)
780
+ new_text << "\\[\e[1;30m\\]"
781
+ else
782
+ new_text << "\e[1;30m"
783
+ end
693
784
  attributes['bold'] = false
694
785
  update_attributes(new_text, attributes)
695
786
  attributes['bold'] = true
696
787
  new_text << attributes['bg'] == "\e[0m" ? "" : attributes['bg']
697
788
  when 'r' # |r - Foreground text red
698
789
  attributes['fg'] = "\e[31m"
699
- new_text << "\e[0;31m"
790
+ if(attributes['shell_prompt'] == true)
791
+ new_text << "\\[\e[0;31m\\]"
792
+ else
793
+ new_text << "\e[0;31m"
794
+ end
700
795
  attributes['bold'] = false
701
796
  update_attributes(new_text, attributes)
702
797
  new_text << attributes['bg'] == "\e[0m" ? "" : attributes['bg']
703
798
  when 'R' # |R - Foreground text bright red
704
799
  attributes['fg'] = "\e[1;31m"
705
- new_text << "\e[1;31m"
800
+ if(attributes['shell_prompt'] == true)
801
+ new_text << "\\[\e[1;31m\\]"
802
+ else
803
+ new_text << "\e[1;31m"
804
+ end
706
805
  attributes['bold'] = false
707
806
  update_attributes(new_text, attributes)
708
807
  attributes['bold'] = true
709
808
  new_text << attributes['bg'] == "\e[0m" ? "" : attributes['bg']
710
809
  when 'g' # |g - Foreground text green
711
810
  attributes['fg'] = "\e[32m"
712
- new_text << "\e[0;32m"
811
+ if(attributes['shell_prompt'] == true)
812
+ new_text << "\\[\e[0;32m\\]"
813
+ else
814
+ new_text << "\e[0;32m"
815
+ end
713
816
  attributes['bold'] = false
714
817
  update_attributes(new_text, attributes)
715
818
  new_text << attributes['bg'] == "\e[0m" ? "" : attributes['bg']
716
819
  when 'G' # |G - Foreground text bright green
717
820
  attributes['fg'] = "\e[1;32m"
718
- new_text << "\e[1;32m"
821
+ if(attributes['shell_prompt'] == true)
822
+ new_text << "\\[\e[1;32m\\]"
823
+ else
824
+ new_text << "\e[1;32m"
825
+ end
719
826
  attributes['bold'] = false
720
827
  update_attributes(new_text, attributes)
721
828
  attributes['bold'] = true
722
829
  new_text << attributes['bg'] == "\e[0m" ? "" : attributes['bg']
723
830
  when 'y' # |y - Foreground text yellow (brown)
724
831
  attributes['fg'] = "\e[33m"
725
- new_text << "\e[0;33m"
832
+ if(attributes['shell_prompt'] == true)
833
+ new_text << "\\[\e[0;33m\\]"
834
+ else
835
+ new_text << "\e[0;33m"
836
+ end
726
837
  attributes['bold'] = false
727
838
  update_attributes(new_text, attributes)
728
839
  new_text << attributes['bg'] == "\e[0m" ? "" : attributes['bg']
729
840
  when 'Y' # |Y - Foreground text bright yellow
730
841
  attributes['fg'] = "\e[1;33m"
731
- new_text << "\e[1;33m"
842
+ if(attributes['shell_prompt'] == true)
843
+ new_text << "\\[\e[1;33m\\]"
844
+ else
845
+ new_text << "\e[1;33m"
846
+ end
732
847
  attributes['bold'] = false
733
848
  update_attributes(new_text, attributes)
734
849
  attributes['bold'] = true
735
850
  new_text << attributes['bg'] == "\e[0m" ? "" : attributes['bg']
736
851
  when 'b' # |b - Foreground text blue
737
852
  attributes['fg'] = "\e[34m"
738
- new_text << "\e[0;34m"
853
+ if(attributes['shell_prompt'] == true)
854
+ new_text << "\\[\e[0;34m\\]"
855
+ else
856
+ new_text << "\e[0;34m"
857
+ end
739
858
  attributes['bold'] = false
740
859
  update_attributes(new_text, attributes)
741
860
  new_text << attributes['bg'] == "\e[0m" ? "" : attributes['bg']
742
861
  when 'B' # |B - Foreground text bright blue
743
862
  attributes['fg'] = "\e[1;34m"
744
- new_text << "\e[1;34m"
863
+ if(attributes['shell_prompt'] == true)
864
+ new_text << "\\[\e[1;34m\\]"
865
+ else
866
+ new_text << "\e[1;34m"
867
+ end
745
868
  attributes['bold'] = false
746
869
  update_attributes(new_text, attributes)
747
870
  attributes['bold'] = true
748
871
  new_text << attributes['bg'] == "\e[0m" ? "" : attributes['bg']
749
872
  when 'm' # |m - Foreground text magenta
750
873
  attributes['fg'] = "\e[35m"
751
- new_text << "\e[0;35m"
874
+ if(attributes['shell_prompt'] == true)
875
+ new_text << "\\[\e[0;35m\\]"
876
+ else
877
+ new_text << "\e[0;35m"
878
+ end
752
879
  attributes['bold'] = false
753
880
  update_attributes(new_text, attributes)
754
881
  new_text << attributes['bg'] == "\e[0m" ? "" : attributes['bg']
755
882
  when 'M' # |M - Foreground text bright magenta
756
883
  attributes['fg'] = "\e[1;35m"
757
- new_text << "\e[1;35m"
884
+ if(attributes['shell_prompt'] == true)
885
+ new_text << "\\[\e[1;35m\\]"
886
+ else
887
+ new_text << "\e[1;35m"
888
+ end
758
889
  attributes['bold'] = false
759
890
  update_attributes(new_text, attributes)
760
891
  attributes['bold'] = true
761
892
  new_text << attributes['bg'] == "\e[0m" ? "" : attributes['bg']
762
893
  when 'c' # |c - Foreground text cyan
763
894
  attributes['fg'] = "\e[36m"
764
- new_text << "\e[0;36m"
895
+ if(attributes['shell_prompt'] == true)
896
+ new_text << "\\[\e[0;36m\\]"
897
+ else
898
+ new_text << "\e[0;36m"
899
+ end
765
900
  attributes['bold'] = false
766
901
  update_attributes(new_text, attributes)
767
902
  new_text << attributes['bg'] == "\e[0m" ? "" : attributes['bg']
768
903
  when 'C' # |C - Foreground text bright cyan
769
904
  attributes['fg'] = "\e[1;36m"
770
- new_text << "\e[1;36m"
905
+ if(attributes['shell_prompt'] == true)
906
+ new_text << "\\[\e[1;36m\\]"
907
+ else
908
+ new_text << "\e[1;36m"
909
+ end
771
910
  attributes['bold'] = false
772
911
  update_attributes(new_text, attributes)
773
912
  attributes['bold'] = true
774
913
  new_text << attributes['bg'] == "\e[0m" ? "" : attributes['bg']
775
914
  when 'W', 'w' # |W or |w - Foreground text white
776
915
  attributes['fg'] = "\e[1;37m"
777
- new_text << "\e[1;37m"
916
+ if(attributes['shell_prompt'] == true)
917
+ new_text << "\\[\e[1;37m\\]"
918
+ else
919
+ new_text << "\e[1;37m"
920
+ end
778
921
  attributes['bold'] = false
779
922
  update_attributes(new_text, attributes)
780
923
  attributes['bold'] = true
781
924
  new_text << attributes['bg'] == "\e[0m" ? "" : attributes['bg']
782
925
  when 'N', 'n' # |N or |n - Foreground text normal
783
926
  attributes['fg'] = ""
784
- new_text << "\e[0;37m"
927
+ if(attributes['shell_prompt'] == true)
928
+ new_text << "\\[\e[0;37m\\]"
929
+ else
930
+ new_text << "\e[0;37m"
931
+ end
785
932
  attributes['bold'] = false
786
933
  update_attributes(new_text, attributes)
787
- new_text << attributes['bg'] == "\e[0m" ? "" : attributes['bg']
934
+ if(attributes['shell_prompt'] == true)
935
+ new_text << attributes['bg'] == "\e[0m" ? "" : "\\[" + attributes['bg'] + "\\]"
936
+ else
937
+ new_text << attributes['bg'] == "\e[0m" ? "" : attributes['bg']
938
+ end
788
939
  when 'O' # |O - Box mode off
789
940
  attributes['box'] = -1
790
941
  when 'o' # |o - Box mode 0
@@ -816,6 +967,12 @@ module PipeText
816
967
  attributes['variable_capture'] = true
817
968
  when '\\' # |\ - Escape mode
818
969
  attributes['escape'] = true
970
+ when '$' # |$ - Toggle shell prompt mode
971
+ if(attributes['shell_prompt'] == true)
972
+ attributes['shell_prompt'] = false
973
+ else
974
+ attributes['shell_prompt'] = true
975
+ end
819
976
  else # We didn't find the next character
820
977
  attributes['found'] = false
821
978
  end
@@ -871,50 +1028,90 @@ module PipeText
871
1028
  attributes['palette_capture'] = 1
872
1029
  return
873
1030
  when 'W', 'w' # &W or &w - Background white
874
- new_text << "\e[0;47m"
1031
+ if(attributes['shell_prompt'] == true)
1032
+ new_text << "\\[\e[0;47m\\]"
1033
+ else
1034
+ new_text << "\e[0;47m"
1035
+ end
875
1036
  attributes['bg'] = "\e[47m"
876
1037
  update_attributes(new_text, attributes)
877
1038
  new_text << attributes['fg'] == "\e[0m" ? "" : attributes['fg']
878
1039
  when 'C', 'c' # &C or &c - Background cyan
879
- new_text << "\e[0;46m"
1040
+ if(attributes['shell_prompt'] == true)
1041
+ new_text << "\\[\e[0;46m\\]"
1042
+ else
1043
+ new_text << "\e[0;46m"
1044
+ end
880
1045
  attributes['bg'] = "\e[46m"
881
1046
  update_attributes(new_text, attributes)
882
1047
  new_text << attributes['fg'] == "\e[0m" ? "" : attributes['fg']
883
1048
  when 'M', 'm' # &M or &m - Background magenta
884
- new_text << "\e[0;45m"
1049
+ if(attributes['shell_prompt'] == true)
1050
+ new_text << "\\[\e[0;45m\\]"
1051
+ else
1052
+ new_text << "\e[0;45m"
1053
+ end
885
1054
  attributes['bg'] = "\e[45m"
886
1055
  update_attributes(new_text, attributes)
887
1056
  new_text << attributes['fg'] == "\e[0m" ? "" : attributes['fg']
888
1057
  when 'B', 'b' # &B or &b - Background blue
889
- new_text << "\e[0;44m"
1058
+ if(attributes['shell_prompt'] == true)
1059
+ new_text << "\\[\e[0;44m\\]"
1060
+ else
1061
+ new_text << "\e[0;44m"
1062
+ end
890
1063
  attributes['bg'] = "\e[44m"
891
1064
  update_attributes(new_text, attributes)
892
1065
  new_text << attributes['fg'] == "\e[0m" ? "" : attributes['fg']
893
1066
  when 'Y', 'y' # &Y or &y - Background yellow (brown)
894
- new_text << "\e[0;43m"
1067
+ if(attributes['shell_prompt'] == true)
1068
+ new_text << "\\[\e[0;43m\\]"
1069
+ else
1070
+ new_text << "\e[0;43m"
1071
+ end
895
1072
  attributes['bg'] = "\e[43m"
896
1073
  update_attributes(new_text, attributes)
897
1074
  new_text << attributes['fg'] == "\e[0m" ? "" : attributes['fg']
898
1075
  when 'G', 'g' # &G or &g - Background green
899
- new_text << "\e[0;42m"
1076
+ if(attributes['shell_prompt'] == true)
1077
+ new_text << "\\[\e[0;42m\\]"
1078
+ else
1079
+ new_text << "\e[0;42m"
1080
+ end
900
1081
  attributes['bg'] = "\e[42m"
901
1082
  update_attributes(new_text, attributes)
902
1083
  new_text << attributes['fg'] == "\e[0m" ? "" : attributes['fg']
903
1084
  when 'R', 'r' # &R or &r - Background red
904
- new_text << "\e[0;41m"
1085
+ if(attributes['shell_prompt'] == true)
1086
+ new_text << "\\[\e[0;41m\\]"
1087
+ else
1088
+ new_text << "\e[0;41m"
1089
+ end
905
1090
  attributes['bg'] ="\e[41m"
906
1091
  update_attributes(new_text, attributes)
907
1092
  new_text << attributes['fg'] == "\e[0m" ? "" : attributes['fg']
908
1093
  when 'S', 's', 'K', 'k' # &S, &s, &K, &k - Background black/smoke
909
- new_text << "\e[0;40m"
1094
+ if(attributes['shell_prompt'] == true)
1095
+ new_text << "\\[\e[0;40m\\]"
1096
+ else
1097
+ new_text << "\e[0;40m"
1098
+ end
910
1099
  attributes['bg'] = "\e[40m"
911
1100
  update_attributes(new_text, attributes)
912
1101
  new_text << attributes['fg'] == "\e[0m" ? "" : attributes['fg']
913
1102
  when 'N', 'n' # &N or &n - Background normal
914
- new_text << "\e[0m"
1103
+ if(attributes['shell_prompt'] == true)
1104
+ new_text << "\\[\e[0m\\]"
1105
+ else
1106
+ new_text << "\e[0m"
1107
+ end
915
1108
  attributes['bg'] = ""
916
1109
  update_attributes(new_text, attributes)
917
- new_text << attributes['fg'] == "\e[0m" ? "" : attributes['fg']
1110
+ if(attributes['shell_prompt'] == true)
1111
+ new_text << attributes['fg'] == "\e[0m" ? "" : "\\[" + attributes['fg'] + "\\]"
1112
+ else
1113
+ new_text << attributes['fg'] == "\e[0m" ? "" : attributes['fg']
1114
+ end
918
1115
  else
919
1116
  new_text << '&' + character
920
1117
  end
File without changes
@@ -4,6 +4,6 @@ module PipeText
4
4
 
5
5
  public
6
6
 
7
- VERSION = "0.2.2"
7
+ VERSION = "0.2.4"
8
8
  end
9
9
 
data/lib/pipetext.rb CHANGED
File without changes
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.2.2
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Minaswan Nakamoto
@@ -11,28 +11,29 @@ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies: []
12
12
  description: "== Easily add colors, boxes, repetitions and emojis to your terminal
13
13
  output using pipes (|).\n \n Install using the Ruby Gem:\n \n > gem install
14
- pipetext\n \n Includes a Ruby library module which can be included in your code:\n
15
- \ \n require 'pipetext'\n\n class YellowPrinter\n include PipeText\n def
16
- print(string)\n write('|Y' + string + '|n')\n end\n end\n\n printer =
17
- YellowPrinter.new\n printer.print('This is yellow')\n \n The gem includes a command
18
- line interface too:\n \n > pipetext\n\n > pipetext '|Ccyan|n'\n\n Works with
19
- files:\n\n > pipetext <filename>\n\n Works with pipes too:\n\n > echo '|RRed
20
- test |u1f49c|n' | pipetext\n\n---\n | pipe || & ampersand && Toggle (&) background
21
- color mode |&\n smoke |s white |W black text on white background
22
- \ |k&w\n red |r bright red |R red background &r\n green |g
23
- \ bright green |G green background &g\n blue |b bright blue |B blue
24
- background &b\n cyan |c bright cyan |C cyan background &c\n yellow
25
- \ |y bright yellow |Y yellow background &y\n magenta |m bright magenta |M
26
- \ magenta background &m\n---\n Hex RGB color codes: Foreground |#RRGGBB Background
27
- \ &#RRGGBB\n Palette colors (256) using Hex: |p33&pF8 Clear Screen |!\n
28
- \ black with white background |K&w Blinking |@\n white with
29
- magenta background |w&m invert |i\n smoke with green background
30
- \ |s&g Underlined |_\n red with cyan background |r&c
31
- \ Italics |~\n bright red with blue background |R&b Bold |+\n
32
- \ green with yellow background |g&y Faint |.\n bright green
33
- with red background |G&r Crossed out |x\n normal color and background
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 |;
14
+ pipetext\n \n Includes a library module which can be included in your code:\n
15
+ \ \n require 'pipetext'\n \n class YellowPrinter\n include PipeText\n def
16
+ print(string)\n write('|Y' + string + '|n')\n end\n end\n \n printer
17
+ = YellowPrinter.new\n printer.print('This is yellow')\n \n The gem includes a
18
+ command line interface too:\n \n > pipetext\n\n > pipetext '|Ccyan|n'\n\n Easily
19
+ set your bash prompt colors using pipetext:\n\n > PS1=$(pipetext '|g\\u|n@|g\\h|n:|g\\w|n$
20
+ ')\n\n Works with files:\n\n > pipetext <filename>\n\n Works with pipes too:\n\n
21
+ \ > echo '|RRed test |u1f49c|n' | pipetext\n\n---\n | pipe || & ampersand &&
22
+ \ Toggle (&) background color mode |&\n smoke |s white |W black text
23
+ on white background |k&w\n red |r bright red |R red background &r\n
24
+ \ green |g bright green |G green background &g\n blue |b bright blue
25
+ \ |B blue background &b\n cyan |c bright cyan |C cyan background
26
+ \ &c\n yellow |y bright yellow |Y yellow background &y\n magenta |m bright
27
+ magenta |M magenta background &m\n---\n Hex RGB color codes: Foreground |#RRGGBB
28
+ \ Background &#RRGGBB\n Palette colors (256) using Hex: |p33&pF8 Clear
29
+ Screen |!\n black with white background |K&w Blinking |@\n
30
+ \ white with magenta background |w&m invert |i\n smoke with
31
+ green background |s&g Underlined |_\n red with cyan background
32
+ \ |r&c Italics |~\n bright red with blue background |R&b
33
+ \ Bold |+\n green with yellow background |g&y Faint |.\n
34
+ \ bright green with red background |G&r Crossed out |x\n normal color
35
+ and background |n&n Escape Sequence |\\\n\n Center text using current
36
+ position and line end number |{text to center}\n Add spaces to line end |;
36
37
  \ Set line end |]#\n Set current x,y cursor position |[x,y] Terminal
37
38
  bell |[bell]\n Move cursor up 1 line |^ Hide cursor |h\n
38
39
  \ Move cursor down 1 line |v Unhide cursor |H\n Move cursor
@@ -41,7 +42,8 @@ description: "== Easily add colors, boxes, repetitions and emojis to your termin
41
42
  variable |(variable name=data) Display variable |(variable name)\n
42
43
  \ Add to variable |(variable name+=data) Subtract from variable |(variable
43
44
  name-=data)\n Multiple variable |(variable name*=data) Divide variable |(variable
44
- name/=data)\n Copy variable to current number |(#variable name)\n\n---\n Emojis:
45
+ name/=data)\n Copy variable to current number |(#variable name)\n\n |$ toggles
46
+ [ and ] around empty sequences automatically for bash command prompts\n\n---\n Emojis:
45
47
  \ https://unicode.org/emoji/charts/full-emoji-list.html\n |[Abbreviated
46
48
  CLDR Short Name] \U0001F60D |[smiling face with heart-eyes] or\n ⚙ |[gear]
47
49
  \ \U0001F4A4 |[zzz] \U0001F468 |[man] \U0001F60D |[sm f w he e]\n ✔ |U2714