Skip to content

Commit f3b585a

Browse files
committed
v1.6.0 bugfixes for default values of ConsoleOptions and ScreenColorOptions.
1 parent 5b0da01 commit f3b585a

File tree

5 files changed

+48
-26
lines changed

5 files changed

+48
-26
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
* `Beep(Melody melody)` was checking `Melody` elements with checking duration of beeping and duration of waiting as not being lower than zero. Now it is checking with equal or lower than zero as it should be.
2121
* `Sleep(int duration)` now only waits instead of writing sleeping duration into screen.
2222

23+
#### Fixed
24+
* Several features were not working due to default values of `ConsoleOptions` and `ScreenColorOptions`. Features like `WriteLine()` or `StartingMethod()` now can be used without calling `StartUp()`.
25+
2326
### [1.5.0]
2427
#### Added
2528
* `Write<T>(T value, ConsoleColor color, Melody melody)` method is added. You can call it to write colorful text with beeping.

HelpConsole/HelpConsole.cs

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,36 @@
22

33
namespace HelpConsole
44
{
5+
public partial class HelpConsole
6+
{
7+
private readonly static string s_defaultAppName = "HelpConsole";
8+
private readonly static bool s_defaultCursorVisible = false;
9+
private readonly static ScreenColorOption s_defaultScreenColorOption = new ScreenColorOption(foregroundColor: Green, backgroundColor: Black);
10+
private readonly static bool s_defaultWaitOnEnd = true;
11+
private readonly static bool s_defaultWarningSound = false;
12+
13+
private readonly static ConsoleOption s_defaultConsoleOption = new ConsoleOption
14+
{
15+
AppName = s_defaultAppName,
16+
CursorVisible = s_defaultCursorVisible,
17+
ScreenColorOption = s_defaultScreenColorOption,
18+
WaitOnEnd = s_defaultWaitOnEnd,
19+
WarningSound = s_defaultWarningSound
20+
};
21+
}
22+
523
/// <summary>
624
///
725
/// </summary>
826
public partial class HelpConsole
927
{
1028
// Console Option
11-
internal static ConsoleOption s_consoleOptions;
29+
internal static ConsoleOption s_currentConsoleOptions;
1230

1331
/// <summary>
1432
/// Set and holds console options.
1533
/// </summary>
16-
public static ConsoleOption ConsoleOptions { get => s_consoleOptions; set => s_consoleOptions = value; }
34+
public static ConsoleOption ConsoleOptions { get => s_currentConsoleOptions ?? s_defaultConsoleOption; set => s_currentConsoleOptions = value; }
1735

1836
/// <summary>
1937
/// Settings for console.
@@ -23,27 +41,27 @@ public class ConsoleOption
2341
/// <summary>
2442
/// Application name
2543
/// </summary>
26-
public string AppName = "HelpConsole";
44+
public string AppName = s_defaultAppName;
2745

2846
/// <summary>
29-
/// Screen color option. It has foreground and background color individually.
47+
/// Sets whether cursor is visible or not.
3048
/// </summary>
31-
public ScreenColorOption ScreenColorOption = s_defaultScreenColorOption;
49+
public bool CursorVisible = s_defaultCursorVisible;
3250

3351
/// <summary>
34-
/// Sets whether cursor is visible or not.
52+
/// Screen color option. It has foreground and background color individually.
3553
/// </summary>
36-
public bool CursorVisible = false;
54+
public ScreenColorOption ScreenColorOption = s_currentScreenColorOption ?? s_defaultScreenColorOption;
3755

3856
/// <summary>
39-
/// Sets warning beep.
57+
/// Sets whether application should wait end or not.
4058
/// </summary>
41-
public bool WarningSound = false;
59+
public bool WaitOnEnd = s_defaultWaitOnEnd;
4260

4361
/// <summary>
44-
/// Sets whether application should wait end or not.
62+
/// Sets warning beep.
4563
/// </summary>
46-
public bool WaitOnEnd = true;
64+
public bool WarningSound = s_defaultWarningSound;
4765
}
4866
}
4967

@@ -69,7 +87,7 @@ public static void StartUp(ConsoleOption consoleOptions = null)
6987
if (consoleOptions == null)
7088
{
7189
// Sets parameter variable with default constructor.
72-
consoleOptions = new ConsoleOption { AppName = "HelpConsole", ScreenColorOption = new ScreenColorOption(foregroundColor: White, backgroundColor: Black), CursorVisible = false, WarningSound = false, WaitOnEnd = true };
90+
consoleOptions = s_defaultConsoleOption;
7391
}
7492

7593
// Set console title with default value.
@@ -111,14 +129,14 @@ public static void FinishUp()
111129
WriteLine("Done...");
112130

113131
// Beep sound.
114-
if (s_consoleOptions.WarningSound)
132+
if (ConsoleOptions.WarningSound)
115133
{
116134
// Beeping.
117135
Beep(s_finishUpMelody);
118136
}
119137

120138
// Checking if WaitOnEnd is true.
121-
if (s_consoleOptions.WaitOnEnd)
139+
if (ConsoleOptions.WaitOnEnd)
122140
{
123141
// Waiting for a key.
124142
_ = Console.ReadKey();

HelpConsole/HelpConsole.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* Beep(Melody melody) was checking Melody elements with checking duration of beeping and duration of waiting as not being lower than zero. Now it is checking with equal or lower than zero as it should be.
1919
* SleepWithTitle(int duration) method added instead of Sleep(int duration). It writes sleeping duration into Console's title.
2020
* Sleep(int duration) now only waits instead of writing sleeping duration into screen.
21+
* Several features were not working due to default values of ConsoleOptions and ScreenColorOptions. Features like WriteLine() or StartingMethod() now can be used without calling `StartUp()`.
2122
See changelog (https://github.com/meokullu/HelpConsole/blob/master/CHANGELOG.md)
2223
</PackageReleaseNotes>
2324
<RepositoryUrl>https://github.com/meokullu/HelpConsole</RepositoryUrl>

HelpConsole/src/Method.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public static void StartingMethod([CallerMemberName] string memberName = "")
5353
WriteLine($"{memberName} started...");
5454

5555
// Checks if warning sound is active.
56-
if (s_consoleOptions.WarningSound)
56+
if (ConsoleOptions.WarningSound)
5757
{
5858
// Beep sounds
5959
Beep(s_startMethodMelody);
@@ -71,7 +71,7 @@ public static void StartingMethod(ConsoleColor consoleColor, [CallerMemberName]
7171
WriteLine($"{memberName} started...", color: consoleColor);
7272

7373
// Checks if warning sound is active.
74-
if (s_consoleOptions.WarningSound)
74+
if (ConsoleOptions.WarningSound)
7575
{
7676
// Beep sounds
7777
Beep(s_startMethodMelody);
@@ -89,7 +89,7 @@ public static void StartingMethod(Melody melody, [CallerMemberName] string membe
8989
WriteLine($"{memberName} started...");
9090

9191
// Checks if warning sound is active.
92-
if (s_consoleOptions.WarningSound)
92+
if (ConsoleOptions.WarningSound)
9393
{
9494
// Beep sounds
9595
Beep(melody: melody);
@@ -108,7 +108,7 @@ public static void StartingMethod(ConsoleColor consoleColor, Melody melody, [Cal
108108
WriteLine($"{memberName} started...", color: consoleColor);
109109

110110
// Checks if warning sound is active.
111-
if (s_consoleOptions.WarningSound)
111+
if (ConsoleOptions.WarningSound)
112112
{
113113
// Beep sounds
114114
Beep(melody: melody);
@@ -126,7 +126,7 @@ public static void EndingMethod([CallerMemberName] string memberName = "")
126126
WriteLine($"{memberName} ended...");
127127

128128
// Checks if warning sound is active.
129-
if (s_consoleOptions.WarningSound)
129+
if (ConsoleOptions.WarningSound)
130130
{
131131
// Beep sounds.
132132
Beep(s_endMethodMelody);
@@ -144,7 +144,7 @@ public static void EndingMethod(ConsoleColor consoleColor, [CallerMemberName] st
144144
WriteLine($"{memberName} ended...", color: consoleColor);
145145

146146
// Checks if warning sound is active.
147-
if (s_consoleOptions.WarningSound)
147+
if (ConsoleOptions.WarningSound)
148148
{
149149
// Beep sounds.
150150
Beep(s_endMethodMelody);
@@ -162,7 +162,7 @@ public static void EndingMethod(Melody melody, [CallerMemberName] string memberN
162162
WriteLine($"{memberName} ended...");
163163

164164
// Checks if warning sound is active.
165-
if (s_consoleOptions.WarningSound)
165+
if (ConsoleOptions.WarningSound)
166166
{
167167
// Beep sounds
168168
Beep(melody: melody);
@@ -181,7 +181,7 @@ public static void EndingMethod(ConsoleColor consoleColor, Melody melody, [Calle
181181
WriteLine($"{memberName} ended...", color: consoleColor);
182182

183183
// Checks if warning sound is active.
184-
if (s_consoleOptions.WarningSound)
184+
if (ConsoleOptions.WarningSound)
185185
{
186186
// Beep sounds.
187187
Beep(melody: melody);

HelpConsole/src/ScreenColorOption.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ namespace HelpConsole
55
public partial class HelpConsole
66
{
77
// Screen Color Option.
8-
internal static ScreenColorOption s_defaultScreenColorOption;
8+
internal static ScreenColorOption s_currentScreenColorOption;
99

1010
/// <summary>
1111
/// Set and holds screen color options.
1212
/// </summary>
13-
public static ScreenColorOption ScreenColorOptions { get => s_defaultScreenColorOption; set => s_defaultScreenColorOption = value; }
13+
public static ScreenColorOption ScreenColorOptions { get => s_currentScreenColorOption ?? s_defaultScreenColorOption; set => s_currentScreenColorOption = value; }
1414

1515
/// <summary>
1616
/// Preset black for background, yellow for foreground.
@@ -40,12 +40,12 @@ public class ScreenColorOption
4040
/// <summary>
4141
/// Sets foreground color for text.
4242
/// </summary>
43-
public ConsoleColor ForegroundColor = ConsoleColor.Black;
43+
public ConsoleColor ForegroundColor = Green;
4444

4545
/// <summary>
4646
/// Sets background color for background.
4747
/// </summary>
48-
public ConsoleColor BackgroundColor = ConsoleColor.White;
48+
public ConsoleColor BackgroundColor = Black;
4949

5050
/// <summary>
5151
/// Sets ScreenColorOption.

0 commit comments

Comments
 (0)