@@ -411,25 +411,25 @@ public static string GetC1ControlChar (in char c)
411
411
{
412
412
// These control characters are used in the vtXXX emulation.
413
413
return c switch
414
- {
415
- 'D' => "IND" , // Index
416
- 'E' => "NEL" , // Next Line
417
- 'H' => "HTS" , // Tab Set
418
- 'M' => "RI" , // Reverse Index
419
- 'N' => "SS2" , // Single Shift Select of G2 Character Set: affects next character only
420
- 'O' => "SS3" , // Single Shift Select of G3 Character Set: affects next character only
421
- 'P' => "DCS" , // Device Control String
422
- 'V' => "SPA" , // Start of Guarded Area
423
- 'W' => "EPA" , // End of Guarded Area
424
- 'X' => "SOS" , // Start of String
425
- 'Z' => "DECID" , // Return Terminal ID Obsolete form of CSI c (DA)
426
- '[' => "CSI" , // Control Sequence Introducer
427
- '\\ ' => "ST" , // String Terminator
428
- ']' => "OSC" , // Operating System Command
429
- '^' => "PM" , // Privacy Message
430
- '_' => "APC" , // Application Program Command
431
- _ => string . Empty
432
- } ;
414
+ {
415
+ 'D' => "IND" , // Index
416
+ 'E' => "NEL" , // Next Line
417
+ 'H' => "HTS" , // Tab Set
418
+ 'M' => "RI" , // Reverse Index
419
+ 'N' => "SS2" , // Single Shift Select of G2 Character Set: affects next character only
420
+ 'O' => "SS3" , // Single Shift Select of G3 Character Set: affects next character only
421
+ 'P' => "DCS" , // Device Control String
422
+ 'V' => "SPA" , // Start of Guarded Area
423
+ 'W' => "EPA" , // End of Guarded Area
424
+ 'X' => "SOS" , // Start of String
425
+ 'Z' => "DECID" , // Return Terminal ID Obsolete form of CSI c (DA)
426
+ '[' => "CSI" , // Control Sequence Introducer
427
+ '\\ ' => "ST" , // String Terminator
428
+ ']' => "OSC" , // Operating System Command
429
+ '^' => "PM" , // Privacy Message
430
+ '_' => "APC" , // Application Program Command
431
+ _ => string . Empty
432
+ } ;
433
433
}
434
434
435
435
@@ -462,46 +462,46 @@ public static ConsoleKey GetConsoleKey (char terminator, string? value, ref Cons
462
462
}
463
463
464
464
return ( terminator , value ) switch
465
- {
466
- ( 'A' , _ ) => ConsoleKey . UpArrow ,
467
- ( 'B' , _ ) => ConsoleKey . DownArrow ,
468
- ( 'C' , _ ) => ConsoleKey . RightArrow ,
469
- ( 'D' , _ ) => ConsoleKey . LeftArrow ,
470
- ( 'E' , _ ) => ConsoleKey . Clear ,
471
- ( 'F' , _ ) => ConsoleKey . End ,
472
- ( 'H' , _ ) => ConsoleKey . Home ,
473
- ( 'P' , _ ) => ConsoleKey . F1 ,
474
- ( 'Q' , _ ) => ConsoleKey . F2 ,
475
- ( 'R' , _ ) => ConsoleKey . F3 ,
476
- ( 'S' , _ ) => ConsoleKey . F4 ,
477
- ( 'Z' , _ ) => ConsoleKey . Tab ,
478
- ( '~' , "2" ) => ConsoleKey . Insert ,
479
- ( '~' , "3" ) => ConsoleKey . Delete ,
480
- ( '~' , "5" ) => ConsoleKey . PageUp ,
481
- ( '~' , "6" ) => ConsoleKey . PageDown ,
482
- ( '~' , "15" ) => ConsoleKey . F5 ,
483
- ( '~' , "17" ) => ConsoleKey . F6 ,
484
- ( '~' , "18" ) => ConsoleKey . F7 ,
485
- ( '~' , "19" ) => ConsoleKey . F8 ,
486
- ( '~' , "20" ) => ConsoleKey . F9 ,
487
- ( '~' , "21" ) => ConsoleKey . F10 ,
488
- ( '~' , "23" ) => ConsoleKey . F11 ,
489
- ( '~' , "24" ) => ConsoleKey . F12 ,
490
- // These terminators are used by macOS on a numeric keypad without keys modifiers
491
- ( 'l' , null ) => ConsoleKey . Add ,
492
- ( 'm' , null ) => ConsoleKey . Subtract ,
493
- ( 'p' , null ) => ConsoleKey . Insert ,
494
- ( 'q' , null ) => ConsoleKey . End ,
495
- ( 'r' , null ) => ConsoleKey . DownArrow ,
496
- ( 's' , null ) => ConsoleKey . PageDown ,
497
- ( 't' , null ) => ConsoleKey . LeftArrow ,
498
- ( 'u' , null ) => ConsoleKey . Clear ,
499
- ( 'v' , null ) => ConsoleKey . RightArrow ,
500
- ( 'w' , null ) => ConsoleKey . Home ,
501
- ( 'x' , null ) => ConsoleKey . UpArrow ,
502
- ( 'y' , null ) => ConsoleKey . PageUp ,
503
- ( _, _) => 0
504
- } ;
465
+ {
466
+ ( 'A' , _ ) => ConsoleKey . UpArrow ,
467
+ ( 'B' , _ ) => ConsoleKey . DownArrow ,
468
+ ( 'C' , _ ) => ConsoleKey . RightArrow ,
469
+ ( 'D' , _ ) => ConsoleKey . LeftArrow ,
470
+ ( 'E' , _ ) => ConsoleKey . Clear ,
471
+ ( 'F' , _ ) => ConsoleKey . End ,
472
+ ( 'H' , _ ) => ConsoleKey . Home ,
473
+ ( 'P' , _ ) => ConsoleKey . F1 ,
474
+ ( 'Q' , _ ) => ConsoleKey . F2 ,
475
+ ( 'R' , _ ) => ConsoleKey . F3 ,
476
+ ( 'S' , _ ) => ConsoleKey . F4 ,
477
+ ( 'Z' , _ ) => ConsoleKey . Tab ,
478
+ ( '~' , "2" ) => ConsoleKey . Insert ,
479
+ ( '~' , "3" ) => ConsoleKey . Delete ,
480
+ ( '~' , "5" ) => ConsoleKey . PageUp ,
481
+ ( '~' , "6" ) => ConsoleKey . PageDown ,
482
+ ( '~' , "15" ) => ConsoleKey . F5 ,
483
+ ( '~' , "17" ) => ConsoleKey . F6 ,
484
+ ( '~' , "18" ) => ConsoleKey . F7 ,
485
+ ( '~' , "19" ) => ConsoleKey . F8 ,
486
+ ( '~' , "20" ) => ConsoleKey . F9 ,
487
+ ( '~' , "21" ) => ConsoleKey . F10 ,
488
+ ( '~' , "23" ) => ConsoleKey . F11 ,
489
+ ( '~' , "24" ) => ConsoleKey . F12 ,
490
+ // These terminators are used by macOS on a numeric keypad without keys modifiers
491
+ ( 'l' , null ) => ConsoleKey . Add ,
492
+ ( 'm' , null ) => ConsoleKey . Subtract ,
493
+ ( 'p' , null ) => ConsoleKey . Insert ,
494
+ ( 'q' , null ) => ConsoleKey . End ,
495
+ ( 'r' , null ) => ConsoleKey . DownArrow ,
496
+ ( 's' , null ) => ConsoleKey . PageDown ,
497
+ ( 't' , null ) => ConsoleKey . LeftArrow ,
498
+ ( 'u' , null ) => ConsoleKey . Clear ,
499
+ ( 'v' , null ) => ConsoleKey . RightArrow ,
500
+ ( 'w' , null ) => ConsoleKey . Home ,
501
+ ( 'x' , null ) => ConsoleKey . UpArrow ,
502
+ ( 'y' , null ) => ConsoleKey . PageUp ,
503
+ ( _, _) => 0
504
+ } ;
505
505
}
506
506
507
507
/// <summary>
@@ -512,18 +512,18 @@ public static ConsoleKey GetConsoleKey (char terminator, string? value, ref Cons
512
512
public static ConsoleModifiers GetConsoleModifiers ( string ? value )
513
513
{
514
514
return value switch
515
- {
516
- "2" => ConsoleModifiers . Shift ,
517
- "3" => ConsoleModifiers . Alt ,
518
- "4" => ConsoleModifiers . Shift | ConsoleModifiers . Alt ,
519
- "5" => ConsoleModifiers . Control ,
520
- "6" => ConsoleModifiers . Shift | ConsoleModifiers . Control ,
521
- "7" => ConsoleModifiers . Alt | ConsoleModifiers . Control ,
522
- "8" => ConsoleModifiers . Shift | ConsoleModifiers . Alt | ConsoleModifiers . Control ,
523
- _ => 0
524
- } ;
515
+ {
516
+ "2" => ConsoleModifiers . Shift ,
517
+ "3" => ConsoleModifiers . Alt ,
518
+ "4" => ConsoleModifiers . Shift | ConsoleModifiers . Alt ,
519
+ "5" => ConsoleModifiers . Control ,
520
+ "6" => ConsoleModifiers . Shift | ConsoleModifiers . Control ,
521
+ "7" => ConsoleModifiers . Alt | ConsoleModifiers . Control ,
522
+ "8" => ConsoleModifiers . Shift | ConsoleModifiers . Alt | ConsoleModifiers . Control ,
523
+ _ => 0
524
+ } ;
525
525
}
526
- #nullable restore
526
+ #nullable restore
527
527
528
528
/// <summary>
529
529
/// Gets all the needed information about an escape sequence.
@@ -1675,6 +1675,19 @@ public static ConsoleKeyInfo [] ToConsoleKeyInfoArray (string ansi)
1675
1675
/// <returns></returns>
1676
1676
public static string CSI_SetCursorPosition ( int row , int col ) { return $ "{ CSI } { row } ;{ col } H"; }
1677
1677
1678
+ /// <summary>
1679
+ /// ESC [ y ; x H - CUP Cursor Position - Cursor moves to x ; y coordinate within the viewport, where x is the column
1680
+ /// of the y line
1681
+ /// </summary>
1682
+ /// <param name="builder">StringBuilder where to append the cursor position sequence.</param>
1683
+ /// <param name="row">Origin is (1,1).</param>
1684
+ /// <param name="col">Origin is (1,1).</param>
1685
+ public static void CSI_AppendCursorPosition ( StringBuilder builder , int row , int col )
1686
+ {
1687
+ // InterpolatedStringHandler is composed in stack, skipping the string allocation.
1688
+ builder . Append ( $ "{ CSI } { row } ;{ col } H") ;
1689
+ }
1690
+
1678
1691
//ESC [ <y> ; <x> f - HVP Horizontal Vertical Position* Cursor moves to<x>; <y> coordinate within the viewport, where <x> is the column of the<y> line
1679
1692
//ESC [ s - ANSISYSSC Save Cursor – Ansi.sys emulation **With no parameters, performs a save cursor operation like DECSC
1680
1693
//ESC [ u - ANSISYSRC Restore Cursor – Ansi.sys emulation **With no parameters, performs a restore cursor operation like DECRC
@@ -1785,11 +1798,29 @@ public enum DECSCUSR_Style
1785
1798
/// </summary>
1786
1799
public static string CSI_SetForegroundColorRGB ( int r , int g , int b ) { return $ "{ CSI } 38;2;{ r } ;{ g } ;{ b } m"; }
1787
1800
1801
+ /// <summary>
1802
+ /// ESC[38;2;{r};{g};{b}m Append foreground color as RGB to StringBuilder.
1803
+ /// </summary>
1804
+ public static void CSI_AppendForegroundColorRGB ( StringBuilder builder , int r , int g , int b )
1805
+ {
1806
+ // InterpolatedStringHandler is composed in stack, skipping the string allocation.
1807
+ builder . Append ( $ "{ CSI } 38;2;{ r } ;{ g } ;{ b } m") ;
1808
+ }
1809
+
1788
1810
/// <summary>
1789
1811
/// ESC[48;2;{r};{g};{b}m Set background color as RGB.
1790
1812
/// </summary>
1791
1813
public static string CSI_SetBackgroundColorRGB ( int r , int g , int b ) { return $ "{ CSI } 48;2;{ r } ;{ g } ;{ b } m"; }
1792
1814
1815
+ /// <summary>
1816
+ /// ESC[48;2;{r};{g};{b}m Append background color as RGB to StringBuilder.
1817
+ /// </summary>
1818
+ public static void CSI_AppendBackgroundColorRGB ( StringBuilder builder , int r , int g , int b )
1819
+ {
1820
+ // InterpolatedStringHandler is composed in stack, skipping the string allocation.
1821
+ builder . Append ( $ "{ CSI } 48;2;{ r } ;{ g } ;{ b } m") ;
1822
+ }
1823
+
1793
1824
#endregion
1794
1825
1795
1826
#region Requests
0 commit comments