mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
Fix test
This commit is contained in:
parent
e5cc2d3682
commit
9ff25120a8
1 changed files with 7 additions and 4 deletions
|
|
@ -1,4 +1,4 @@
|
|||
use std::{borrow::Cow, collections::VecDeque, sync::LazyLock};
|
||||
use std::{borrow::Cow, collections::VecDeque, sync::OnceLock};
|
||||
|
||||
use regex::Regex;
|
||||
use serde::Deserialize;
|
||||
|
|
@ -6,7 +6,7 @@ use yazi_shared::event::Cmd;
|
|||
|
||||
use super::Key;
|
||||
|
||||
static RE: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"\s+").unwrap());
|
||||
static RE: OnceLock<Regex> = OnceLock::new();
|
||||
|
||||
#[derive(Debug, Default, Deserialize)]
|
||||
pub struct Control {
|
||||
|
|
@ -26,11 +26,14 @@ impl Control {
|
|||
pub fn on(&self) -> String { self.on.iter().map(ToString::to_string).collect() }
|
||||
|
||||
pub fn run(&self) -> String {
|
||||
RE.replace_all(&self.run.iter().map(|c| c.to_string()).collect::<Vec<_>>().join("; "), " ")
|
||||
RE.get_or_init(|| Regex::new(r"\s+").unwrap())
|
||||
.replace_all(&self.run.iter().map(|c| c.to_string()).collect::<Vec<_>>().join("; "), " ")
|
||||
.into_owned()
|
||||
}
|
||||
|
||||
pub fn desc(&self) -> Option<Cow<str>> { self.desc.as_ref().map(|s| RE.replace_all(s, " ")) }
|
||||
pub fn desc(&self) -> Option<Cow<str>> {
|
||||
self.desc.as_ref().map(|s| RE.get_or_init(|| Regex::new(r"\s+").unwrap()).replace_all(s, " "))
|
||||
}
|
||||
|
||||
pub fn desc_or_run(&self) -> Cow<str> { self.desc().unwrap_or_else(|| self.run().into()) }
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue