Skip to content

Commit d40dfb0

Browse files
committed
some minor improvements
1 parent f6b58aa commit d40dfb0

File tree

2 files changed

+33
-20
lines changed

2 files changed

+33
-20
lines changed
Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Threading;
1+
using System;
2+
using System.Threading;
23
using LibVLCSharp.Shared;
34
using RadioTerm.Player;
45

@@ -13,11 +14,18 @@ public static bool IsPlayable(this Station station)
1314
vlc.Log += (_, _) => { }; // disable default log handler
1415
var previousVolume = player.Volume;
1516
player.Volume = 0;
16-
player.Play(new Media(vlc, station.Url, FromType.FromLocation));
17-
Thread.Sleep(1000); // dirty hack to let vlc some time to load the stream
18-
var playable = player.IsPlaying;
19-
player.Stop();
20-
player.Volume = previousVolume; // restore the volume
21-
return playable;
17+
try
18+
{
19+
player.Play(new Media(vlc, station.Url, FromType.FromLocation));
20+
Thread.Sleep(1000); // dirty hack to let vlc some time to load the stream
21+
var playable = player.IsPlaying;
22+
player.Stop();
23+
player.Volume = previousVolume; // restore the volume
24+
return playable;
25+
}
26+
catch
27+
{
28+
return false;
29+
}
2230
}
2331
}

RadioTerm/Rendering/DisplayEngine.cs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@ namespace RadioTerm.Rendering;
99

1010
public sealed class DisplayEngine : IDisplayEngine
1111
{
12-
private void DrawHeader()
12+
private void DrawHeader(int stationCount)
1313
{
1414
Console.ForegroundColor = ConsoleColor.DarkYellow;
15-
string title = "Welcome to RadioTerm";
15+
const string title = "Welcome to RadioTerm";
1616
WriteToCenter(title, 1);
17-
DrawBar(2, title.Length + 18);
17+
Console.ResetColor();
18+
var stationCollection = $"You have {stationCount} stations in your collection";
19+
WriteToCenter(stationCollection,2);
20+
// Console.ForegroundColor = ConsoleColor.DarkYellow;
21+
DrawBar(3, stationCollection.Length + 18);
1822
Console.WriteLine();
1923
Console.WriteLine();
2024
Console.ResetColor();
@@ -36,7 +40,7 @@ private void DrawStations(IEnumerable<Station> stations)
3640
Console.ForegroundColor = ConsoleColor.Gray;
3741
}
3842

39-
WriteToCenter(station.Name, i + 4);
43+
WriteToCenter(station.Name, i + 5);
4044
Console.ForegroundColor = ConsoleColor.Gray;
4145
}
4246
}
@@ -80,14 +84,17 @@ private void DrawFooter()
8084

8185
public void Draw(IEnumerable<Station> stations)
8286
{
87+
Console.CursorVisible = false;
8388
Console.Clear();
84-
DrawHeader();
85-
DrawStations(stations);
89+
var stationsEnumerated = stations.ToList();
90+
DrawHeader(stationsEnumerated.Count);
91+
DrawStations(stationsEnumerated);
8692
DrawFooter();
8793
}
8894

8995
public (string name, string url) AddStation()
9096
{
97+
Console.CursorVisible = true;
9198
Console.Clear();
9299
Console.ForegroundColor = ConsoleColor.DarkYellow;
93100
Console.WriteLine("Add a radio");
@@ -107,14 +114,12 @@ public Guid DeleteStation(IEnumerable<Station> stations)
107114
do
108115
{
109116
Console.Clear();
110-
if (k.Key == ConsoleKey.UpArrow)
111-
{
112-
selectedStation = stationList.Previous(selectedStation);
113-
}
114-
else if (k.Key == ConsoleKey.DownArrow)
117+
selectedStation = k.Key switch
115118
{
116-
selectedStation = stationList.Next(selectedStation);
117-
}
119+
ConsoleKey.UpArrow => stationList.Previous(selectedStation),
120+
ConsoleKey.DownArrow => stationList.Next(selectedStation),
121+
_ => selectedStation
122+
};
118123

119124
foreach (var st in stationList)
120125
{

0 commit comments

Comments
 (0)