Skip to content

Commit

Permalink
switched PUSH/POP codes
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jazzdelightsme committed May 8, 2019
1 parent 4351838 commit ba76a3a
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 16 deletions.
18 changes: 16 additions & 2 deletions DbgProvider/internal/AnsiColorWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,22 @@ public AnsiColorWriter()

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

m_state = new ControlSequenceParseState( m_commandTreeRoot );
Expand Down
34 changes: 24 additions & 10 deletions DbgProvider/internal/CaStringUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ private static int _SkipControlSequence( string s, int startIdx )
{
int commandLen = 1;
if( c == '#' )
commandLen = 2; // '#' is the first char of a command like "#{" or "#}"
commandLen = 2; // '#' is the first char of a command like "#p" or "#q"

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


internal const string SGR = "m"; // SGR: "Select Graphics Rendition"
internal const string PUSH = "#{"; // XTPUSHSGR
internal const string POP = "#}"; // XTPOPSGR

// TROUBLE: The current definition of XTPUSHSGR and XTPOPSGR use curly brackets,
// which turns out to conflict badly with C# string formatting. For example, this:
//
//
// $csFmt = (New-ColorString).AppendPushFg( 'Cyan' ).Append( 'this should all be cyan: {0}' )
// [string]::format( $csFmt.ToString( $true ), 'blah' )
//
// will blow up.
//
// For now, I'm going to switch to some other characters while we see if we get
// can something worked out with xterm.
//internal const string PUSH = "#{"; // XTPUSHSGR
//internal const string POP = "#}"; // XTPOPSGR
internal const string PUSH = "#p"; // NOT XTPUSHSGR
internal const string POP = "#q"; // NOT XTPOPSGR

// public static string FG( ConsoleColor foreground )
// {
Expand Down Expand Up @@ -715,8 +729,8 @@ public enum IndentAndWrapOptions
// leading space is longer than the entire outputWidth
}

private const string c_PushAndReset = "\u009b#{\u009b0m";
private const string c_StandalonePop = "\u009b#}";
private const string c_PushAndReset = "\u009b#p\u009b0m";
private const string c_StandalonePop = "\u009b#q";

public static string IndentAndWrap( string str,
int outputWidth,
Expand Down Expand Up @@ -1272,9 +1286,9 @@ public CaStringUtilIndentAndWrapTestCase( string input,
0 ),
new CaStringUtilLengthTestCase( "\u009bm",
0 ),
new CaStringUtilLengthTestCase( "\u009b#{",
new CaStringUtilLengthTestCase( "\u009b#p",
0 ),
new CaStringUtilLengthTestCase( "\u009b#{\u009b91mRED\u009b#}",
new CaStringUtilLengthTestCase( "\u009b#p\u009b91mRED\u009b#q",
3 ),
new CaStringUtilLengthTestCase( "\u009bm123",
3 ),
Expand Down Expand Up @@ -1402,9 +1416,9 @@ public CaStringUtilIndentAndWrapTestCase( string input,
/* 15 */ new CaStringUtilTruncateTestCase( "\u009bm1234567\u009bm",
6,
"\u009bm12345\u009bm…" ),
/* 16 */ new CaStringUtilTruncateTestCase( "\u009bm1234567\u009b#{", // <-- Note: two-char command code
/* 16 */ new CaStringUtilTruncateTestCase( "\u009bm1234567\u009b#p", // <-- Note: two-char command code
6,
"\u009bm12345\u009b#{…" ),
"\u009bm12345\u009b#p…" ),
/* 17 */ new CaStringUtilTruncateTestCase( "",
1,
false,
Expand Down
6 changes: 4 additions & 2 deletions DbgProvider/public/ColorString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,8 @@ private PushSgrSequence() : base( null )
{
}

protected override string Command { get { return "#{"; } } // "XTPUSHSGR"
//protected override string Command { get { return "#{"; } } // "XTPUSHSGR"
protected override string Command { get { return "#p"; } } // NOT "XTPUSHSGR"

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

protected override string Command { get { return "#}"; } } // "XTPOPSGR"
//protected override string Command { get { return "#}"; } } // "XTPOPSGR"
protected override string Command { get { return "#q"; } } // NOT "XTPOPSGR"

public static readonly PopSgrSequence Instance = new PopSgrSequence();
} // end class PopSgrSequence
Expand Down
18 changes: 16 additions & 2 deletions DbgShell/ConsoleControl.AnsiColorWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,22 @@ public AnsiColorWriter()

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

m_state = new ControlSequenceParseState( m_commandTreeRoot );
Expand Down

0 comments on commit ba76a3a

Please sign in to comment.