Skip to content

Commit ba76a3a

Browse files
switched PUSH/POP codes
The xterm-style SGR push/pop control sequences conflict with C# formatting (due to use of curly brackets), so I'm swapping the curly brackets out for something else ('p' and 'q') for the time being.
1 parent 4351838 commit ba76a3a

File tree

4 files changed

+60
-16
lines changed

4 files changed

+60
-16
lines changed

DbgProvider/internal/AnsiColorWriter.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,22 @@ public AnsiColorWriter()
121121

122122
m_hashCommands = new Dictionary< char, Func< Action< List< int > > > >()
123123
{
124-
{ '{', () => _PushSgr },
125-
{ '}', () => _PopSgr },
124+
// TROUBLE: The current definition of XTPUSHSGR and XTPOPSGR use curly
125+
// brackets, which turns out to conflict badly with C# string formatting.
126+
// For example, this:
127+
//
128+
//
129+
// $csFmt = (New-ColorString).AppendPushFg( 'Cyan' ).Append( 'this should all be cyan: {0}' )
130+
// [string]::format( $csFmt.ToString( $true ), 'blah' )
131+
//
132+
// will blow up.
133+
//
134+
// For now, I'm going to switch to some other characters while we see if
135+
// we get can something worked out with xterm.
136+
//{ '{', () => _PushSgr },
137+
//{ '}', () => _PopSgr },
138+
{ 'p', () => _PushSgr },
139+
{ 'q', () => _PopSgr },
126140
};
127141

128142
m_state = new ControlSequenceParseState( m_commandTreeRoot );

DbgProvider/internal/CaStringUtil.cs

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ private static int _SkipControlSequence( string s, int startIdx )
143143
{
144144
int commandLen = 1;
145145
if( c == '#' )
146-
commandLen = 2; // '#' is the first char of a command like "#{" or "#}"
146+
commandLen = 2; // '#' is the first char of a command like "#p" or "#q"
147147

148148
return curIdx + commandLen; // note that this could be just past the end of the string.
149149
}
@@ -327,7 +327,7 @@ private static void _StripContent( StringBuilder destSb,
327327
destSb.Append( s[ i ] );
328328
if( s[ i ] == '#' )
329329
{
330-
// This is the first char of a two-char command code ("#{" or "#}").
330+
// This is the first char of a two-char command code ("#p" or "#q").
331331
inTwoCharControlSeq = true;
332332
}
333333
else if( !_IsDigitOrSemi( s[ i ] ) )
@@ -582,8 +582,22 @@ public static int ApparentIndexOf( string s, char c )
582582

583583

584584
internal const string SGR = "m"; // SGR: "Select Graphics Rendition"
585-
internal const string PUSH = "#{"; // XTPUSHSGR
586-
internal const string POP = "#}"; // XTPOPSGR
585+
586+
// TROUBLE: The current definition of XTPUSHSGR and XTPOPSGR use curly brackets,
587+
// which turns out to conflict badly with C# string formatting. For example, this:
588+
//
589+
//
590+
// $csFmt = (New-ColorString).AppendPushFg( 'Cyan' ).Append( 'this should all be cyan: {0}' )
591+
// [string]::format( $csFmt.ToString( $true ), 'blah' )
592+
//
593+
// will blow up.
594+
//
595+
// For now, I'm going to switch to some other characters while we see if we get
596+
// can something worked out with xterm.
597+
//internal const string PUSH = "#{"; // XTPUSHSGR
598+
//internal const string POP = "#}"; // XTPOPSGR
599+
internal const string PUSH = "#p"; // NOT XTPUSHSGR
600+
internal const string POP = "#q"; // NOT XTPOPSGR
587601

588602
// public static string FG( ConsoleColor foreground )
589603
// {
@@ -715,8 +729,8 @@ public enum IndentAndWrapOptions
715729
// leading space is longer than the entire outputWidth
716730
}
717731

718-
private const string c_PushAndReset = "\u009b#{\u009b0m";
719-
private const string c_StandalonePop = "\u009b#}";
732+
private const string c_PushAndReset = "\u009b#p\u009b0m";
733+
private const string c_StandalonePop = "\u009b#q";
720734

721735
public static string IndentAndWrap( string str,
722736
int outputWidth,
@@ -1272,9 +1286,9 @@ public CaStringUtilIndentAndWrapTestCase( string input,
12721286
0 ),
12731287
new CaStringUtilLengthTestCase( "\u009bm",
12741288
0 ),
1275-
new CaStringUtilLengthTestCase( "\u009b#{",
1289+
new CaStringUtilLengthTestCase( "\u009b#p",
12761290
0 ),
1277-
new CaStringUtilLengthTestCase( "\u009b#{\u009b91mRED\u009b#}",
1291+
new CaStringUtilLengthTestCase( "\u009b#p\u009b91mRED\u009b#q",
12781292
3 ),
12791293
new CaStringUtilLengthTestCase( "\u009bm123",
12801294
3 ),
@@ -1402,9 +1416,9 @@ public CaStringUtilIndentAndWrapTestCase( string input,
14021416
/* 15 */ new CaStringUtilTruncateTestCase( "\u009bm1234567\u009bm",
14031417
6,
14041418
"\u009bm12345\u009bm…" ),
1405-
/* 16 */ new CaStringUtilTruncateTestCase( "\u009bm1234567\u009b#{", // <-- Note: two-char command code
1419+
/* 16 */ new CaStringUtilTruncateTestCase( "\u009bm1234567\u009b#p", // <-- Note: two-char command code
14061420
6,
1407-
"\u009bm12345\u009b#{…" ),
1421+
"\u009bm12345\u009b#p…" ),
14081422
/* 17 */ new CaStringUtilTruncateTestCase( "",
14091423
1,
14101424
false,

DbgProvider/public/ColorString.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,8 @@ private PushSgrSequence() : base( null )
567567
{
568568
}
569569

570-
protected override string Command { get { return "#{"; } } // "XTPUSHSGR"
570+
//protected override string Command { get { return "#{"; } } // "XTPUSHSGR"
571+
protected override string Command { get { return "#p"; } } // NOT "XTPUSHSGR"
571572

572573
public static readonly PushSgrSequence Instance = new PushSgrSequence();
573574
} // end class PushSgrSequence
@@ -578,7 +579,8 @@ private PopSgrSequence() : base( null )
578579
{
579580
}
580581

581-
protected override string Command { get { return "#}"; } } // "XTPOPSGR"
582+
//protected override string Command { get { return "#}"; } } // "XTPOPSGR"
583+
protected override string Command { get { return "#q"; } } // NOT "XTPOPSGR"
582584

583585
public static readonly PopSgrSequence Instance = new PopSgrSequence();
584586
} // end class PopSgrSequence

DbgShell/ConsoleControl.AnsiColorWriter.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,22 @@ public AnsiColorWriter()
126126

127127
m_hashCommands = new Dictionary< char, Func< Action< List< int > > > >()
128128
{
129-
{ '{', () => _PushSgr },
130-
{ '}', () => _PopSgr },
129+
// TROUBLE: The current definition of XTPUSHSGR and XTPOPSGR use curly
130+
// brackets, which turns out to conflict badly with C# string formatting.
131+
// For example, this:
132+
//
133+
//
134+
// $csFmt = (New-ColorString).AppendPushFg( 'Cyan' ).Append( 'this should all be cyan: {0}' )
135+
// [string]::format( $csFmt.ToString( $true ), 'blah' )
136+
//
137+
// will blow up.
138+
//
139+
// For now, I'm going to switch to some other characters while we see if
140+
// we get can something worked out with xterm.
141+
//{ '{', () => _PushSgr },
142+
//{ '}', () => _PopSgr },
143+
{ 'p', () => _PushSgr },
144+
{ 'q', () => _PopSgr },
131145
};
132146

133147
m_state = new ControlSequenceParseState( m_commandTreeRoot );

0 commit comments

Comments
 (0)