@@ -31,7 +31,10 @@ 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 , ColorConfig , BOLD_GREY , GREY } ;
34
+ use turborepo_ui:: {
35
+ cprint, cprintln, sender:: UISender , tui, tui:: TuiSender , wui:: sender:: WebUISender , ColorConfig ,
36
+ BOLD_GREY , GREY ,
37
+ } ;
35
38
36
39
pub use crate :: run:: error:: Error ;
37
40
use crate :: {
@@ -69,9 +72,13 @@ pub struct Run {
69
72
task_access : TaskAccess ,
70
73
daemon : Option < DaemonClient < DaemonConnector > > ,
71
74
should_print_prelude : bool ,
72
- ui_mode : UIMode ,
73
75
}
74
76
77
+ type UIResult < T > = Result < Option < ( T , JoinHandle < Result < ( ) , turborepo_ui:: Error > > ) > , Error > ;
78
+
79
+ type WuiResult = UIResult < WebUISender > ;
80
+ type TuiResult = UIResult < TuiSender > ;
81
+
75
82
impl Run {
76
83
fn has_persistent_tasks ( & self ) -> bool {
77
84
self . engine . has_persistent_tasks
@@ -195,24 +202,41 @@ impl Run {
195
202
}
196
203
197
204
pub fn has_tui ( & self ) -> bool {
198
- self . ui_mode . use_tui ( )
205
+ self . opts . run_opts . ui_mode . use_tui ( )
199
206
}
200
207
201
208
pub fn should_start_ui ( & self ) -> Result < bool , Error > {
202
- Ok ( self . ui_mode . use_tui ( )
209
+ Ok ( self . opts . run_opts . ui_mode . use_tui ( )
203
210
&& self . opts . run_opts . dry_run . is_none ( )
204
211
&& tui:: terminal_big_enough ( ) ?)
205
212
}
206
213
207
- #[ allow( clippy:: type_complexity) ]
208
- pub fn start_experimental_ui (
209
- & self ,
210
- ) -> Result < Option < ( AppSender , JoinHandle < Result < ( ) , tui:: Error > > ) > , Error > {
214
+ pub fn start_ui ( & self ) -> UIResult < UISender > {
211
215
// Print prelude here as this needs to happen before the UI is started
212
216
if self . should_print_prelude {
213
217
self . print_run_prelude ( ) ;
214
218
}
215
219
220
+ match self . opts . run_opts . ui_mode {
221
+ UIMode :: Tui => self
222
+ . start_terminal_ui ( )
223
+ . map ( |res| res. map ( |( sender, handle) | ( UISender :: Tui ( sender) , handle) ) ) ,
224
+ UIMode :: Stream => Ok ( None ) ,
225
+ UIMode :: Web => self
226
+ . start_web_ui ( )
227
+ . map ( |res| res. map ( |( sender, handle) | ( UISender :: Wui ( sender) , handle) ) ) ,
228
+ }
229
+ }
230
+ fn start_web_ui ( & self ) -> WuiResult {
231
+ let ( tx, rx) = tokio:: sync:: mpsc:: unbounded_channel ( ) ;
232
+
233
+ let handle = tokio:: spawn ( turborepo_ui:: wui:: server:: start_server ( rx) ) ;
234
+
235
+ Ok ( Some ( ( WebUISender { tx } , handle) ) )
236
+ }
237
+
238
+ #[ allow( clippy:: type_complexity) ]
239
+ fn start_terminal_ui ( & self ) -> TuiResult {
216
240
if !self . should_start_ui ( ) ? {
217
241
return Ok ( None ) ;
218
242
}
@@ -223,8 +247,8 @@ impl Run {
223
247
return Ok ( None ) ;
224
248
}
225
249
226
- let ( sender, receiver) = AppSender :: new ( ) ;
227
- let handle = tokio:: task:: spawn_blocking ( move || tui:: run_app ( task_names, receiver) ) ;
250
+ let ( sender, receiver) = TuiSender :: new ( ) ;
251
+ let handle = tokio:: task:: spawn_blocking ( move || Ok ( tui:: run_app ( task_names, receiver) ? ) ) ;
228
252
229
253
Ok ( Some ( ( sender, handle) ) )
230
254
}
@@ -236,11 +260,7 @@ impl Run {
236
260
}
237
261
}
238
262
239
- pub async fn run (
240
- & mut self ,
241
- experimental_ui_sender : Option < AppSender > ,
242
- is_watch : bool ,
243
- ) -> Result < i32 , Error > {
263
+ pub async fn run ( & mut self , ui_sender : Option < UISender > , is_watch : bool ) -> Result < i32 , Error > {
244
264
let skip_cache_writes = self . opts . runcache_opts . skip_writes ;
245
265
if let Some ( subscriber) = self . signal_handler . subscribe ( ) {
246
266
let run_cache = self . run_cache . clone ( ) ;
@@ -427,7 +447,7 @@ impl Run {
427
447
self . processes . clone ( ) ,
428
448
& self . repo_root ,
429
449
global_env,
430
- experimental_ui_sender ,
450
+ ui_sender ,
431
451
is_watch,
432
452
) ;
433
453
0 commit comments