-
Notifications
You must be signed in to change notification settings - Fork 0
/
AnimationService.cs
51 lines (43 loc) · 1.56 KB
/
AnimationService.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System;
using System.Threading;
using System.Threading.Tasks;
using DiD.Idefix.Resources;
namespace DiD.Idefix.Animations
{
internal class AnimationService : IAnimationService
{
public Task ShowIdefixAsync()
{
string idefix = IdefixResources.Idefix;
return Console.Out.WriteLineAsync(idefix);
}
public async Task ShowWigglingIdefixAsync()
{
Console.CursorVisible = false;
Console.Clear();
await ShowIdefixAsync();
var previousRow = Console.CursorTop;
var tailLeft = IdefixResources.IdefixTailLeft.Split(Environment.NewLine);
var tailRight = IdefixResources.IdefixTailRight.Split(Environment.NewLine);
bool isTailRight = true;
CancellationTokenSource cts = new CancellationTokenSource(2500);
try
{
while (!cts.Token.IsCancellationRequested)
{
var tailToUpdate = isTailRight ? tailLeft : tailRight;
for (int i = 0; i < tailToUpdate.Length; i++)
{
Console.SetCursorPosition(0, 2 + i);
await Console.Out.WriteAsync(tailToUpdate[i]);
}
isTailRight = !isTailRight;
await Task.Delay(250, cts.Token);
}
}
catch (TaskCanceledException) { }
Console.CursorVisible = true;
Console.SetCursorPosition(0, previousRow);
}
}
}