@@ -31,7 +31,9 @@ use turborepo_env::EnvironmentVariableMap;
31
31
use turborepo_repository:: package_graph:: { PackageGraph , PackageName , PackageNode } ;
32
32
use turborepo_scm:: SCM ;
33
33
use turborepo_telemetry:: events:: generic:: GenericEventBuilder ;
34
- use turborepo_ui:: { cprint, cprintln, tui, tui:: AppSender , BOLD_GREY , GREY , UI } ;
34
+ use turborepo_ui:: {
35
+ cprint, cprintln, sender:: UISender , tui, tui:: TuiSender , wui:: WebUISender , BOLD_GREY , GREY , UI ,
36
+ } ;
35
37
36
38
pub use crate :: run:: error:: Error ;
37
39
use crate :: {
@@ -69,9 +71,12 @@ pub struct Run {
69
71
task_access : TaskAccess ,
70
72
daemon : Option < DaemonClient < DaemonConnector > > ,
71
73
should_print_prelude : bool ,
72
- ui_mode : UIMode ,
73
74
}
74
75
76
+ type UIResult = Result < Option < ( UISender , JoinHandle < Result < ( ) , turborepo_ui:: Error > > ) > , Error > ;
77
+ type WuiResult = Result < Option < ( WebUISender , JoinHandle < Result < ( ) , turborepo_ui:: Error > > ) > , Error > ;
78
+ type TuiResult = Result < Option < ( TuiSender , JoinHandle < Result < ( ) , turborepo_ui:: Error > > ) > , Error > ;
79
+
75
80
impl Run {
76
81
fn has_persistent_tasks ( & self ) -> bool {
77
82
self . engine . has_persistent_tasks
@@ -173,19 +178,36 @@ impl Run {
173
178
}
174
179
175
180
pub fn has_tui ( & self ) -> bool {
176
- self . ui_mode . use_tui ( )
181
+ self . opts . run_opts . ui_mode . use_tui ( )
177
182
}
178
183
179
184
pub fn should_start_ui ( & self ) -> Result < bool , Error > {
180
- Ok ( self . ui_mode . use_tui ( )
185
+ Ok ( self . opts . run_opts . ui_mode . use_tui ( )
181
186
&& self . opts . run_opts . dry_run . is_none ( )
182
187
&& tui:: terminal_big_enough ( ) ?)
183
188
}
184
189
190
+ pub fn start_ui ( & self ) -> UIResult {
191
+ match self . opts . run_opts . ui_mode {
192
+ UIMode :: Tui => self
193
+ . start_terminal_ui ( )
194
+ . map ( |res| res. map ( |( sender, handle) | ( UISender :: Tui ( sender) , handle) ) ) ,
195
+ UIMode :: Stream => Ok ( None ) ,
196
+ UIMode :: Web => self
197
+ . start_web_ui ( )
198
+ . map ( |res| res. map ( |( sender, handle) | ( UISender :: Wui ( sender) , handle) ) ) ,
199
+ }
200
+ }
201
+ pub fn start_web_ui ( & self ) -> WuiResult {
202
+ let ( tx, rx) = tokio:: sync:: broadcast:: channel ( 100 ) ;
203
+
204
+ let handle = tokio:: spawn ( turborepo_ui:: wui:: start_ws_server ( rx) ) ;
205
+
206
+ Ok ( Some ( ( WebUISender { tx } , handle) ) )
207
+ }
208
+
185
209
#[ allow( clippy:: type_complexity) ]
186
- pub fn start_experimental_ui (
187
- & self ,
188
- ) -> Result < Option < ( AppSender , JoinHandle < Result < ( ) , tui:: Error > > ) > , Error > {
210
+ pub fn start_terminal_ui ( & self ) -> TuiResult {
189
211
// Print prelude here as this needs to happen before the UI is started
190
212
if self . should_print_prelude {
191
213
self . print_run_prelude ( ) ;
@@ -201,8 +223,8 @@ impl Run {
201
223
return Ok ( None ) ;
202
224
}
203
225
204
- let ( sender, receiver) = AppSender :: new ( ) ;
205
- let handle = tokio:: task:: spawn_blocking ( move || tui:: run_app ( task_names, receiver) ) ;
226
+ let ( sender, receiver) = TuiSender :: new ( ) ;
227
+ let handle = tokio:: task:: spawn_blocking ( move || Ok ( tui:: run_app ( task_names, receiver) ? ) ) ;
206
228
207
229
Ok ( Some ( ( sender, handle) ) )
208
230
}
@@ -214,11 +236,7 @@ impl Run {
214
236
}
215
237
}
216
238
217
- pub async fn run (
218
- & mut self ,
219
- experimental_ui_sender : Option < AppSender > ,
220
- is_watch : bool ,
221
- ) -> Result < i32 , Error > {
239
+ pub async fn run ( & mut self , ui_sender : Option < UISender > , is_watch : bool ) -> Result < i32 , Error > {
222
240
let skip_cache_writes = self . opts . runcache_opts . skip_writes ;
223
241
if let Some ( subscriber) = self . signal_handler . subscribe ( ) {
224
242
let run_cache = self . run_cache . clone ( ) ;
@@ -405,7 +423,7 @@ impl Run {
405
423
self . processes . clone ( ) ,
406
424
& self . repo_root ,
407
425
global_env,
408
- experimental_ui_sender ,
426
+ ui_sender ,
409
427
is_watch,
410
428
) ;
411
429
0 commit comments