Move the original get_draw_order code into the tree_iter module.
This commit is contained in:
@@ -126,26 +126,6 @@ impl Activity {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn is_transparent(&self) -> bool {
|
||||
match self {
|
||||
Activity::Root(_activity_root) => true,
|
||||
Activity::Unknown(_activity_unknown) => false,
|
||||
Activity::CopyPath(_activity_copy_path) => false,
|
||||
Activity::FileTransfer(_activity_file_transfer) => false,
|
||||
Activity::Realize(_activity_realize) => true,
|
||||
Activity::CopyPaths(_activity_copy_paths) => true,
|
||||
Activity::Builds(_activity_builds) => true,
|
||||
Activity::Build(_activity_build) => false,
|
||||
Activity::OptimizeStore(_activity_optimize_store) => false,
|
||||
Activity::VerifyPaths(_activity_verify_paths) => false,
|
||||
Activity::Substitute(_activity_substitute) => false,
|
||||
Activity::QueryPathInfo(_activity_query_path_info) => false,
|
||||
Activity::PostBuildHook(_activity_post_build_hook) => false,
|
||||
Activity::BuildWaiting(_activity_build_waiting) => true,
|
||||
Activity::FetchTree(_activity_fetch_tree) => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn display_name(&self) -> Option<Cow<'_, str>> {
|
||||
match self {
|
||||
Activity::Root(_activity_root) => {
|
||||
@@ -204,63 +184,43 @@ impl Activity {
|
||||
|
||||
pub(crate) fn get_progress_text(&self) -> Option<Cow<'_, str>> {
|
||||
match self {
|
||||
Activity::Root(_activity_root) => {
|
||||
// TODO
|
||||
panic!("Attempted to get_progress_text of a root activity.");
|
||||
}
|
||||
Activity::Root(_activity_root) => None,
|
||||
Activity::Unknown(_activity_unknown) => None,
|
||||
Activity::CopyPath(activity_copy_path) => Some(Cow::Owned(format!(
|
||||
"[{}/{}]",
|
||||
activity_copy_path.done, activity_copy_path.expected
|
||||
))),
|
||||
Activity::FileTransfer(activity_file_transfer) => Some(Cow::Owned(format!(
|
||||
"[{}/{}]",
|
||||
activity_file_transfer.done, activity_file_transfer.expected
|
||||
))),
|
||||
Activity::Realize(_activity_realize) => {
|
||||
// TODO
|
||||
panic!("Attempted to get_progress_text of a realize activity.");
|
||||
Activity::CopyPath(activity_copy_path) => {
|
||||
get_progress_bar(activity_copy_path.done, activity_copy_path.expected).or_else(
|
||||
|| get_progress_text(activity_copy_path.done, activity_copy_path.expected),
|
||||
)
|
||||
}
|
||||
Activity::FileTransfer(activity_file_transfer) => {
|
||||
get_progress_bar(activity_file_transfer.done, activity_file_transfer.expected)
|
||||
.or_else(|| {
|
||||
get_progress_text(
|
||||
activity_file_transfer.done,
|
||||
activity_file_transfer.expected,
|
||||
)
|
||||
})
|
||||
}
|
||||
Activity::Realize(_activity_realize) => None,
|
||||
Activity::CopyPaths(activity_copy_paths) => {
|
||||
get_progress_bar(activity_copy_paths.done, activity_copy_paths.expected).or_else(
|
||||
|| get_progress_text(activity_copy_paths.done, activity_copy_paths.expected),
|
||||
)
|
||||
}
|
||||
Activity::Builds(activity_builds) => {
|
||||
get_progress_bar(activity_builds.done, activity_builds.expected)
|
||||
.or_else(|| get_progress_text(activity_builds.done, activity_builds.expected))
|
||||
}
|
||||
Activity::CopyPaths(activity_copy_paths) => Some(Cow::Owned(format!(
|
||||
"[{}/{}]",
|
||||
activity_copy_paths.done, activity_copy_paths.expected
|
||||
))),
|
||||
Activity::Builds(activity_builds) => Some(Cow::Owned(format!(
|
||||
"[{}/{}]",
|
||||
activity_builds.done, activity_builds.expected
|
||||
))),
|
||||
Activity::Build(activity_build) => activity_build
|
||||
.phase
|
||||
.as_ref()
|
||||
.map(|phase| Cow::Owned(format!("[{}]", phase))),
|
||||
Activity::OptimizeStore(_activity_optimize_store) => {
|
||||
// TODO
|
||||
panic!("Attempted to get_progress_text of a optimize store activity.");
|
||||
}
|
||||
Activity::VerifyPaths(_activity_verify_paths) => {
|
||||
// TODO
|
||||
panic!("Attempted to get_progress_text of a verify paths activity.");
|
||||
}
|
||||
Activity::Substitute(_activity_substitute) => {
|
||||
// TODO
|
||||
panic!("Attempted to get_progress_text of a substitute activity.");
|
||||
}
|
||||
Activity::QueryPathInfo(_activity_query_path_info) => {
|
||||
// TODO
|
||||
panic!("Attempted to get_progress_text of a query path info activity.");
|
||||
}
|
||||
Activity::PostBuildHook(_activity_post_build_hook) => {
|
||||
// TODO
|
||||
panic!("Attempted to get_progress_text of a post build hook activity.");
|
||||
}
|
||||
Activity::BuildWaiting(_activity_build_waiting) => {
|
||||
// TODO
|
||||
panic!("Attempted to get_progress_text of a build waiting activity.");
|
||||
}
|
||||
Activity::FetchTree(_activity_fetch_tree) => {
|
||||
// TODO
|
||||
panic!("Attempted to get_progress_text of a fetch tree activity.");
|
||||
}
|
||||
Activity::OptimizeStore(_activity_optimize_store) => None,
|
||||
Activity::VerifyPaths(_activity_verify_paths) => None,
|
||||
Activity::Substitute(_activity_substitute) => None,
|
||||
Activity::QueryPathInfo(_activity_query_path_info) => None,
|
||||
Activity::PostBuildHook(_activity_post_build_hook) => None,
|
||||
Activity::BuildWaiting(_activity_build_waiting) => None,
|
||||
Activity::FetchTree(_activity_fetch_tree) => None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -531,3 +491,35 @@ impl Default for ActivityState {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn get_progress_bar(done: u64, expected: u64) -> Option<Cow<'static, str>> {
|
||||
if expected == 0 {
|
||||
return None;
|
||||
}
|
||||
let percent = done as f32 / expected as f32;
|
||||
// ○◔◑◕●
|
||||
// ○◎◉●
|
||||
// ▁▂▃▄▅▆▇█
|
||||
// ▏▎▍▌▋▊▉█
|
||||
// ░▒▓█
|
||||
//
|
||||
// 🮷 download
|
||||
// 🮸 upload
|
||||
// 🮵
|
||||
// 🮶
|
||||
if percent < 0.33 {
|
||||
Some(Cow::Borrowed("░"))
|
||||
} else if percent < 0.66 {
|
||||
Some(Cow::Borrowed("▒"))
|
||||
} else if percent < 1.0 {
|
||||
Some(Cow::Borrowed("▓"))
|
||||
} else if percent >= 1.0 {
|
||||
Some(Cow::Borrowed("█"))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn get_progress_text(done: u64, expected: u64) -> Option<Cow<'static, str>> {
|
||||
Some(Cow::Owned(format!("[{}/{}]", done, expected)))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user