24
24
25
25
/**
26
26
* A ANSI output stream extracts ANSI escape codes written to
27
- * an output stream.
27
+ * an output stream and calls corresponding <code>process*</code> methods.
28
28
*
29
29
* For more information about ANSI escape codes, see:
30
30
* http://en.wikipedia.org/wiki/ANSI_escape_code
31
31
*
32
32
* This class just filters out the escape codes so that they are not
33
- * sent out to the underlying OutputStream. Subclasses should
34
- * actually perform the ANSI escape behaviors.
33
+ * sent out to the underlying OutputStream: <code>process*</code> methods
34
+ * are empty. Subclasses should actually perform the ANSI escape behaviors
35
+ * by implementing active code in <code>process*</code> methods.
35
36
*
36
37
* @author <a href="http://hiramchirino.com">Hiram Chirino</a>
37
38
* @author Joris Kuipers
@@ -407,29 +408,53 @@ private boolean processOperatingSystemCommand(ArrayList<Object> options) throws
407
408
return false ;
408
409
}
409
410
411
+ /**
412
+ * Process <code>CSI u</code> ANSI code, corresponding to <code>RCP – Restore Cursor Position</code>
413
+ * @throws IOException
414
+ */
410
415
protected void processRestoreCursorPosition () throws IOException {
411
416
}
412
417
418
+ /**
419
+ * Process <code>CSI s</code> ANSI code, corresponding to <code>SCP – Save Cursor Position</code>
420
+ * @throws IOException
421
+ */
413
422
protected void processSaveCursorPosition () throws IOException {
414
423
}
415
424
425
+ /**
426
+ * Process <code>CSI n T</code> ANSI code, corresponding to <code>SD – Scroll Down</code>
427
+ * @throws IOException
428
+ */
416
429
protected void processScrollDown (int optionInt ) throws IOException {
417
430
}
418
431
432
+ /**
433
+ * Process <code>CSI n U</code> ANSI code, corresponding to <code>SU – Scroll Up</code>
434
+ * @throws IOException
435
+ */
419
436
protected void processScrollUp (int optionInt ) throws IOException {
420
437
}
421
438
422
439
protected static final int ERASE_SCREEN_TO_END = 0 ;
423
440
protected static final int ERASE_SCREEN_TO_BEGINING = 1 ;
424
441
protected static final int ERASE_SCREEN = 2 ;
425
442
443
+ /**
444
+ * Process <code>CSI n J</code> ANSI code, corresponding to <code>ED – Erase in Display</code>
445
+ * @throws IOException
446
+ */
426
447
protected void processEraseScreen (int eraseOption ) throws IOException {
427
448
}
428
449
429
450
protected static final int ERASE_LINE_TO_END = 0 ;
430
451
protected static final int ERASE_LINE_TO_BEGINING = 1 ;
431
452
protected static final int ERASE_LINE = 2 ;
432
453
454
+ /**
455
+ * Process <code>CSI n K</code> ANSI code, corresponding to <code>ED – Erase in Line</code>
456
+ * @throws IOException
457
+ */
433
458
protected void processEraseLine (int eraseOption ) throws IOException {
434
459
}
435
460
@@ -450,6 +475,20 @@ protected void processEraseLine(int eraseOption) throws IOException {
450
475
protected static final int ATTRIBUTE_NEGATIVE_OFF = 27 ; // Image; Positive
451
476
protected static final int ATTRIBUTE_CONCEAL_OFF = 28 ; // Reveal conceal off
452
477
478
+ /**
479
+ * process <code>SGR</code> other than <code>0</code> (reset), <code>30-39</code> (foreground),
480
+ * <code>40-49</code> (background), <code>90-97</code> (foreground high intensity) or
481
+ * <code>100-107</code> (background high intensity)
482
+ * @param attribute
483
+ * @throws IOException
484
+ * @see #processAttributeRest()
485
+ * @see #processSetForegroundColor(int)
486
+ * @see #processSetForegroundColor(int, boolean)
487
+ * @see #processSetForegroundColorExt(int)
488
+ * @see #processSetForegroundColorExt(int, int, int)
489
+ * @see #processDefaultTextColor()
490
+ * @see #processDefaultBackgroundColor()
491
+ */
453
492
protected void processSetAttribute (int attribute ) throws IOException {
454
493
}
455
494
@@ -462,87 +501,213 @@ protected void processSetAttribute(int attribute) throws IOException {
462
501
protected static final int CYAN = 6 ;
463
502
protected static final int WHITE = 7 ;
464
503
504
+ /**
505
+ * process <code>SGR 30-37</code> corresponding to <code>Set text color (foreground)</code>.
506
+ * @param color the text color
507
+ * @throws IOException
508
+ */
465
509
protected void processSetForegroundColor (int color ) throws IOException {
466
510
processSetForegroundColor (color , false );
467
511
}
468
512
513
+ /**
514
+ * process <code>SGR 30-37</code> or <code>SGR 90-97</code> corresponding to
515
+ * <code>Set text color (foreground)</code> either in normal mode or high intensity.
516
+ * @param color the text color
517
+ * @param bright is high intensity?
518
+ * @throws IOException
519
+ */
469
520
protected void processSetForegroundColor (int color , boolean bright ) throws IOException {
470
521
}
471
522
523
+ /**
524
+ * process <code>SGR 38</code> corresponding to <code>extended set text color (foreground)</code>
525
+ * with a palette of 255 colors.
526
+ * @param paletteIndex the text color in the palette
527
+ * @throws IOException
528
+ */
472
529
protected void processSetForegroundColorExt (int paletteIndex ) throws IOException {
473
530
}
474
531
532
+ /**
533
+ * process <code>SGR 38</code> corresponding to <code>extended set text color (foreground)</code>
534
+ * with a 24 bits RGB definition of the color.
535
+ * @param r red
536
+ * @param g green
537
+ * @param b blue
538
+ * @throws IOException
539
+ */
475
540
protected void processSetForegroundColorExt (int r , int g , int b ) throws IOException {
476
541
}
477
542
543
+ /**
544
+ * process <code>SGR 40-47</code> corresponding to <code>Set background color</code>.
545
+ * @param color the background color
546
+ * @throws IOException
547
+ */
478
548
protected void processSetBackgroundColor (int color ) throws IOException {
479
549
processSetBackgroundColor (color , false );
480
550
}
481
551
552
+ /**
553
+ * process <code>SGR 40-47</code> or <code>SGR 100-107</code> corresponding to
554
+ * <code>Set background color</code> either in normal mode or high intensity.
555
+ * @param color the background color
556
+ * @param bright is high intensity?
557
+ * @throws IOException
558
+ */
482
559
protected void processSetBackgroundColor (int color , boolean bright ) throws IOException {
483
560
}
484
561
562
+ /**
563
+ * process <code>SGR 48</code> corresponding to <code>extended set background color</code>
564
+ * with a palette of 255 colors.
565
+ * @param paletteIndex the background color in the palette
566
+ * @throws IOException
567
+ */
485
568
protected void processSetBackgroundColorExt (int paletteIndex ) throws IOException {
486
569
}
487
570
571
+ /**
572
+ * process <code>SGR 48</code> corresponding to <code>extended set background color</code>
573
+ * with a 24 bits RGB definition of the color.
574
+ * @param r red
575
+ * @param g green
576
+ * @param b blue
577
+ * @throws IOException
578
+ */
488
579
protected void processSetBackgroundColorExt (int r , int g , int b ) throws IOException {
489
580
}
490
581
582
+ /**
583
+ * process <code>SGR 39</code> corresponding to <code>Default text color (foreground)</code>
584
+ * @throws IOException
585
+ */
491
586
protected void processDefaultTextColor () throws IOException {
492
587
}
493
588
589
+ /**
590
+ * process <code>SGR 49</code> corresponding to <code>Default background color</code>
591
+ * @throws IOException
592
+ */
494
593
protected void processDefaultBackgroundColor () throws IOException {
495
594
}
496
595
596
+ /**
597
+ * process <code>SGR 0</code> corresponding to <code>Reset / Normal</code>
598
+ * @throws IOException
599
+ */
497
600
protected void processAttributeRest () throws IOException {
498
601
}
499
602
603
+ /**
604
+ * process <code>CSI n ; m H</code> corresponding to <code>CUP – Cursor Position</code> or
605
+ * <code>CSI n ; m f</code> corresponding to <code>HVP – Horizontal and Vertical Position</code>
606
+ * @param row
607
+ * @param col
608
+ * @throws IOException
609
+ */
500
610
protected void processCursorTo (int row , int col ) throws IOException {
501
611
}
502
612
613
+ /**
614
+ * process <code>CSI n G</code> corresponding to <code>CHA – Cursor Horizontal Absolute</code>
615
+ * @param x the column
616
+ * @throws IOException
617
+ */
503
618
protected void processCursorToColumn (int x ) throws IOException {
504
619
}
505
620
621
+ /**
622
+ * process <code>CSI n F</code> corresponding to <code>CPL – Cursor Previous Line</code>
623
+ * @param count line count
624
+ * @throws IOException
625
+ */
506
626
protected void processCursorUpLine (int count ) throws IOException {
507
627
}
508
628
629
+ /**
630
+ * process <code>CSI n E</code> corresponding to <code>CNL – Cursor Next Line</code>
631
+ * @param count line count
632
+ * @throws IOException
633
+ */
509
634
protected void processCursorDownLine (int count ) throws IOException {
510
635
// Poor mans impl..
511
636
for (int i = 0 ; i < count ; i ++) {
512
637
out .write ('\n' );
513
638
}
514
639
}
515
640
641
+ /**
642
+ * process <code>CSI n D</code> corresponding to <code>CUB – Cursor Back</code>
643
+ * @param count
644
+ * @throws IOException
645
+ */
516
646
protected void processCursorLeft (int count ) throws IOException {
517
647
}
518
648
649
+ /**
650
+ * process <code>CSI n C</code> corresponding to <code>CUF – Cursor Forward</code>
651
+ * @param count
652
+ * @throws IOException
653
+ */
519
654
protected void processCursorRight (int count ) throws IOException {
520
655
// Poor mans impl..
521
656
for (int i = 0 ; i < count ; i ++) {
522
657
out .write (' ' );
523
658
}
524
659
}
525
660
661
+ /**
662
+ * process <code>CSI n B</code> corresponding to <code>CUD – Cursor Down</code>
663
+ * @param count
664
+ * @throws IOException
665
+ */
526
666
protected void processCursorDown (int count ) throws IOException {
527
667
}
528
668
669
+ /**
670
+ * process <code>CSI n A</code> corresponding to <code>CUU – Cursor Up</code>
671
+ * @param count
672
+ * @throws IOException
673
+ */
529
674
protected void processCursorUp (int count ) throws IOException {
530
675
}
531
676
532
677
protected void processUnknownExtension (ArrayList <Object > options , int command ) {
533
678
}
534
679
680
+ /**
681
+ * process <code>OSC 0;text BEL</code> corresponding to <code>Change Window and Icon label</code>
682
+ * @param label
683
+ * @throws IOException
684
+ */
535
685
protected void processChangeIconNameAndWindowTitle (String label ) {
536
686
processChangeIconName (label );
537
687
processChangeWindowTitle (label );
538
688
}
539
689
690
+ /**
691
+ * process <code>OSC 1;text BEL</code> corresponding to <code>Change Icon label</code>
692
+ * @param label
693
+ * @throws IOException
694
+ */
540
695
protected void processChangeIconName (String label ) {
541
696
}
542
697
698
+ /**
699
+ * process <code>OSC 2;text BEL</code> corresponding to <code>Change Window title</code>
700
+ * @param label
701
+ * @throws IOException
702
+ */
543
703
protected void processChangeWindowTitle (String label ) {
544
704
}
545
705
706
+ /**
707
+ * Process unknown <code>OSC</code> command.
708
+ * @param command
709
+ * @param param
710
+ */
546
711
protected void processUnknownOperatingSystemCommand (int command , String param ) {
547
712
}
548
713
0 commit comments