Skip to content

Commit ff81b78

Browse files
committed
Fix console coloring
1 parent effdebc commit ff81b78

4 files changed

Lines changed: 52 additions & 27 deletions

File tree

sql_profiler/Code/Lexer/YukonLexer.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ public string SyntaxHighlight(OutputWriter sb, string value)
7777
{
7878
Line = value;
7979

80+
sb.AppendLine();
81+
8082
System.Collections.Generic.List<TokenKind> lsTokenTypeHistory =
8183
new System.Collections.Generic.List<TokenKind>();
8284

@@ -140,12 +142,11 @@ public string SyntaxHighlight(OutputWriter sb, string value)
140142

141143
sb.AppendLine();
142144
sb.AppendLine();
143-
string lol = sb.ToString();
144-
145+
145146
lsTokenTypeHistory.Clear();
146147
lsTokenTypeHistory = null;
147148

148-
return lol;
149+
return sb.ToString();
149150
}
150151

151152
private string Line

sql_profiler/Code/OutputWriter/ConsoleOutputWriter.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public override System.Drawing.Color BackColor
8282
{
8383
// if (!s_colorDict.ContainsKey(value)) System.Console.WriteLine(value);
8484
System.Console.BackgroundColor = s_colorDict[value];
85-
this.AppendLine();
85+
//this.AppendLine();
8686
}
8787
}
8888

@@ -91,7 +91,9 @@ public override void AppendLine()
9191
{
9292
// Finish the line with empty color
9393
System.Console.Write(new string(' ', System.Console.BufferWidth - System.Console.CursorLeft));
94-
System.Console.Write(System.Environment.NewLine);
94+
95+
if(!s_isWindows)
96+
System.Console.Write(System.Environment.NewLine);
9597
//else System.Console.WriteLine();
9698
}
9799

sql_profiler/Code/SqlServerProfiler.cs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ protected enum ProfilingStateEnum { psStopped, psProfiling, psPaused }
1818
protected System.Collections.Concurrent.ConcurrentQueue<ProfilerEvent> m_events;
1919
protected readonly System.Collections.Generic.List<PerfColumn> m_columns;
2020
protected readonly YukonLexer m_Lex;
21-
22-
21+
protected readonly bool m_isWindows;
22+
23+
2324
protected readonly ProfilerEvent m_EventStarted = new ProfilerEvent();
2425
protected readonly ProfilerEvent m_EventStopped = new ProfilerEvent();
2526
protected readonly ProfilerEvent m_EventPaused = new ProfilerEvent();
@@ -54,11 +55,11 @@ public SqlServerProfiler(string server, string database
5455
this.m_password = password;
5556
this.m_integrated_security = string.IsNullOrWhiteSpace(username);
5657

57-
bool isWindows = System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(
58+
this.m_isWindows = System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(
5859
System.Runtime.InteropServices.OSPlatform.Windows
5960
);
6061

61-
if (this.m_integrated_security && !isWindows)
62+
if (this.m_integrated_security && !this.m_isWindows)
6263
{
6364
throw new System.ArgumentException($"Username is NULL or empty. Cannot use integrated-security on non-windows platform.");
6465
}
@@ -399,8 +400,12 @@ protected void NewEventArrived(ProfilerEvent evt, bool last)
399400
string caption = GetEventCaption(evt);
400401
System.Console.Write(caption);
401402
System.Console.Write(new string(' ', System.Console.BufferWidth - System.Console.CursorLeft));
402-
System.Console.Write(System.Environment.NewLine);
403+
404+
if(!this.m_isWindows)
405+
System.Console.Write(System.Environment.NewLine);
403406

407+
408+
404409
string td = evt.GetFormattedData(ProfilerEventColumns.TextData, null);
405410
// System.Console.WriteLine(td);
406411

@@ -417,9 +422,12 @@ protected void NewEventArrived(ProfilerEvent evt, bool last)
417422
};
418423

419424

420-
// var lex = new YukonLexer(); lex.SyntaxHighlight(cw, td);
421-
this.m_Lex.SyntaxHighlight(cw, td);
422-
// rich.Rtf = this.m_Lex.SyntaxHighlight(rb, td);
425+
if (!string.IsNullOrEmpty(td))
426+
{
427+
// var lex = new YukonLexer(); lex.SyntaxHighlight(cw, td);
428+
this.m_Lex.SyntaxHighlight(cw, td);
429+
// rich.Rtf = this.m_Lex.SyntaxHighlight(rb, td);
430+
}
423431

424432
// for(int i = 0; i < 65; ++i) // 65 is size of array
425433
// System.Console.WriteLine(evt.GetFormattedData(i, null));

sql_profiler/Program.cs

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -280,23 +280,31 @@ public static string GetPlatformDefaultInstance()
280280

281281
static void Main(string[] args)
282282
{
283-
// MainTest(args);
284-
DoProfiling(args);
283+
MainTest(args);
284+
// DoProfiling(args);
285285
}
286-
287-
286+
287+
288288
static void MainTest(string[] args)
289289
{
290290
string instance = GetPlatformDefaultInstance();
291291
// dotnet run --server localhost --username MY_USER --password MY_PASSWORD --db MY_DB
292292
// string ar = $"--server {instance} --username WebAppWebServices --password TOP_SECRET --Db COR_Basic_Demo_V4";
293-
// string ar = $"--server {instance} /db \"COR_Basic_Demo_V4\"";
294-
295-
string un = TestPlotly.SecretManager.GetSecret<string>("DefaultDbUser");
296-
string pw = TestPlotly.SecretManager.GetSecret<string>("DefaultDbPassword");
297-
298-
string ar = $"--server {instance} --username {un} --password {pw} --db \"Redmine\"";
299-
293+
294+
string ar = $"--server {instance} /db \"COR_Basic_Demo_V4\"";
295+
ar = $"--server {instance} /db \"SwissRe_Test_V4\"";
296+
297+
bool isWindows = System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(
298+
System.Runtime.InteropServices.OSPlatform.Windows
299+
);
300+
301+
if(!isWindows)
302+
{
303+
string un = TestPlotly.SecretManager.GetSecret<string>("DefaultDbUser");
304+
string pw = TestPlotly.SecretManager.GetSecret<string>("DefaultDbPassword");
305+
ar = $"--server {instance} --username {un} --password {pw} --db \"Redmine\"";
306+
}
307+
300308
DoProfiling(ar.Split(' '));
301309
} // End Sub Main
302310

@@ -360,8 +368,10 @@ static void DoProfiling(string[] args)
360368
s_profiler = new ExpressProfiler.SqlServerProfiler(server, db, username, password);
361369

362370
s_profiler.StartProfiling();
363-
364-
371+
372+
373+
System.Console.ResetColor();
374+
365375
// System.Console.WriteLine("--- Press ENTER to stop profiling --- ");
366376
// System.Console.ReadLine();
367377

@@ -383,8 +393,12 @@ static void DoProfiling(string[] args)
383393
]
384394
private static void OnExit()
385395
{
386-
if(s_profiler != null) // Is there any chance this could happen ?
396+
System.Console.ResetColor();
397+
398+
if (s_profiler != null) // Is there any chance this could happen ?
387399
s_profiler.StopProfiling();
400+
401+
System.Console.ResetColor();
388402
} // End Sub OnExit
389403

390404

0 commit comments

Comments
 (0)