antex 0.2.2

Styled text and tree in terminal
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
use crate::colors::{Color, RgbColor};
use crate::mode::ColorMode;
use std::fmt;
use std::fmt::{Alignment, Debug, Display};
use std::ops::{Add, AddAssign};

/// A trait representing styled text.
pub trait StyledText: Sized {
  /// Adds content to text.
  fn s<T: Display>(self, s: T) -> Self;

  /// Resets all styling and then appends formatted content.
  ///
  /// This is equivalent to calling `text.reset().s(value)`.
  fn r<T: Display>(self, s: T) -> Self {
    self.reset().s(s)
  }
  /// Resets all colors and styling flags.
  fn reset(self) -> Self;
  /// Adds repeated content to text.
  fn repeat<T: Display>(self, s: T, n: usize) -> Self;
  /// Adds `s` suffix to the content when the number is not 1.
  fn plural<T: Display>(self, s: T, n: usize) -> Self;
  /// Adds the content aligned left with specified width.
  fn align_left<T: Display>(self, s: T, width: usize) -> Self;
  /// Adds the content aligned right with specified width.
  fn align_right<T: Display>(self, s: T, width: usize) -> Self;
  /// Adds the content centered with specified width.
  fn align_center<T: Display>(self, s: T, width: usize) -> Self;
  /// Pads the content with specified character.
  fn pad<T: Display>(self, ch: char, padding: usize, s: T) -> Self;
  /// Pads the content aligned the left with specified width.
  fn pad_left<T: Display>(self, ch: char, s: T, width: usize) -> Self;
  /// Pads the content aligned right with specified width.
  fn pad_right<T: Display>(self, ch: char, s: T, width: usize) -> Self;
  /// Pads the content centered with specified width.
  fn pad_center<T: Display>(self, ch: char, s: T, width: usize) -> Self;
  /// Fills the content with the given character until the given width is reached.
  fn fill(self, ch: char, width: usize) -> Self;
  /// Adds new content based on the condition.
  fn choose<T: Display>(self, condition: bool, when_true: T, when_false: T) -> Self;
  /// Adds indented content.
  fn indent<T: Display>(self, indent: usize, s: T) -> Self;
  /// Style text as bold.
  fn bold(self) -> Self;
  /// Style text as italic.
  fn italic(self) -> Self;
  /// Style text as underlined.
  fn underline(self) -> Self;
  /// Sets the foreground color to black.
  fn black(self) -> Self;
  /// Sets the foreground color to bright black.
  fn bright_black(self) -> Self;
  /// Sets the foreground color to red.
  fn red(self) -> Self;
  /// Sets the foreground color to bright red.
  fn bright_red(self) -> Self;
  /// Sets the foreground color to green.
  fn green(self) -> Self;
  /// Sets the foreground color to bright green.
  fn bright_green(self) -> Self;
  /// Sets the foreground color to yellow.
  fn yellow(self) -> Self;
  /// Sets the foreground color to bright yellow.
  fn bright_yellow(self) -> Self;
  /// Sets the foreground color to blue.
  fn blue(self) -> Self;
  /// Sets the foreground color to bright blue.
  fn bright_blue(self) -> Self;
  /// Sets the foreground color to magenta.
  fn magenta(self) -> Self;
  /// Sets the foreground color to bright magenta.
  fn bright_magenta(self) -> Self;
  /// Sets the foreground color to cyan.
  fn cyan(self) -> Self;
  /// Sets the foreground color to bright cyan.
  fn bright_cyan(self) -> Self;
  /// Sets the foreground color to white.
  fn white(self) -> Self;
  /// Sets the foreground color to bright white.
  fn bright_white(self) -> Self;
  /// Sets the background color to black.
  fn bg_black(self) -> Self;
  /// Sets the background color to bright black.
  fn bg_bright_black(self) -> Self;
  /// Sets the background color to red.
  fn bg_red(self) -> Self;
  /// Sets the background color to bright red.
  fn bg_bright_red(self) -> Self;
  /// Sets the background color to green.
  fn bg_green(self) -> Self;
  /// Sets the background color to bright green.
  fn bg_bright_green(self) -> Self;
  /// Sets the background color to yellow.
  fn bg_yellow(self) -> Self;
  /// Sets the background color to bright yellow.
  fn bg_bright_yellow(self) -> Self;
  /// Sets the background color to blue.
  fn bg_blue(self) -> Self;
  /// Sets the background color to bright blue.
  fn bg_bright_blue(self) -> Self;
  /// Sets the background color to magenta.
  fn bg_magenta(self) -> Self;
  /// Sets the background color to bright magenta.
  fn bg_bright_magenta(self) -> Self;
  /// Sets the background color to cyan.
  fn bg_cyan(self) -> Self;
  /// Sets the background color to bright cyan.
  fn bg_bright_cyan(self) -> Self;
  /// Sets the background color to white.
  fn bg_white(self) -> Self;
  /// Sets the background color to bright white.
  fn bg_bright_white(self) -> Self;
  /// Sets the color by color enumeration.
  fn color(self, c: Color) -> Self;
  /// Sets the bright color by color enumeration.
  fn bright_color(self, c: Color) -> Self;
  /// Sets the background color by color enumeration.
  fn bg_color(self, c: Color) -> Self;
  /// Sets the background bright color by color enumeration.
  fn bg_bright_color(self, c: Color) -> Self;
  /// Sets the color by color index.
  fn color_8(self, c: u8) -> Self;
  /// Sets the bright color by color index.
  fn bright_color_8(self, c: u8) -> Self;
  /// Sets the background color by color index.
  fn bg_color_8(self, c: u8) -> Self;
  /// Sets the background bright color by color index.
  fn bg_bright_color_8(self, c: u8) -> Self;
  fn color_256(self, c: u8) -> Self;
  fn bg_color_256(self, c: u8) -> Self;
  fn color_rgb(self, c: RgbColor) -> Self;
  fn bg_color_rgb(self, c: RgbColor) -> Self;
}

#[derive(Debug, Clone)]
enum Sequence {
  Char(char),
  Control(String),
}

impl Display for Sequence {
  fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
    match self {
      Sequence::Char(ch) => write!(f, "{}", ch),
      Sequence::Control(s) => write!(f, "{}", s),
    }
  }
}

impl Sequence {
  fn is_char(&self) -> bool {
    matches!(self, Sequence::Char(_))
  }
}

#[derive(Debug, Default, Clone)]
struct Content(Vec<Sequence>);

impl Display for Content {
  fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
    for sequence in &self.0 {
      write!(f, "{}", sequence)?;
    }
    Ok(())
  }
}

impl Content {
  /// Returns an iterator over characters.
  fn chars(&self) -> impl Iterator<Item = char> + '_ {
    self.0.iter().filter_map(|sequence| match sequence {
      Sequence::Char(c) => Some(*c),
      _ => None,
    })
  }

  fn write(&self, f: &mut fmt::Formatter<'_>, max: usize) -> fmt::Result {
    let mut count = 0;
    for sequence in &self.0 {
      write!(f, "{}", sequence)?;
      if sequence.is_char() {
        count += 1;
      }
      if count == max {
        break;
      }
    }
    Ok(())
  }

  fn chr(&mut self, ch: char) {
    self.0.push(Sequence::Char(ch));
  }

  fn str(&mut self, s: &str) {
    for ch in s.chars() {
      self.0.push(Sequence::Char(ch));
    }
  }

  fn str_n(&mut self, s: &str, n: usize) {
    for ch in s.chars().take(n) {
      self.0.push(Sequence::Char(ch));
    }
  }

  fn ctrl(&mut self, s: impl ToString) {
    self.0.push(Sequence::Control(s.to_string()));
  }

  fn append(&mut self, s: &Content) {
    for sequence in &s.0 {
      self.0.push(sequence.clone());
    }
  }

  fn pad(&mut self, ch: char, n: usize) {
    for _ in 0..n {
      self.chr(ch);
    }
  }

  fn fill(&mut self, ch: char, length: usize) {
    for _ in 0..length.saturating_sub(self.chars().count()) {
      self.0.push(Sequence::Char(ch));
    }
  }
}

/// Styled text.
#[derive(Debug, Clone)]
pub struct Text {
  /// Color mode.
  cm: ColorMode,
  /// Text content.
  content: Content,
}

impl Display for Text {
  fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
    if let Some(width) = f.width() {
      let fill = width.saturating_sub(self.content.chars().count());
      let ch = f.fill().to_string();
      if let Some(align) = f.align() {
        match align {
          Alignment::Left => {
            self.content.write(f, width)?;
            write!(f, "{}", ch.repeat(fill))?;
          }
          Alignment::Right => {
            write!(f, "{}", ch.repeat(fill))?;
            self.content.write(f, width)?;
          }
          Alignment::Center => {
            let left_fill = fill / 2;
            write!(f, "{}", ch.repeat(left_fill))?;
            self.content.write(f, width)?;
            write!(f, "{}", ch.repeat(fill - left_fill))?;
          }
        }
      } else {
        self.content.write(f, width)?;
        write!(f, "{}", ch.repeat(fill))?;
      }
    } else {
      write!(f, "{}", self.content)?;
    }
    Ok(())
  }
}

impl Default for Text {
  fn default() -> Self {
    Self::new(ColorMode::default())
  }
}

impl From<ColorMode> for Text {
  fn from(cm: ColorMode) -> Self {
    Self::new(cm)
  }
}

impl Text {
  pub fn new(cm: ColorMode) -> Self {
    Self { cm, content: Default::default() }
  }

  pub fn auto() -> Self {
    Self {
      cm: ColorMode::default(),
      content: Default::default(),
    }
  }

  pub fn on() -> Self {
    Self {
      cm: ColorMode::On,
      content: Default::default(),
    }
  }

  pub fn off() -> Self {
    Self {
      cm: ColorMode::Off,
      content: Default::default(),
    }
  }

  /// Returns an iterator over characters in text.
  pub fn chars(&self) -> impl Iterator<Item = char> + '_ {
    self.content.chars()
  }

  /// Returns the number of characters in text.
  pub fn count(&self) -> usize {
    self.chars().count()
  }
}

impl StyledText for Text {
  fn s<T: Display>(mut self, s: T) -> Self {
    self.content.str(&format!("{}", s));
    self
  }

  fn reset(mut self) -> Self {
    self.content.ctrl(self.cm.reset());
    self
  }

  fn repeat<T: Display>(self, s: T, n: usize) -> Self {
    self.s(s.to_string().repeat(n))
  }

  fn plural<T: Display>(self, s: T, n: usize) -> Self {
    if n == 1 { self.s(s) } else { self.s(format!("{}s", s)) }
  }

  fn align_left<T: Display>(self, s: T, width: usize) -> Self {
    self.pad_right(' ', s, width)
  }

  fn align_right<T: Display>(self, s: T, width: usize) -> Self {
    self.pad_left(' ', s, width)
  }

  fn align_center<T: Display>(self, s: T, width: usize) -> Self {
    self.pad_center(' ', s, width)
  }

  fn pad<T: Display>(mut self, ch: char, padding: usize, s: T) -> Self {
    self.content.pad(ch, padding);
    self.content.str(&format!("{}", s));
    self
  }

  fn pad_left<T: Display>(mut self, ch: char, s: T, width: usize) -> Self {
    let buffer = format!("{}", s);
    self.content.pad(ch, width.saturating_sub(buffer.chars().count()));
    self.content.str_n(&buffer, width);
    self
  }

  fn pad_right<T: Display>(mut self, ch: char, s: T, width: usize) -> Self {
    let buffer = format!("{}", s);
    self.content.str_n(&buffer, width);
    self.content.pad(ch, width.saturating_sub(buffer.chars().count()));
    self
  }

  fn pad_center<T: Display>(mut self, ch: char, s: T, width: usize) -> Self {
    let buffer = format!("{}", s);
    let fill = width.saturating_sub(buffer.chars().count());
    let left_fill = fill / 2;
    self.content.pad(ch, left_fill);
    self.content.str_n(&buffer, width);
    self.content.pad(ch, fill - left_fill);
    self
  }

  fn fill(mut self, ch: char, width: usize) -> Self {
    self.content.fill(ch, width);
    self
  }

  fn choose<T: Display>(self, condition: bool, when_true: T, when_false: T) -> Self {
    self.s(if condition { when_true } else { when_false })
  }

  fn indent<T: Display>(self, indent: usize, s: T) -> Self {
    self.pad(' ', indent, s)
  }

  fn bold(mut self) -> Self {
    self.content.ctrl(self.cm.bold());
    self
  }

  fn italic(mut self) -> Self {
    self.content.ctrl(self.cm.italic());
    self
  }

  fn underline(mut self) -> Self {
    self.content.ctrl(self.cm.underline());
    self
  }

  fn black(mut self) -> Self {
    self.content.ctrl(self.cm.black(false));
    self
  }

  fn bright_black(mut self) -> Self {
    self.content.ctrl(self.cm.black(true));
    self
  }

  fn red(mut self) -> Self {
    self.content.ctrl(self.cm.red(false));
    self
  }

  fn bright_red(mut self) -> Self {
    self.content.ctrl(self.cm.red(true));
    self
  }

  fn green(mut self) -> Self {
    self.content.ctrl(self.cm.green(false));
    self
  }

  fn bright_green(mut self) -> Self {
    self.content.ctrl(self.cm.green(true));
    self
  }

  fn yellow(mut self) -> Self {
    self.content.ctrl(self.cm.yellow(false));
    self
  }

  fn bright_yellow(mut self) -> Self {
    self.content.ctrl(self.cm.yellow(true));
    self
  }

  fn blue(mut self) -> Self {
    self.content.ctrl(self.cm.blue(false));
    self
  }

  fn bright_blue(mut self) -> Self {
    self.content.ctrl(self.cm.blue(true));
    self
  }

  fn magenta(mut self) -> Self {
    self.content.ctrl(self.cm.magenta(false));
    self
  }

  fn bright_magenta(mut self) -> Self {
    self.content.ctrl(self.cm.magenta(true));
    self
  }

  fn cyan(mut self) -> Self {
    self.content.ctrl(self.cm.cyan(false));
    self
  }

  fn bright_cyan(mut self) -> Self {
    self.content.ctrl(self.cm.cyan(true));
    self
  }

  fn white(mut self) -> Self {
    self.content.ctrl(self.cm.white(false));
    self
  }

  fn bright_white(mut self) -> Self {
    self.content.ctrl(self.cm.white(true));
    self
  }

  fn bg_black(mut self) -> Self {
    self.content.ctrl(self.cm.bg_black(false));
    self
  }

  fn bg_bright_black(mut self) -> Self {
    self.content.ctrl(self.cm.bg_black(true));
    self
  }

  fn bg_red(mut self) -> Self {
    self.content.ctrl(self.cm.bg_red(false));
    self
  }

  fn bg_bright_red(mut self) -> Self {
    self.content.ctrl(self.cm.bg_red(true));
    self
  }

  fn bg_green(mut self) -> Self {
    self.content.ctrl(self.cm.bg_green(false));
    self
  }

  fn bg_bright_green(mut self) -> Self {
    self.content.ctrl(self.cm.bg_green(true));
    self
  }

  fn bg_yellow(mut self) -> Self {
    self.content.ctrl(self.cm.bg_yellow(false));
    self
  }

  fn bg_bright_yellow(mut self) -> Self {
    self.content.ctrl(self.cm.bg_yellow(true));
    self
  }

  fn bg_blue(mut self) -> Self {
    self.content.ctrl(self.cm.bg_blue(false));
    self
  }

  fn bg_bright_blue(mut self) -> Self {
    self.content.ctrl(self.cm.bg_blue(true));
    self
  }

  fn bg_magenta(mut self) -> Self {
    self.content.ctrl(self.cm.bg_magenta(false));
    self
  }

  fn bg_bright_magenta(mut self) -> Self {
    self.content.ctrl(self.cm.bg_magenta(true));
    self
  }

  fn bg_cyan(mut self) -> Self {
    self.content.ctrl(self.cm.bg_cyan(false));
    self
  }

  fn bg_bright_cyan(mut self) -> Self {
    self.content.ctrl(self.cm.bg_cyan(true));
    self
  }

  fn bg_white(mut self) -> Self {
    self.content.ctrl(self.cm.bg_white(false));
    self
  }

  fn bg_bright_white(mut self) -> Self {
    self.content.ctrl(self.cm.bg_white(true));
    self
  }

  fn color(mut self, c: Color) -> Self {
    self.content.ctrl(self.cm.color(c, false));
    self
  }

  fn bright_color(mut self, c: Color) -> Self {
    self.content.ctrl(self.cm.color(c, true));
    self
  }

  fn bg_color(mut self, c: Color) -> Self {
    self.content.ctrl(self.cm.bg_color(c, false));
    self
  }

  fn bg_bright_color(mut self, c: Color) -> Self {
    self.content.ctrl(self.cm.bg_color(c, true));
    self
  }

  fn color_8(mut self, c: u8) -> Self {
    self.content.ctrl(self.cm.color_8(c, false));
    self
  }

  fn bright_color_8(mut self, c: u8) -> Self {
    self.content.ctrl(self.cm.color_8(c, true));
    self
  }

  fn bg_color_8(mut self, c: u8) -> Self {
    self.content.ctrl(self.cm.bg_color_8(c, false));
    self
  }

  fn bg_bright_color_8(mut self, c: u8) -> Self {
    self.content.ctrl(self.cm.bg_color_8(c, true));
    self
  }

  fn color_256(mut self, c: u8) -> Self {
    self.content.ctrl(self.cm.color_256(c));
    self
  }

  fn bg_color_256(mut self, c: u8) -> Self {
    self.content.ctrl(self.cm.bg_color_256(c));
    self
  }

  fn color_rgb(mut self, c: RgbColor) -> Self {
    self.content.ctrl(self.cm.color_rgb(c));
    self
  }

  fn bg_color_rgb(mut self, c: RgbColor) -> Self {
    self.content.ctrl(self.cm.bg_color_rgb(c));
    self
  }
}

impl AddAssign<Text> for Text {
  fn add_assign(&mut self, rhs: Text) {
    self.content.append(&rhs.content);
  }
}

impl AddAssign<&Text> for Text {
  fn add_assign(&mut self, rhs: &Text) {
    self.content.append(&rhs.content);
  }
}

impl AddAssign<&str> for Text {
  fn add_assign(&mut self, rhs: &str) {
    self.content.str(rhs);
  }
}

impl AddAssign<String> for Text {
  fn add_assign(&mut self, rhs: String) {
    self.content.str(&rhs);
  }
}

impl AddAssign<&String> for Text {
  fn add_assign(&mut self, rhs: &String) {
    self.content.str(rhs);
  }
}

impl AddAssign<char> for Text {
  fn add_assign(&mut self, rhs: char) {
    self.content.str(&rhs.to_string());
  }
}

impl Add<Text> for Text {
  type Output = Text;
  fn add(mut self, rhs: Text) -> Text {
    self += rhs;
    self
  }
}

impl Add<&Text> for Text {
  type Output = Text;
  fn add(mut self, rhs: &Text) -> Text {
    self += rhs;
    self
  }
}

impl Add<&str> for Text {
  type Output = Text;
  fn add(mut self, rhs: &str) -> Text {
    self += rhs;
    self
  }
}

impl Add<String> for Text {
  type Output = Text;
  fn add(mut self, rhs: String) -> Text {
    self += rhs;
    self
  }
}

impl Add<&String> for Text {
  type Output = Text;
  fn add(mut self, rhs: &String) -> Text {
    self += rhs;
    self
  }
}

impl Add<char> for Text {
  type Output = Text;
  fn add(mut self, rhs: char) -> Text {
    self += rhs;
    self
  }
}

impl Add<Text> for &str {
  type Output = Text;
  fn add(self, rhs: Text) -> Text {
    self.add(&rhs)
  }
}

impl Add<&Text> for &str {
  type Output = Text;
  fn add(self, rhs: &Text) -> Text {
    let mut content = Content::default();
    content.str(self);
    content.append(&rhs.content);
    Text { cm: rhs.cm, content }
  }
}

impl Add<Text> for String {
  type Output = Text;
  fn add(self, rhs: Text) -> Text {
    self.add(&rhs)
  }
}

impl Add<&Text> for String {
  type Output = Text;
  fn add(self, rhs: &Text) -> Text {
    let mut content = Content::default();
    content.str(&self);
    content.append(&rhs.content);
    Text { cm: rhs.cm, content }
  }
}

impl Add<Text> for &String {
  type Output = Text;
  fn add(self, rhs: Text) -> Text {
    self.add(&rhs)
  }
}

impl Add<&Text> for &String {
  type Output = Text;
  fn add(self, rhs: &Text) -> Text {
    self.as_str().add(rhs)
  }
}

impl Add<Text> for char {
  type Output = Text;
  fn add(self, rhs: Text) -> Text {
    self.add(&rhs)
  }
}

impl Add<&Text> for char {
  type Output = Text;
  fn add(self, rhs: &Text) -> Text {
    let mut content = Content::default();
    content.chr(self);
    content.append(&rhs.content);
    Text { cm: rhs.cm, content }
  }
}

pub fn auto() -> Text {
  Text::auto()
}

pub fn always() -> Text {
  Text::on()
}

pub fn never() -> Text {
  Text::off()
}