Skip to content

Commit fbd9ea3

Browse files
authored
Merge pull request #42 from meokullu/buxfix_0001
Buxfix 0001
2 parents 0e63965 + f3b585a commit fbd9ea3

File tree

8 files changed

+106
-62
lines changed

8 files changed

+106
-62
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,18 @@
1111
#### Removed
1212
-->
1313

14+
### [1.6.0]
15+
16+
#### Added
17+
* `SleepWithTitle(int duration)` method added instead of `Sleep(int duration)`. It writes sleeping duration into Console's title.
18+
19+
#### Changed
20+
* `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.
21+
* `Sleep(int duration)` now only waits instead of writing sleeping duration into screen.
22+
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+
1426
### [1.5.0]
1527
#### Added
1628
* `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: 33 additions & 15 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,17 +129,17 @@ 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.
124-
Console.ReadKey();
142+
_ = Console.ReadKey();
125143
}
126144
}
127145
}

HelpConsole/HelpConsole.csproj

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
<PropertyGroup>
44
<TargetFrameworks>net6.0; net7.0; net461; netcoreapp3.1; netstandard2.0</TargetFrameworks>
55
<ImplicitUsings>disable</ImplicitUsings>
6-
<FileVersion>1.5.0</FileVersion>
7-
<AssemblyVersion>1.5.0</AssemblyVersion>
8-
<Version>1.5.0</Version>
6+
<FileVersion>1.6.0</FileVersion>
7+
<AssemblyVersion>1.6.0</AssemblyVersion>
8+
<Version>1.6.0</Version>
99
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
1010
<GenerateDocumentationFile>True</GenerateDocumentationFile>
1111
<Title>Help Console</Title>
@@ -14,10 +14,11 @@
1414
<Copyright>Enes Okullu</Copyright>
1515
<PackageTags>console; console-application; console-app; helper</PackageTags>
1616
<PackageReleaseNotes>
17-
v1.5.0
18-
* StartUp() was throwing an error when consoleOption was not provided, now it is fixed.
19-
* Write&lt;T&gt;(T value, ConsoleColor consoleColor, Melody melody) and WriteLine&lt;T&gt;(T value, ConsoleColor consoleColor, Melody melody) are added.
20-
* Under Beep(Melody melody) now notes are being null-checked and notes as [frequency-beeping duration-waiting duration] is value range checked.
17+
v1.6.0
18+
* 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.
19+
* SleepWithTitle(int duration) method added instead of Sleep(int duration). It writes sleeping duration into Console's title.
20+
* 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/Beep.cs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ public partial class HelpConsole
2828
/// </summary>
2929
/// <param name="duration"></param>
3030
/// <returns></returns>
31-
public static Melody Beeping(int duration) => new Melody { Notes = new int[] { 725, duration, duration } };
31+
public static Melody Beeping(int duration)
32+
{
33+
return new Melody { Notes = new int[] { 725, duration, duration } };
34+
}
3235

3336
/// <summary>
3437
/// Melody holds integer array with an order of sound frequency, duuration of sound and waiting.
@@ -82,10 +85,10 @@ public static void Beep(Melody melody)
8285
}
8386

8487
// Checking if the beeping duration or waitin duration are positive values.
85-
if (melody.Notes[i + 1] < 0 || melody.Notes[i + 2] < 0)
88+
if (melody.Notes[i + 1] <= 0 || melody.Notes[i + 2] <= 0)
8689
{
8790
//
88-
WriteLine($"Error on notes. Notes at index: {i+1}/{i+2} {(melody.Notes[i + 1] < 0 ? "beeping duration should be greater than 0" : "")} {(melody.Notes[i + 2] < 0 ? "waiting duration should be greater than 0" : "")}");
91+
WriteLine($"Error on notes. Notes at index: {i + 1}/{i + 2} {(melody.Notes[i + 1] < 0 ? "beeping duration should be greater than 0" : "")} {(melody.Notes[i + 2] < 0 ? "waiting duration should be greater than 0" : "")}");
8992

9093
//
9194
continue;
@@ -104,20 +107,31 @@ public static void Beep(Melody melody)
104107
}
105108

106109
/// <summary>
107-
/// Sleep uses <see cref="Thread.Sleep(int)"/>, writes Sleeping {duration} ms to console's title via <see cref="SetConsoleTitle(string)"/>.
110+
/// Sleep uses <see cref="Thread.Sleep(int)"/>.
108111
/// </summary>
109112
/// <param name="duration">Time in milliseconds.</param>
110113
//[SupportedOSPlatform("windows")]
111114
public static void Sleep(int duration)
115+
{
116+
// Sleeping.
117+
Thread.Sleep(duration);
118+
}
119+
120+
/// <summary>
121+
/// Sleep uses <see cref="Thread.Sleep(int)"/>, writes Sleeping {duration} s/ms to console's title via <see cref="SetConsoleTitle(string)"/>.
122+
/// </summary>
123+
/// <param name="duration">Time in milliseconds.</param>
124+
//[SupportedOSPlatform("windows")]
125+
public static void SleepWithTitle(int duration)
112126
{
113127
// Save console title into temporary variable.
114128
string tempTitle = Console.Title;
115129

116130
// Set console title specified with duration to indicate sleeping.
117-
SetConsoleTitle($"Sleeping {duration} ms");
131+
SetConsoleTitle($"Sleeping {(duration >= 1000 ? duration / 1000 : duration)} {(duration >= 1000 ? "s" : "ms")}");
118132

119133
// Sleeping.
120-
Thread.Sleep(duration);
134+
Sleep(duration);
121135

122136
// Set console title's back.
123137
SetConsoleTitle(tempTitle);

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: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,32 @@ 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.
1717
/// </summary>
18-
public readonly static ScreenColorOption ScreenColorOptionYellow = new ScreenColorOption(foregroundColor: ConsoleColor.Yellow, backgroundColor: ConsoleColor.Black);
18+
public static readonly ScreenColorOption ScreenColorOptionYellow = new ScreenColorOption(foregroundColor: ConsoleColor.Yellow, backgroundColor: ConsoleColor.Black);
1919

2020
/// <summary>
2121
/// Preset black for background, green for foreground color.
2222
/// </summary>
23-
public readonly static ScreenColorOption ScreenColorOptionGreen = new ScreenColorOption(foregroundColor: ConsoleColor.Green, backgroundColor: ConsoleColor.Black);
23+
public static readonly ScreenColorOption ScreenColorOptionGreen = new ScreenColorOption(foregroundColor: ConsoleColor.Green, backgroundColor: ConsoleColor.Black);
2424

2525
/// <summary>
2626
/// Preset black for background, green for foreground color.
2727
/// </summary>
28-
public readonly static ScreenColorOption ScreenColorOptionCyan = new ScreenColorOption(foregroundColor: ConsoleColor.Cyan, backgroundColor: ConsoleColor.Black);
28+
public static readonly ScreenColorOption ScreenColorOptionCyan = new ScreenColorOption(foregroundColor: ConsoleColor.Cyan, backgroundColor: ConsoleColor.Black);
2929

3030
/// <summary>
3131
/// Preset black for background, dark yellow for foreground color.
3232
/// </summary>
33-
public readonly static ScreenColorOption ScreenColorOptionDarkYellow = new ScreenColorOption(foregroundColor: ConsoleColor.DarkYellow, backgroundColor: ConsoleColor.Black);
33+
public static readonly ScreenColorOption ScreenColorOptionDarkYellow = new ScreenColorOption(foregroundColor: ConsoleColor.DarkYellow, backgroundColor: ConsoleColor.Black);
3434

3535
/// <summary>
3636
/// Settings for console colors.
@@ -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)