@@ -17,15 +17,16 @@ public string ShowSlider()
17
17
{
18
18
RenderInterface ( ) ;
19
19
20
- var key = Console . ReadKey ( true ) ;
20
+ var key = AnsiConsole . Console . Input . ReadKey ( true ) ;
21
+ if ( key == null ) continue ;
21
22
22
23
if ( _state . IsTypingNumber )
23
24
{
24
- HandleNumberInput ( key ) ;
25
+ HandleNumberInput ( key . Value ) ;
25
26
continue ;
26
27
}
27
28
28
- if ( HandleNavigationKey ( key ) )
29
+ if ( HandleNavigationKey ( key . Value ) )
29
30
{
30
31
return FormatResult ( ) ;
31
32
}
@@ -36,22 +37,26 @@ public string ShowSlider()
36
37
37
38
private void RenderInterface ( )
38
39
{
40
+ HideCursor ( ) ;
41
+ StringWriter output = new ( ) ;
42
+ var console = AnsiConsole . Create ( new AnsiConsoleSettings
43
+ {
44
+ Out = new AnsiConsoleOutput ( output )
45
+ } ) ;
46
+
47
+ console . Clear ( ) ;
48
+ DrawSlider ( console ) ;
49
+ DrawInstructions ( console ) ;
50
+
39
51
AnsiConsole . Clear ( ) ;
40
- DrawSlider ( ) ;
41
- DrawInstructions ( ) ;
52
+ AnsiConsole . Write ( output . ToString ( ) ) ;
53
+ ShowCursor ( ) ;
42
54
}
43
55
44
- private void DrawInstructions ( )
45
- {
46
- if ( _state . IsTypingNumber )
47
- {
48
- AnsiConsole . Write ( DisplayStrings . GetTimeInput ( _state . NumberBuffer ) ) ;
49
- }
50
- else
51
- {
52
- AnsiConsole . Write ( DisplayStrings . Controls ) ;
53
- }
54
- }
56
+ private void DrawInstructions ( IAnsiConsole console )
57
+ => console . Write ( _state . IsTypingNumber
58
+ ? DisplayStrings . GetTimeInput ( _state . NumberBuffer )
59
+ : DisplayStrings . Controls ) ;
55
60
56
61
private void HandleNumberInput ( ConsoleKeyInfo key )
57
62
{
@@ -93,7 +98,9 @@ private bool HandleNavigationKey(ConsoleKeyInfo key)
93
98
return true ;
94
99
}
95
100
96
- var step = ( key . Modifiers & ConsoleModifiers . Shift ) != 0 ? Constants . MillisecondStep : Constants . SecondStep ;
101
+ var step = ( key . Modifiers & ConsoleModifiers . Shift ) != 0
102
+ ? Constants . MillisecondStep
103
+ : Constants . SecondStep ;
97
104
98
105
return key . Key switch
99
106
{
@@ -111,15 +118,15 @@ private bool HandleNavigationKey(ConsoleKeyInfo key)
111
118
112
119
private static bool SetResult ( bool result ) => result ;
113
120
114
- private void DrawSlider ( )
121
+ private void DrawSlider ( IAnsiConsole console )
115
122
{
116
123
var slider = CreateSliderVisualization ( ) ;
117
124
118
- AnsiConsole . MarkupLine ( $ "\n Video duration: [blue]{ FormatTime ( _duration ) } [/]") ;
119
- AnsiConsole . MarkupLine (
125
+ console . MarkupLine ( $ "\n Video duration: [blue]{ FormatTime ( _duration ) } [/]") ;
126
+ console . MarkupLine (
120
127
$ "Selected range: [green]{ _state . FormatRange ( ) } [/]\n ") ;
121
- AnsiConsole . MarkupLine ( $ "Currently adjusting: [blue]{ ( _state . IsAdjustingStart ? "Start" : "End" ) } [/] position\n ") ;
122
- AnsiConsole . MarkupLine ( $ "0s { slider } { _duration . TotalSeconds : F2} s") ;
128
+ console . MarkupLine ( $ "Currently adjusting: [blue]{ ( _state . IsAdjustingStart ? "Start" : "End" ) } [/] position\n ") ;
129
+ console . MarkupLine ( $ "0s { slider } { _duration . TotalSeconds : F2} s") ;
123
130
}
124
131
125
132
private string CreateSliderVisualization ( ) =>
@@ -136,4 +143,10 @@ private string FormatResult()
136
143
}
137
144
138
145
private bool IsCancelled ( ) => _state . IsCancelled ;
146
+
147
+ private static void HideCursor ( )
148
+ => AnsiConsole . Cursor . Hide ( ) ;
149
+
150
+ private static void ShowCursor ( )
151
+ => AnsiConsole . Cursor . Show ( ) ;
139
152
}
0 commit comments