feat(rink): extract description from result (#37)
This splits the rink result to move the bracketed text into the description, meaning copying the result will not contain text such as `(dimensionless)` or `(length)`, while still keeping this information present.
This commit is contained in:
		| @@ -43,14 +43,17 @@ fn info() -> PluginInfo { | ||||
| #[get_matches] | ||||
| fn get_matches(input: RString, ctx: &mut rink_core::Context) -> RVec<Match> { | ||||
|     match rink_core::one_line(ctx, &input) { | ||||
|         Ok(result) => vec![Match { | ||||
|             title: result.into(), | ||||
|             description: ROption::RNone, | ||||
|             use_pango: false, | ||||
|             icon: ROption::RNone, | ||||
|             id: ROption::RNone, | ||||
|         }] | ||||
|         .into(), | ||||
|         Ok(result) => { | ||||
|             let (title, desc) = parse_result(result); | ||||
|             vec![Match { | ||||
|                 title: title.into(), | ||||
|                 description: desc.map(RString::from).into(), | ||||
|                 use_pango: false, | ||||
|                 icon: ROption::RNone, | ||||
|                 id: ROption::RNone, | ||||
|             }] | ||||
|             .into() | ||||
|         } | ||||
|         Err(_) => RVec::new(), | ||||
|     } | ||||
| } | ||||
| @@ -59,3 +62,17 @@ fn get_matches(input: RString, ctx: &mut rink_core::Context) -> RVec<Match> { | ||||
| fn handler(selection: Match) -> HandleResult { | ||||
|     HandleResult::Copy(selection.title.into_bytes()) | ||||
| } | ||||
|  | ||||
| /// Extracts the title and description from `rink` result. | ||||
| /// The description is anything inside brackets from `rink`, if present. | ||||
| fn parse_result(result: String) -> (String, Option<String>) { | ||||
|     result | ||||
|         .split_once(" (") | ||||
|         .map(|(title, desc)| { | ||||
|             ( | ||||
|                 title.to_string(), | ||||
|                 Some(desc.trim_end_matches(')').to_string()), | ||||
|             ) | ||||
|         }) | ||||
|         .unwrap_or((result, None)) | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Jake Stanger
					Jake Stanger