Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/text
diff options
context:
space:
mode:
authorSebastian Dröge <sebastian@centricular.com>2020-12-11 13:25:47 +0300
committerSebastian Dröge <sebastian@centricular.com>2020-12-11 13:25:47 +0300
commitb5796f5773450c03f190b7f9ced7f6560e0445ff (patch)
tree2adcb6eccac5beb73dd1d88c10f6799d2ce06c25 /text
parent09561686b86fbd719bfd1151f9fb76eebb6fa214 (diff)
textwrap: Update to textwrap 0.13
Diffstat (limited to 'text')
-rw-r--r--text/wrap/Cargo.toml2
-rw-r--r--text/wrap/src/gsttextwrap/imp.rs51
2 files changed, 24 insertions, 29 deletions
diff --git a/text/wrap/Cargo.toml b/text/wrap/Cargo.toml
index 20ae8cfbb..6b717af2e 100644
--- a/text/wrap/Cargo.toml
+++ b/text/wrap/Cargo.toml
@@ -10,7 +10,7 @@ repository = "https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs"
[dependencies]
glib = { git = "https://github.com/gtk-rs/gtk-rs" }
once_cell = "1.0"
-textwrap = { version = "0.12", features = ["hyphenation"] }
+textwrap = { version = "0.13", features = ["hyphenation"] }
hyphenation = "0.8"
[dependencies.gst]
diff --git a/text/wrap/src/gsttextwrap/imp.rs b/text/wrap/src/gsttextwrap/imp.rs
index 0f38ff78b..0ba9bc26e 100644
--- a/text/wrap/src/gsttextwrap/imp.rs
+++ b/text/wrap/src/gsttextwrap/imp.rs
@@ -95,28 +95,23 @@ impl Default for Settings {
}
}
-#[allow(clippy::large_enum_variant)]
-enum Wrapper {
- H(textwrap::Wrapper<'static, Standard>),
- N(textwrap::Wrapper<'static, textwrap::NoHyphenation>),
-}
+// FIXME: Not needed anymore after https://github.com/mgeisler/textwrap/pull/254
+#[derive(Debug)]
+struct Splitter(Box<dyn textwrap::WordSplitter + Send>);
-struct State {
- wrapper: Option<Wrapper>,
+impl textwrap::WordSplitter for Splitter {
+ fn split_points(&self, word: &str) -> Vec<usize> {
+ self.0.split_points(word)
+ }
}
-impl Wrapper {
- fn fill(&self, s: &str) -> String {
- match *self {
- Wrapper::H(ref w) => w.fill(s),
- Wrapper::N(ref w) => w.fill(s),
- }
- }
+struct State {
+ options: Option<textwrap::Options<'static, Splitter>>,
}
impl Default for State {
fn default() -> Self {
- Self { wrapper: None }
+ Self { options: None }
}
}
@@ -132,11 +127,11 @@ impl TextWrap {
let settings = self.settings.lock().unwrap();
let mut state = self.state.lock().unwrap();
- if state.wrapper.is_some() {
+ if state.options.is_some() {
return;
}
- state.wrapper = if let Some(dictionary) = &settings.dictionary {
+ state.options = if let Some(dictionary) = &settings.dictionary {
let dict_file = match File::open(dictionary) {
Err(err) => {
gst_error!(CAT, obj: element, "Failed to open dictionary file: {}", err);
@@ -159,15 +154,15 @@ impl TextWrap {
Ok(standard) => standard,
};
- Some(Wrapper::H(textwrap::Wrapper::with_splitter(
+ Some(textwrap::Options::with_splitter(
settings.columns as usize,
- standard,
- )))
+ Splitter(Box::new(standard)),
+ ))
} else {
- Some(Wrapper::N(textwrap::Wrapper::with_splitter(
+ Some(textwrap::Options::with_splitter(
settings.columns as usize,
- textwrap::NoHyphenation,
- )))
+ Splitter(Box::new(textwrap::NoHyphenation)),
+ ))
};
}
@@ -211,11 +206,11 @@ impl TextWrap {
let data = {
let state = self.state.lock().unwrap();
- let wrapper = state
- .wrapper
+ let options = state
+ .options
.as_ref()
.expect("We should have a wrapper by now");
- wrapper.fill(data)
+ textwrap::fill(data, options)
};
// If the lines property was set, we want to split the result into buffers
@@ -347,13 +342,13 @@ impl ObjectImpl for TextWrap {
let mut settings = self.settings.lock().unwrap();
let mut state = self.state.lock().unwrap();
settings.dictionary = value.get().expect("type checked upstream");
- state.wrapper = None;
+ state.options = None;
}
subclass::Property("columns", ..) => {
let mut settings = self.settings.lock().unwrap();
let mut state = self.state.lock().unwrap();
settings.columns = value.get_some().expect("type checked upstream");
- state.wrapper = None;
+ state.options = None;
}
subclass::Property("lines", ..) => {
let mut settings = self.settings.lock().unwrap();