MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / start

Method start

atomic-cli/src/commands/git/rolling_dashboard.rs:340–425  ·  view source on GitHub ↗
(window_size: usize, window_bytes: usize, enabled: bool)

Source from the content-addressed store, hash-verified

338
339impl Dashboard {
340 pub fn start(window_size: usize, window_bytes: usize, enabled: bool) -> Self {
341 let enabled = enabled && !crate::output::live::is_active();
342 let state = Arc::new(Mutex::new(Progress {
343 phase: "preflight",
344 total: 0,
345 checked: 0,
346 loaded: 0,
347 published: 0,
348 queued: 0,
349 in_flight: 0,
350 window_size,
351 reserved_bytes: 0,
352 window_bytes,
353 }));
354 let interactive = std::io::stderr().is_terminal()
355 && std::env::var_os("TERM").is_some_and(|term| term != "dumb");
356 let (stop, worker) = if enabled {
357 let (tx, rx) = mpsc::channel();
358 let shared = Arc::clone(&state);
359 let handle = thread::spawn(move || {
360 let mut screen = interactive.then(Screen::enter).and_then(Result::ok);
361 let mut metrics = Metrics::default();
362 let start = Instant::now();
363 let mut previous: Option<(Instant, f64)> = None;
364 let mut stopping = false;
365 loop {
366 let now = Instant::now();
367 let sample = resources();
368 let cpu =
369 previous
370 .zip(sample.cpu_seconds)
371 .and_then(|((time, prior), current)| {
372 let delta = now.duration_since(time).as_secs_f64();
373 (delta > 0.0)
374 .then_some(((current - prior).max(0.0) / delta) * 100.0)
375 });
376 if let Some(current) = sample.cpu_seconds {
377 previous = Some((now, current));
378 }
379 let progress = shared.lock().unwrap_or_else(|e| e.into_inner()).clone();
380 metrics.observe(&sample, cpu);
381 if let Some(active) = &mut screen {
382 if active
383 .terminal
384 .draw(|frame| {
385 draw(frame, &progress, &sample, cpu, start.elapsed(), &metrics)
386 })
387 .is_err()
388 {
389 // A broken terminal must not fail the import.
390 screen = None;
391 }
392 } else {
393 let text = plain(&progress, &sample, cpu, start.elapsed());
394 let mut stderr = std::io::stderr().lock();
395 let _ = stderr.write_all(text.as_bytes());
396 let _ = stderr.flush();
397 }

Callers

nothing calls this directly

Calls 11

is_activeFunction · 0.85
stderrFunction · 0.85
resourcesFunction · 0.85
plainFunction · 0.85
lockMethod · 0.80
drawFunction · 0.70
cloneMethod · 0.45
into_innerMethod · 0.45
observeMethod · 0.45
as_bytesMethod · 0.45
flushMethod · 0.45

Tested by

no test coverage detected