Skip to content

Commit 6834a6e

Browse files
author
RogueMacro
committed
Better Make logs
1 parent 699bda9 commit 6834a6e

File tree

3 files changed

+34
-103
lines changed

3 files changed

+34
-103
lines changed

src/beef.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pub struct BeefSpace {
1717
pub projects: HashMap<String, ProjectEntry>,
1818
#[serde(default)]
1919
pub workspace_folders: HashMap<String, HashSet<String>>,
20+
#[serde(default)]
2021
pub workspace: Workspace,
2122

2223
#[serde(flatten)]

src/ops/install.rs

Lines changed: 6 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
use std::{
2-
collections::HashMap,
32
fs,
43
path::{Path, PathBuf},
5-
time::Duration,
64
};
75

86
use anyhow::Context;
9-
use indicatif::{ProgressBar, ProgressStyle};
107
use reqwest::Url;
118
use semver::Version;
129

@@ -18,12 +15,14 @@ use crate::{
1815
prelude::*,
1916
};
2017

18+
/// Returns the path to the installed package and a bool indicating
19+
/// if the package was downloaded.
2120
pub fn install<S, C>(
2221
pkg: S,
2322
version: &Version,
2423
index: Option<&Index>,
2524
progress_callback: C,
26-
) -> Result<PathBuf>
25+
) -> Result<(PathBuf, bool)>
2726
where
2827
S: AsRef<str>,
2928
C: FnMut(git2::Progress<'_>),
@@ -52,7 +51,7 @@ where
5251
let ident = format!("{}-{}", pkg, version);
5352
let path = paths::pkg(".", &ident);
5453
if path.exists() {
55-
return Ok(path);
54+
return Ok((path, false));
5655
}
5756

5857
let (path, _) = install_git(
@@ -61,7 +60,8 @@ where
6160
Some(&ident),
6261
progress_callback,
6362
)?;
64-
Ok(path)
63+
64+
Ok((path, true))
6565
}
6666

6767
/// Returns the path to the installed package and the revision
@@ -217,78 +217,3 @@ pub fn prepare_pkg(path: &Path, ident: Option<&str>) -> Result<()> {
217217

218218
Ok(())
219219
}
220-
221-
pub fn install_multiple<F>(
222-
pkgs: &HashMap<String, Version>,
223-
with_progress: bool,
224-
index: Option<&Index>,
225-
on_install: Option<F>,
226-
) -> Result<HashMap<String, PathBuf>>
227-
where
228-
F: Fn(&str, &Version),
229-
{
230-
let mut owned_index = None;
231-
let index = index.map_or_else(
232-
|| -> Result<&Index> {
233-
owned_index = Some(index::parse(false, false)?);
234-
Ok(owned_index.as_ref().unwrap())
235-
},
236-
|i| Ok(i),
237-
)?;
238-
239-
let mut paths = HashMap::new();
240-
if with_progress {
241-
let progress = crate::log::get_multi_progress();
242-
let install_progress = progress.add(
243-
ProgressBar::new_spinner().with_style(
244-
ProgressStyle::default_spinner()
245-
.template("{spinner:>11}> {msg}")?
246-
.tick_chars("=\\|/==="),
247-
),
248-
);
249-
let fetch_progress = progress.add(
250-
ProgressBar::new(pkgs.len() as u64)
251-
.with_style(
252-
ProgressStyle::default_bar()
253-
.template("{prefix:>12.bright.cyan} [{bar:40}] {pos}/{len}")?
254-
.progress_chars("=> "),
255-
)
256-
.with_prefix("Fetching"),
257-
);
258-
install_progress.enable_steady_tick(Duration::from_millis(150));
259-
fetch_progress.tick();
260-
261-
for (pkg, version) in pkgs.iter() {
262-
install_progress.set_message(format!("{} v{}", pkg, version));
263-
264-
let path = install(pkg, version, Some(index), |_| {})?;
265-
paths.insert(pkg.clone(), path);
266-
267-
install_progress.println(format!(
268-
"{:>12} {} v{}",
269-
console::style("Installed").bright().green(),
270-
pkg,
271-
version
272-
));
273-
fetch_progress.inc(1);
274-
275-
if let Some(on_install) = &on_install {
276-
on_install(pkg, version);
277-
}
278-
}
279-
280-
fetch_progress.finish();
281-
install_progress.finish_and_clear();
282-
progress.clear()?;
283-
} else {
284-
for (pkg, version) in pkgs.iter() {
285-
let path = install(pkg, version, Some(index), |_| {})?;
286-
paths.insert(pkg.clone(), path);
287-
if let Some(on_install) = &on_install {
288-
on_install(pkg, version);
289-
}
290-
}
291-
}
292-
293-
Ok(paths)
294-
}

src/ops/make.rs

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub fn make(path: &Path, silent: bool) -> Result<()> {
2727

2828
if !silent {
2929
println!(
30-
"{:>12} {} v{}\n",
30+
"{:>12} {} v{}",
3131
console::style("Make").bright().cyan(),
3232
manifest.package.name,
3333
manifest.package.version
@@ -36,6 +36,10 @@ pub fn make(path: &Path, silent: bool) -> Result<()> {
3636

3737
let multi = crate::log::get_multi_progress();
3838

39+
// Invisible progress bar to create empty line between logs and progress bars
40+
let p = multi.add(ProgressBar::new(0).with_style(ProgressStyle::default_bar().template(" ")?));
41+
p.finish();
42+
3943
let index = make_step(
4044
&multi,
4145
1,
@@ -79,7 +83,7 @@ pub fn make(path: &Path, silent: bool) -> Result<()> {
7983
let progress = multi.add(
8084
ProgressBar::new(1).with_style(
8185
ProgressStyle::default_bar()
82-
.template("{prefix:>12} [{bar:11}] {msg:.bright.grey}")?
86+
.template("{prefix:>12} [{bar:40}] {msg:.bright.grey}")?
8387
.progress_chars("=> "),
8488
),
8589
);
@@ -100,26 +104,32 @@ pub fn make(path: &Path, silent: bool) -> Result<()> {
100104
for (pkg, versions) in lock {
101105
for version in versions {
102106
progress.set_message(format!("{} 0%", pkg));
103-
let path =
107+
let (path, fetched) =
104108
crate::ops::install(&pkg, &version, Some(&index), |install_progress| {
105109
progress.set_message(format!(
106-
"{} {}% ({}/{}) {}",
110+
"{} {}%",
107111
pkg,
108-
((install_progress.received_objects()
109-
+ install_progress.indexed_objects())
110-
as f32
111-
/ (install_progress.total_objects() * 2) as f32
112+
(install_progress.indexed_objects() as f32
113+
/ install_progress.total_objects() as f32
112114
* 100f32)
113-
.round(),
114-
install_progress.received_objects(),
115-
install_progress.total_objects(),
116-
install_progress.indexed_objects()
115+
.floor(),
117116
))
118117
})?;
119118

120-
pkgs.insert((pkg.clone(), either::Left(version)), path);
119+
pkgs.insert((pkg.clone(), either::Left(version.clone())), path);
121120

122121
if !silent {
122+
if fetched {
123+
multi.suspend(|| {
124+
println!(
125+
"{:>12} {} v{}",
126+
console::style("Fetched").bright().cyan(),
127+
pkg,
128+
version
129+
);
130+
});
131+
}
132+
123133
progress.inc(1);
124134
progress.set_prefix(format!(
125135
"{} / {}",
@@ -138,17 +148,12 @@ pub fn make(path: &Path, silent: bool) -> Result<()> {
138148
Some(name),
139149
|install_progress| {
140150
progress.set_message(format!(
141-
"{} {}% ({}/{}) {}",
151+
"{} {}%",
142152
name,
143-
((install_progress.received_objects()
144-
+ install_progress.indexed_objects())
145-
as f32
146-
/ (install_progress.total_objects() * 2) as f32
153+
(install_progress.indexed_objects() as f32
154+
/ install_progress.total_objects() as f32
147155
* 100f32)
148156
.round(),
149-
install_progress.received_objects(),
150-
install_progress.total_objects(),
151-
install_progress.indexed_objects()
152157
))
153158
},
154159
)?;
@@ -267,7 +272,7 @@ where
267272
.template("{msg} {spinner}")?
268273
.tick_chars("⠁⠂⠄⡀⢀⠠⠐⠈✔");
269274
let progress = multi.insert(
270-
step as usize - 1,
275+
step as usize, /*- 1*/
271276
ProgressBar::new_spinner()
272277
.with_message(format!(
273278
"{:>12} {}{}",

0 commit comments

Comments
 (0)