command_kit 0.1.0 → 0.3.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.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +18 -3
  3. data/.rubocop.yml +141 -0
  4. data/ChangeLog.md +165 -0
  5. data/Gemfile +3 -0
  6. data/README.md +186 -118
  7. data/Rakefile +3 -2
  8. data/command_kit.gemspec +4 -4
  9. data/examples/command.rb +1 -1
  10. data/gemspec.yml +7 -0
  11. data/lib/command_kit/arguments/argument.rb +2 -2
  12. data/lib/command_kit/arguments.rb +36 -7
  13. data/lib/command_kit/colors.rb +702 -53
  14. data/lib/command_kit/command.rb +2 -3
  15. data/lib/command_kit/commands/auto_load.rb +8 -1
  16. data/lib/command_kit/commands/help.rb +3 -2
  17. data/lib/command_kit/commands/subcommand.rb +1 -1
  18. data/lib/command_kit/commands.rb +24 -9
  19. data/lib/command_kit/env/path.rb +1 -1
  20. data/lib/command_kit/file_utils.rb +46 -0
  21. data/lib/command_kit/help/man.rb +17 -33
  22. data/lib/command_kit/inflector.rb +47 -17
  23. data/lib/command_kit/interactive.rb +9 -0
  24. data/lib/command_kit/main.rb +7 -9
  25. data/lib/command_kit/man.rb +44 -0
  26. data/lib/command_kit/open_app.rb +69 -0
  27. data/lib/command_kit/options/option.rb +41 -27
  28. data/lib/command_kit/options/option_value.rb +3 -2
  29. data/lib/command_kit/options/parser.rb +17 -22
  30. data/lib/command_kit/options.rb +102 -14
  31. data/lib/command_kit/os/linux.rb +157 -0
  32. data/lib/command_kit/os.rb +159 -11
  33. data/lib/command_kit/package_manager.rb +200 -0
  34. data/lib/command_kit/pager.rb +46 -4
  35. data/lib/command_kit/printing/indent.rb +4 -4
  36. data/lib/command_kit/printing.rb +14 -3
  37. data/lib/command_kit/program_name.rb +9 -0
  38. data/lib/command_kit/sudo.rb +40 -0
  39. data/lib/command_kit/terminal.rb +5 -0
  40. data/lib/command_kit/version.rb +1 -1
  41. data/spec/arguments/argument_spec.rb +1 -1
  42. data/spec/arguments_spec.rb +84 -1
  43. data/spec/colors_spec.rb +357 -70
  44. data/spec/command_spec.rb +77 -6
  45. data/spec/commands/auto_load_spec.rb +33 -2
  46. data/spec/commands_spec.rb +101 -29
  47. data/spec/env/path_spec.rb +6 -0
  48. data/spec/exception_handler_spec.rb +1 -1
  49. data/spec/file_utils_spec.rb +59 -0
  50. data/spec/fixtures/template.erb +5 -0
  51. data/spec/help/man_spec.rb +54 -57
  52. data/spec/inflector_spec.rb +70 -8
  53. data/spec/man_spec.rb +46 -0
  54. data/spec/open_app_spec.rb +85 -0
  55. data/spec/options/option_spec.rb +38 -2
  56. data/spec/options/option_value_spec.rb +55 -0
  57. data/spec/options/parser_spec.rb +0 -10
  58. data/spec/options_spec.rb +328 -0
  59. data/spec/os/linux_spec.rb +164 -0
  60. data/spec/os_spec.rb +200 -13
  61. data/spec/package_manager_spec.rb +806 -0
  62. data/spec/pager_spec.rb +71 -6
  63. data/spec/printing/indent_spec.rb +7 -5
  64. data/spec/printing_spec.rb +23 -1
  65. data/spec/program_name_spec.rb +8 -0
  66. data/spec/sudo_spec.rb +51 -0
  67. data/spec/terminal_spec.rb +30 -0
  68. data/spec/usage_spec.rb +1 -1
  69. metadata +23 -4
@@ -26,7 +26,7 @@ module CommandKit
26
26
  #
27
27
  # ## Alternatives
28
28
  #
29
- # * [ansi](http://rubyworks.github.io/ansi/)
29
+ # * [ansi](https://rubyworks.github.io/ansi/)
30
30
  # * [colorize](https://github.com/fazibear/colorize#readme)
31
31
  #
32
32
  # @see https://en.wikipedia.org/wiki/ANSI_escape_code
@@ -67,7 +67,7 @@ module CommandKit
67
67
  # ANSI color code for blue
68
68
  BLUE = "\e[34m"
69
69
 
70
- # ANSI color code for megenta
70
+ # ANSI color code for magenta
71
71
  MAGENTA = "\e[35m"
72
72
 
73
73
  # ANSI color code for cyan
@@ -76,11 +76,145 @@ module CommandKit
76
76
  # ANSI color code for white
77
77
  WHITE = "\e[37m"
78
78
 
79
+ # ANSI color code for black
80
+ #
81
+ # @since 0.3.0
82
+ BRIGHT_BLACK = "\e[90m"
83
+
84
+ # ANSI color code for red
85
+ #
86
+ # @since 0.3.0
87
+ BRIGHT_RED = "\e[91m"
88
+
89
+ # ANSI color code for green
90
+ #
91
+ # @since 0.3.0
92
+ BRIGHT_GREEN = "\e[92m"
93
+
94
+ # ANSI color code for yellow
95
+ #
96
+ # @since 0.3.0
97
+ BRIGHT_YELLOW = "\e[93m"
98
+
99
+ # ANSI color code for blue
100
+ #
101
+ # @since 0.3.0
102
+ BRIGHT_BLUE = "\e[94m"
103
+
104
+ # ANSI color code for magenta
105
+ #
106
+ # @since 0.3.0
107
+ BRIGHT_MAGENTA = "\e[95m"
108
+
109
+ # ANSI color code for cyan
110
+ #
111
+ # @since 0.3.0
112
+ BRIGHT_CYAN = "\e[96m"
113
+
114
+ # ANSI color code for white
115
+ #
116
+ # @since 0.3.0
117
+ BRIGHT_WHITE = "\e[97m"
118
+
79
119
  # ANSI color for the default foreground color
80
- RESET_COLOR = "\e[39m"
120
+ #
121
+ # @since 0.3.0
122
+ RESET_FG = "\e[39m"
123
+
124
+ # @see RESET_FG
125
+ RESET_COLOR = RESET_FG
126
+
127
+ # ANSI color code for background color black
128
+ #
129
+ # @since 0.2.0
130
+ ON_BLACK = "\e[40m"
131
+
132
+ # ANSI color code for background color red
133
+ #
134
+ # @since 0.2.0
135
+ ON_RED = "\e[41m"
136
+
137
+ # ANSI color code for background color green
138
+ #
139
+ # @since 0.2.0
140
+ ON_GREEN = "\e[42m"
141
+
142
+ # ANSI color code for background color yellow
143
+ #
144
+ # @since 0.2.0
145
+ ON_YELLOW = "\e[43m"
146
+
147
+ # ANSI color code for background color blue
148
+ #
149
+ # @since 0.2.0
150
+ ON_BLUE = "\e[44m"
151
+
152
+ # ANSI color code for background color magenta
153
+ #
154
+ # @since 0.2.0
155
+ ON_MAGENTA = "\e[45m"
156
+
157
+ # ANSI color code for background color cyan
158
+ #
159
+ # @since 0.2.0
160
+ ON_CYAN = "\e[46m"
161
+
162
+ # ANSI color code for background color white
163
+ #
164
+ # @since 0.2.0
165
+ ON_WHITE = "\e[47m"
166
+
167
+ # ANSI color code for background color bright black
168
+ #
169
+ # @since 0.3.0
170
+ ON_BRIGHT_BLACK = "\e[100m"
171
+
172
+ # ANSI color code for background color bright red
173
+ #
174
+ # @since 0.3.0
175
+ ON_BRIGHT_RED = "\e[101m"
176
+
177
+ # ANSI color code for background color bright green
178
+ #
179
+ # @since 0.3.0
180
+ ON_BRIGHT_GREEN = "\e[102m"
181
+
182
+ # ANSI color code for background color bright yellow
183
+ #
184
+ # @since 0.3.0
185
+ ON_BRIGHT_YELLOW = "\e[103m"
186
+
187
+ # ANSI color code for background color bright blue
188
+ #
189
+ # @since 0.3.0
190
+ ON_BRIGHT_BLUE = "\e[104m"
191
+
192
+ # ANSI color code for background color bright magenta
193
+ #
194
+ # @since 0.3.0
195
+ ON_BRIGHT_MAGENTA = "\e[105m"
196
+
197
+ # ANSI color code for background color bright cyan
198
+ #
199
+ # @since 0.3.0
200
+ ON_BRIGHT_CYAN = "\e[106m"
201
+
202
+ # ANSI color code for background color bright white
203
+ #
204
+ # @since 0.3.0
205
+ ON_BRIGHT_WHITE = "\e[107m"
206
+
207
+ # ANSI color for the default background color
208
+ #
209
+ # @since 0.2.0
210
+ RESET_BG = "\e[49m"
81
211
 
82
212
  module_function
83
213
 
214
+ #
215
+ # @group Styling Methods
216
+ #
217
+
84
218
  #
85
219
  # Resets text formatting.
86
220
  #
@@ -122,6 +256,10 @@ module CommandKit
122
256
  end
123
257
  end
124
258
 
259
+ #
260
+ # @group Foreground Color Methods
261
+ #
262
+
125
263
  #
126
264
  # Sets the text color to black.
127
265
  #
@@ -136,7 +274,7 @@ module CommandKit
136
274
  # @api public
137
275
  #
138
276
  def black(string=nil)
139
- if string then "#{BLACK}#{string}#{RESET_COLOR}"
277
+ if string then "#{BLACK}#{string}#{RESET_FG}"
140
278
  else BLACK
141
279
  end
142
280
  end
@@ -155,7 +293,7 @@ module CommandKit
155
293
  # @api public
156
294
  #
157
295
  def red(string=nil)
158
- if string then "#{RED}#{string}#{RESET_COLOR}"
296
+ if string then "#{RED}#{string}#{RESET_FG}"
159
297
  else RED
160
298
  end
161
299
  end
@@ -174,7 +312,7 @@ module CommandKit
174
312
  # @api public
175
313
  #
176
314
  def green(string=nil)
177
- if string then "#{GREEN}#{string}#{RESET_COLOR}"
315
+ if string then "#{GREEN}#{string}#{RESET_FG}"
178
316
  else GREEN
179
317
  end
180
318
  end
@@ -193,7 +331,7 @@ module CommandKit
193
331
  # @api public
194
332
  #
195
333
  def yellow(string=nil)
196
- if string then "#{YELLOW}#{string}#{RESET_COLOR}"
334
+ if string then "#{YELLOW}#{string}#{RESET_FG}"
197
335
  else YELLOW
198
336
  end
199
337
  end
@@ -212,7 +350,7 @@ module CommandKit
212
350
  # @api public
213
351
  #
214
352
  def blue(string=nil)
215
- if string then "#{BLUE}#{string}#{RESET_COLOR}"
353
+ if string then "#{BLUE}#{string}#{RESET_FG}"
216
354
  else BLUE
217
355
  end
218
356
  end
@@ -231,7 +369,7 @@ module CommandKit
231
369
  # @api public
232
370
  #
233
371
  def magenta(string=nil)
234
- if string then "#{MAGENTA}#{string}#{RESET_COLOR}"
372
+ if string then "#{MAGENTA}#{string}#{RESET_FG}"
235
373
  else MAGENTA
236
374
  end
237
375
  end
@@ -250,7 +388,7 @@ module CommandKit
250
388
  # @api public
251
389
  #
252
390
  def cyan(string=nil)
253
- if string then "#{CYAN}#{string}#{RESET_COLOR}"
391
+ if string then "#{CYAN}#{string}#{RESET_FG}"
254
392
  else CYAN
255
393
  end
256
394
  end
@@ -269,75 +407,586 @@ module CommandKit
269
407
  # @api public
270
408
  #
271
409
  def white(string=nil)
272
- if string then "#{WHITE}#{string}#{RESET_COLOR}"
410
+ if string then "#{WHITE}#{string}#{RESET_FG}"
273
411
  else WHITE
274
412
  end
275
413
  end
276
- end
277
414
 
278
- #
279
- # Dummy module with the same interface as {ANSI}, but for when ANSI is not
280
- # supported.
281
- #
282
- module PlainText
283
- RESET = \
284
- CLEAR = \
285
- BOLD = \
286
- RESET_INTENSITY = \
287
- BLACK = \
288
- RED = \
289
- GREEN = \
290
- YELLOW = \
291
- BLUE = \
292
- MAGENTA = \
293
- CYAN = \
294
- WHITE = \
295
- RESET_COLOR = ''
415
+ #
416
+ # Sets the text color to bright black (gray).
417
+ #
418
+ # @param [String, nil] string
419
+ # An optional string.
420
+ #
421
+ # @return [String, BRIGHT_BLACK]
422
+ # The colorized string or just {BRIGHT_BLACK} if no arguments were
423
+ # given.
424
+ #
425
+ # @see BRIGHT_BLACK
426
+ #
427
+ # @api public
428
+ #
429
+ # @since 0.3.0
430
+ #
431
+ def bright_black(string=nil)
432
+ if string then "#{BRIGHT_BLACK}#{string}#{RESET_FG}"
433
+ else BRIGHT_BLACK
434
+ end
435
+ end
296
436
 
297
- module_function
437
+ #
438
+ # Sets the text color to gray.
439
+ #
440
+ # @api public
441
+ #
442
+ # @see #bright_black
443
+ #
444
+ # @since 0.3.0
445
+ #
446
+ def gray(string=nil)
447
+ bright_black(string)
448
+ end
298
449
 
299
- def reset
300
- RESET
450
+ #
451
+ # Sets the text color to bright red.
452
+ #
453
+ # @param [String, nil] string
454
+ # An optional string.
455
+ #
456
+ # @return [String, BRIGHT_RED]
457
+ # The colorized string or just {BRIGHT_RED} if no arguments were given.
458
+ #
459
+ # @see BRIGHT_RED
460
+ #
461
+ # @api public
462
+ #
463
+ # @since 0.3.0
464
+ #
465
+ def bright_red(string=nil)
466
+ if string then "#{BRIGHT_RED}#{string}#{RESET_FG}"
467
+ else BRIGHT_RED
468
+ end
301
469
  end
302
470
 
303
- def clear
304
- reset
471
+ #
472
+ # Sets the text color to bright green.
473
+ #
474
+ # @param [String, nil] string
475
+ # An optional string.
476
+ #
477
+ # @return [String, BRIGHT_GREEN]
478
+ # The colorized string or just {BRIGHT_GREEN} if no arguments were
479
+ # given.
480
+ #
481
+ # @see BRIGHT_GREEN
482
+ #
483
+ # @api public
484
+ #
485
+ # @since 0.3.0
486
+ #
487
+ def bright_green(string=nil)
488
+ if string then "#{BRIGHT_GREEN}#{string}#{RESET_FG}"
489
+ else BRIGHT_GREEN
490
+ end
305
491
  end
306
492
 
307
- def bold(string=nil)
308
- string || ''
493
+ #
494
+ # Sets the text color to bright yellow.
495
+ #
496
+ # @param [String, nil] string
497
+ # An optional string.
498
+ #
499
+ # @return [String, BRIGHT_YELLOW]
500
+ # The colorized string or just {BRIGHT_YELLOW} if no arguments were
501
+ # given.
502
+ #
503
+ # @see BRIGHT_YELLOW
504
+ #
505
+ # @api public
506
+ #
507
+ # @since 0.3.0
508
+ #
509
+ def bright_yellow(string=nil)
510
+ if string then "#{BRIGHT_YELLOW}#{string}#{RESET_FG}"
511
+ else BRIGHT_YELLOW
512
+ end
309
513
  end
310
514
 
311
- def black(string=nil)
312
- string || ''
515
+ #
516
+ # Sets the text color to bright blue.
517
+ #
518
+ # @param [String, nil] string
519
+ # An optional string.
520
+ #
521
+ # @return [String, BRIGHT_BLUE]
522
+ # The colorized string or just {BRIGHT_BLUE} if no arguments were given.
523
+ #
524
+ # @see BRIGHT_BLUE
525
+ #
526
+ # @api public
527
+ #
528
+ # @since 0.3.0
529
+ #
530
+ def bright_blue(string=nil)
531
+ if string then "#{BRIGHT_BLUE}#{string}#{RESET_FG}"
532
+ else BRIGHT_BLUE
533
+ end
313
534
  end
314
535
 
315
- def red(string=nil)
316
- string || ''
536
+ #
537
+ # Sets the text color to bright magenta.
538
+ #
539
+ # @param [String, nil] string
540
+ # An optional string.
541
+ #
542
+ # @return [String, BRIGHT_MAGENTA]
543
+ # The colorized string or just {BRIGHT_MAGENTA} if no arguments were
544
+ # given.
545
+ #
546
+ # @see BRIGHT_MAGENTA
547
+ #
548
+ # @api public
549
+ #
550
+ # @since 0.3.0
551
+ #
552
+ def bright_magenta(string=nil)
553
+ if string then "#{BRIGHT_MAGENTA}#{string}#{RESET_FG}"
554
+ else BRIGHT_MAGENTA
555
+ end
317
556
  end
318
557
 
319
- def green(string=nil)
320
- string || ''
558
+ #
559
+ # Sets the text color to bright cyan.
560
+ #
561
+ # @param [String, nil] string
562
+ # An optional string.
563
+ #
564
+ # @return [String, BRIGHT_CYAN]
565
+ # The colorized string or just {BRIGHT_CYAN} if no arguments were given.
566
+ #
567
+ # @see BRIGHT_CYAN
568
+ #
569
+ # @api public
570
+ #
571
+ # @since 0.3.0
572
+ #
573
+ def bright_cyan(string=nil)
574
+ if string then "#{BRIGHT_CYAN}#{string}#{RESET_FG}"
575
+ else BRIGHT_CYAN
576
+ end
321
577
  end
322
578
 
323
- def yellow(string=nil)
324
- string || ''
579
+ #
580
+ # Sets the text color to bright white.
581
+ #
582
+ # @param [String, nil] string
583
+ # An optional string.
584
+ #
585
+ # @return [String, BRIGHT_WHITE]
586
+ # The colorized string or just {BRIGHT_WHITE} if no arguments were
587
+ # given.
588
+ #
589
+ # @see BRIGHT_WHITE
590
+ #
591
+ # @api public
592
+ #
593
+ # @since 0.3.0
594
+ #
595
+ def bright_white(string=nil)
596
+ if string then "#{BRIGHT_WHITE}#{string}#{RESET_FG}"
597
+ else BRIGHT_WHITE
598
+ end
325
599
  end
326
600
 
327
- def blue(string=nil)
328
- string || ''
601
+ #
602
+ # @group Background Color Methods
603
+ #
604
+
605
+ #
606
+ # Sets the background color to black.
607
+ #
608
+ # @param [String, nil] string
609
+ # An optional string.
610
+ #
611
+ # @return [String, ON_BLACK]
612
+ # The colorized string or just {ON_BLACK} if no arguments were given.
613
+ #
614
+ # @see ON_BLACK
615
+ #
616
+ # @api public
617
+ #
618
+ # @since 0.2.0
619
+ #
620
+ def on_black(string=nil)
621
+ if string then "#{ON_BLACK}#{string}#{RESET_BG}"
622
+ else ON_BLACK
623
+ end
329
624
  end
330
625
 
331
- def magenta(string=nil)
332
- string || ''
626
+ #
627
+ # Sets the background color to red.
628
+ #
629
+ # @param [String, nil] string
630
+ # An optional string.
631
+ #
632
+ # @return [String, ON_RED]
633
+ # The colorized string or just {ON_RED} if no arguments were given.
634
+ #
635
+ # @see ON_RED
636
+ #
637
+ # @api public
638
+ #
639
+ # @since 0.2.0
640
+ #
641
+ def on_red(string=nil)
642
+ if string then "#{ON_RED}#{string}#{RESET_BG}"
643
+ else ON_RED
644
+ end
333
645
  end
334
646
 
335
- def cyan(string=nil)
336
- string || ''
647
+ #
648
+ # Sets the background color to green.
649
+ #
650
+ # @param [String, nil] string
651
+ # An optional string.
652
+ #
653
+ # @return [String, ON_GREEN]
654
+ # The colorized string or just {ON_GREEN} if no arguments were given.
655
+ #
656
+ # @see ON_GREEN
657
+ #
658
+ # @api public
659
+ #
660
+ # @since 0.2.0
661
+ #
662
+ def on_green(string=nil)
663
+ if string then "#{ON_GREEN}#{string}#{RESET_BG}"
664
+ else ON_GREEN
665
+ end
337
666
  end
338
667
 
339
- def white(string=nil)
340
- string || ''
668
+ #
669
+ # Sets the background color to yellow.
670
+ #
671
+ # @param [String, nil] string
672
+ # An optional string.
673
+ #
674
+ # @return [String, ON_YELLOW]
675
+ # The colorized string or just {ON_YELLOW} if no arguments were given.
676
+ #
677
+ # @see ON_YELLOW
678
+ #
679
+ # @api public
680
+ #
681
+ # @since 0.2.0
682
+ #
683
+ def on_yellow(string=nil)
684
+ if string then "#{ON_YELLOW}#{string}#{RESET_BG}"
685
+ else ON_YELLOW
686
+ end
687
+ end
688
+
689
+ #
690
+ # Sets the background color to blue.
691
+ #
692
+ # @param [String, nil] string
693
+ # An optional string.
694
+ #
695
+ # @return [String, ON_BLUE]
696
+ # The colorized string or just {ON_BLUE} if no arguments were given.
697
+ #
698
+ # @see ON_BLUE
699
+ #
700
+ # @api public
701
+ #
702
+ # @since 0.2.0
703
+ #
704
+ def on_blue(string=nil)
705
+ if string then "#{ON_BLUE}#{string}#{RESET_BG}"
706
+ else ON_BLUE
707
+ end
708
+ end
709
+
710
+ #
711
+ # Sets the background color to magenta.
712
+ #
713
+ # @param [String, nil] string
714
+ # An optional string.
715
+ #
716
+ # @return [String, ON_MAGENTA]
717
+ # The colorized string or just {ON_MAGENTA} if no arguments were given.
718
+ #
719
+ # @see ON_MAGENTA
720
+ #
721
+ # @api public
722
+ #
723
+ # @since 0.2.0
724
+ #
725
+ def on_magenta(string=nil)
726
+ if string then "#{ON_MAGENTA}#{string}#{RESET_BG}"
727
+ else ON_MAGENTA
728
+ end
729
+ end
730
+
731
+ #
732
+ # Sets the background color to cyan.
733
+ #
734
+ # @param [String, nil] string
735
+ # An optional string.
736
+ #
737
+ # @return [String, ON_CYAN]
738
+ # The colorized string or just {ON_CYAN} if no arguments were given.
739
+ #
740
+ # @see ON_CYAN
741
+ #
742
+ # @api public
743
+ #
744
+ # @since 0.2.0
745
+ #
746
+ def on_cyan(string=nil)
747
+ if string then "#{ON_CYAN}#{string}#{RESET_BG}"
748
+ else ON_CYAN
749
+ end
750
+ end
751
+
752
+ #
753
+ # Sets the background color to white.
754
+ #
755
+ # @param [String, nil] string
756
+ # An optional string.
757
+ #
758
+ # @return [String, ON_WHITE]
759
+ # The colorized string or just {ON_WHITE} if no arguments were given.
760
+ #
761
+ # @see ON_WHITE
762
+ #
763
+ # @api public
764
+ #
765
+ # @since 0.2.0
766
+ #
767
+ def on_white(string=nil)
768
+ if string then "#{ON_WHITE}#{string}#{RESET_BG}"
769
+ else ON_WHITE
770
+ end
771
+ end
772
+
773
+ #
774
+ # Sets the background color to bright black.
775
+ #
776
+ # @param [String, nil] string
777
+ # An optional string.
778
+ #
779
+ # @return [String, ON_BRIGHT_BLACK]
780
+ # The colorized string or just {ON_BRIGHT_BLACK} if no arguments were
781
+ # given.
782
+ #
783
+ # @see ON_BRIGHT_BLACK
784
+ #
785
+ # @api public
786
+ #
787
+ # @since 0.3.0
788
+ #
789
+ def on_bright_black(string=nil)
790
+ if string then "#{ON_BRIGHT_BLACK}#{string}#{RESET_BG}"
791
+ else ON_BRIGHT_BLACK
792
+ end
793
+ end
794
+
795
+ #
796
+ # @see #on_bright_black
797
+ #
798
+ # @api public
799
+ #
800
+ # @since 0.3.0
801
+ #
802
+ def on_gray(string=nil)
803
+ on_bright_black(string)
804
+ end
805
+
806
+ #
807
+ # Sets the background color to bright red.
808
+ #
809
+ # @param [String, nil] string
810
+ # An optional string.
811
+ #
812
+ # @return [String, ON_BRIGHT_RED]
813
+ # The colorized string or just {ON_BRIGHT_RED} if no arguments were
814
+ # given.
815
+ #
816
+ # @see ON_BRIGHT_RED
817
+ #
818
+ # @api public
819
+ #
820
+ # @since 0.3.0
821
+ #
822
+ def on_bright_red(string=nil)
823
+ if string then "#{ON_BRIGHT_RED}#{string}#{RESET_BG}"
824
+ else ON_BRIGHT_RED
825
+ end
826
+ end
827
+
828
+ #
829
+ # Sets the background color to bright green.
830
+ #
831
+ # @param [String, nil] string
832
+ # An optional string.
833
+ #
834
+ # @return [String, ON_BRIGHT_GREEN]
835
+ # The colorized string or just {ON_BRIGHT_GREEN} if no arguments were
836
+ # given.
837
+ #
838
+ # @see ON_BRIGHT_GREEN
839
+ #
840
+ # @api public
841
+ #
842
+ # @since 0.3.0
843
+ #
844
+ def on_bright_green(string=nil)
845
+ if string then "#{ON_BRIGHT_GREEN}#{string}#{RESET_BG}"
846
+ else ON_BRIGHT_GREEN
847
+ end
848
+ end
849
+
850
+ #
851
+ # Sets the background color to bright yellow.
852
+ #
853
+ # @param [String, nil] string
854
+ # An optional string.
855
+ #
856
+ # @return [String, ON_BRIGHT_YELLOW]
857
+ # The colorized string or just {ON_BRIGHT_YELLOW} if no arguments were
858
+ # given.
859
+ #
860
+ # @see ON_BRIGHT_YELLOW
861
+ #
862
+ # @api public
863
+ #
864
+ # @since 0.3.0
865
+ #
866
+ def on_bright_yellow(string=nil)
867
+ if string then "#{ON_BRIGHT_YELLOW}#{string}#{RESET_BG}"
868
+ else ON_BRIGHT_YELLOW
869
+ end
870
+ end
871
+
872
+ #
873
+ # Sets the background color to bright blue.
874
+ #
875
+ # @param [String, nil] string
876
+ # An optional string.
877
+ #
878
+ # @return [String, ON_BRIGHT_BLUE]
879
+ # The colorized string or just {ON_BRIGHT_BLUE} if no arguments were
880
+ # given.
881
+ #
882
+ # @see ON_BRIGHT_BLUE
883
+ #
884
+ # @api public
885
+ #
886
+ # @since 0.3.0
887
+ #
888
+ def on_bright_blue(string=nil)
889
+ if string then "#{ON_BRIGHT_BLUE}#{string}#{RESET_BG}"
890
+ else ON_BRIGHT_BLUE
891
+ end
892
+ end
893
+
894
+ #
895
+ # Sets the background color to bright magenta.
896
+ #
897
+ # @param [String, nil] string
898
+ # An optional string.
899
+ #
900
+ # @return [String, ON_BRIGHT_MAGENTA]
901
+ # The colorized string or just {ON_BRIGHT_MAGENTA} if no arguments were
902
+ # given.
903
+ #
904
+ # @see ON_BRIGHT_MAGENTA
905
+ #
906
+ # @api public
907
+ #
908
+ # @since 0.3.0
909
+ #
910
+ def on_bright_magenta(string=nil)
911
+ if string then "#{ON_BRIGHT_MAGENTA}#{string}#{RESET_BG}"
912
+ else ON_BRIGHT_MAGENTA
913
+ end
914
+ end
915
+
916
+ #
917
+ # Sets the background color to bright cyan.
918
+ #
919
+ # @param [String, nil] string
920
+ # An optional string.
921
+ #
922
+ # @return [String, ON_BRIGHT_CYAN]
923
+ # The colorized string or just {ON_BRIGHT_CYAN} if no arguments were
924
+ # given.
925
+ #
926
+ # @see ON_BRIGHT_CYAN
927
+ #
928
+ # @api public
929
+ #
930
+ # @since 0.3.0
931
+ #
932
+ def on_bright_cyan(string=nil)
933
+ if string then "#{ON_BRIGHT_CYAN}#{string}#{RESET_BG}"
934
+ else ON_BRIGHT_CYAN
935
+ end
936
+ end
937
+
938
+ #
939
+ # Sets the background color to bright white.
940
+ #
941
+ # @param [String, nil] string
942
+ # An optional string.
943
+ #
944
+ # @return [String, ON_BRIGHT_WHITE]
945
+ # The colorized string or just {ON_BRIGHT_WHITE} if no arguments were
946
+ # given.
947
+ #
948
+ # @see ON_BRIGHT_WHITE
949
+ #
950
+ # @api public
951
+ #
952
+ # @since 0.3.0
953
+ #
954
+ def on_bright_white(string=nil)
955
+ if string then "#{ON_BRIGHT_WHITE}#{string}#{RESET_BG}"
956
+ else ON_BRIGHT_WHITE
957
+ end
958
+ end
959
+ end
960
+
961
+ #
962
+ # Dummy module with the same interface as {ANSI}, but for when ANSI is not
963
+ # supported.
964
+ #
965
+ module PlainText
966
+ ANSI.constants(false).each do |name|
967
+ const_set(name,'')
968
+ end
969
+
970
+ module_function
971
+
972
+ def reset
973
+ RESET
974
+ end
975
+
976
+ def clear
977
+ reset
978
+ end
979
+
980
+ [
981
+ :bold,
982
+ :black, :red, :green, :yellow, :blue, :magenta, :cyan, :white,
983
+ :bright_black, :gray, :bright_red, :bright_green, :bright_yellow, :bright_blue, :bright_magenta, :bright_cyan, :bright_white,
984
+ :on_black, :on_red, :on_green, :on_yellow, :on_blue, :on_magenta, :on_cyan, :on_white,
985
+ :on_bright_black, :on_gray, :on_bright_red, :on_bright_green, :on_bright_yellow, :on_bright_blue, :on_bright_magenta, :on_bright_cyan, :on_bright_white
986
+ ].each do |name|
987
+ define_method(name) do |string=nil|
988
+ string || ''
989
+ end
341
990
  end
342
991
  end
343
992