Remove unindent crate (#357)
This commit is contained in:
parent
f8676f2bec
commit
bf7f49848d
4 changed files with 29 additions and 11 deletions
7
Cargo.lock
generated
7
Cargo.lock
generated
|
@ -452,7 +452,6 @@ dependencies = [
|
||||||
"tokio",
|
"tokio",
|
||||||
"tokio-util",
|
"tokio-util",
|
||||||
"unescape",
|
"unescape",
|
||||||
"unindent",
|
|
||||||
"wait-timeout",
|
"wait-timeout",
|
||||||
"x11rb",
|
"x11rb",
|
||||||
"yuck",
|
"yuck",
|
||||||
|
@ -2288,12 +2287,6 @@ version = "0.2.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
|
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "unindent"
|
|
||||||
version = "0.1.7"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "f14ee04d9415b52b3aeab06258a3f07093182b88ba0f9b8d203f211a7a7d41c7"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "uuid"
|
name = "uuid"
|
||||||
version = "0.8.2"
|
version = "0.8.2"
|
||||||
|
|
|
@ -53,7 +53,6 @@ nix = "0.20"
|
||||||
smart-default = "0.6"
|
smart-default = "0.6"
|
||||||
simple-signal = "1.1"
|
simple-signal = "1.1"
|
||||||
unescape = "0.1"
|
unescape = "0.1"
|
||||||
unindent = "0.1"
|
|
||||||
|
|
||||||
tokio = { version = "1.0", features = ["full"] }
|
tokio = { version = "1.0", features = ["full"] }
|
||||||
futures-core = "0.3"
|
futures-core = "0.3"
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use anyhow::*;
|
use anyhow::*;
|
||||||
|
use std::fmt::Write;
|
||||||
use extend::ext;
|
use extend::ext;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
@ -155,9 +156,26 @@ pub fn replace_env_var_references(input: String) -> String {
|
||||||
.into_owned()
|
.into_owned()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn unindent(text: &str) -> String {
|
||||||
|
// take all the lines of our text and skip over the first empty ones
|
||||||
|
let lines = text.lines().skip_while(|x| *x == "");
|
||||||
|
// find the smallest indentation
|
||||||
|
let min = lines.clone().fold(None, |min, line| {
|
||||||
|
let min = min.unwrap_or(usize::MAX);
|
||||||
|
Some(min.min(line.chars().take(min).take_while(|&c| c == ' ').count()))
|
||||||
|
}).unwrap_or(0);
|
||||||
|
|
||||||
|
let mut result = String::new();
|
||||||
|
for i in lines {
|
||||||
|
writeln!(result, "{}", &i[min..]).expect("Something went wrong unindenting the string");
|
||||||
|
}
|
||||||
|
result.pop();
|
||||||
|
result
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::replace_env_var_references;
|
use super::{replace_env_var_references, unindent};
|
||||||
use std;
|
use std;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -169,4 +187,12 @@ mod test {
|
||||||
format!("$test: {};", std::env::var("USER").unwrap_or_default())
|
format!("$test: {};", std::env::var("USER").unwrap_or_default())
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_unindent() {
|
||||||
|
let indented = "
|
||||||
|
line one
|
||||||
|
line two";
|
||||||
|
assert_eq!("line one\nline two", unindent(indented));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#![allow(clippy::option_map_unit_fn)]
|
#![allow(clippy::option_map_unit_fn)]
|
||||||
use super::{build_widget::BuilderArgs, circular_progressbar::*, run_command};
|
use super::{build_widget::BuilderArgs, circular_progressbar::*, run_command};
|
||||||
use crate::{
|
use crate::{
|
||||||
def_widget, enum_parse, error::DiagError, error_handling_ctx, util::list_difference, widgets::build_widget::build_gtk_widget,
|
def_widget, enum_parse, error::DiagError, error_handling_ctx, util::{list_difference, unindent}, widgets::build_widget::build_gtk_widget,
|
||||||
};
|
};
|
||||||
use anyhow::*;
|
use anyhow::*;
|
||||||
use codespan_reporting::diagnostic::Severity;
|
use codespan_reporting::diagnostic::Severity;
|
||||||
|
@ -601,7 +601,7 @@ fn build_gtk_label(bargs: &mut BuilderArgs) -> Result<gtk::Label> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let text = unescape::unescape(&text).context(format!("Failed to unescape label text {}", &text))?;
|
let text = unescape::unescape(&text).context(format!("Failed to unescape label text {}", &text))?;
|
||||||
let text = unindent::unindent(&text);
|
let text = unindent(&text);
|
||||||
gtk_widget.set_text(&text);
|
gtk_widget.set_text(&text);
|
||||||
},
|
},
|
||||||
// @prop markup - Pango markup to display
|
// @prop markup - Pango markup to display
|
||||||
|
|
Loading…
Add table
Reference in a new issue