Extract links from message
This commit is contained in:
parent
a1043eafd3
commit
8846234d8d
3 changed files with 19 additions and 5 deletions
10
Cargo.lock
generated
10
Cargo.lock
generated
|
|
@ -184,6 +184,7 @@ dependencies = [
|
||||||
"directories",
|
"directories",
|
||||||
"edit",
|
"edit",
|
||||||
"euphoxide",
|
"euphoxide",
|
||||||
|
"linkify",
|
||||||
"log",
|
"log",
|
||||||
"open",
|
"open",
|
||||||
"parking_lot",
|
"parking_lot",
|
||||||
|
|
@ -545,6 +546,15 @@ dependencies = [
|
||||||
"vcpkg",
|
"vcpkg",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "linkify"
|
||||||
|
version = "0.9.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "96dd5884008358112bc66093362197c7248ece00d46624e2cf71e50029f8cff5"
|
||||||
|
dependencies = [
|
||||||
|
"memchr",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lock_api"
|
name = "lock_api"
|
||||||
version = "0.4.7"
|
version = "0.4.7"
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ tokio = { version = "1.20.1", features = ["full"] }
|
||||||
toml = "0.5.9"
|
toml = "0.5.9"
|
||||||
unicode-segmentation = "1.9.0"
|
unicode-segmentation = "1.9.0"
|
||||||
unicode-width = "0.1.9"
|
unicode-width = "0.1.9"
|
||||||
|
linkify = "0.9.0"
|
||||||
|
|
||||||
[dependencies.time]
|
[dependencies.time]
|
||||||
version = "0.3.13"
|
version = "0.3.13"
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ use std::io;
|
||||||
|
|
||||||
use crossterm::event::KeyCode;
|
use crossterm::event::KeyCode;
|
||||||
use crossterm::style::{ContentStyle, Stylize};
|
use crossterm::style::{ContentStyle, Stylize};
|
||||||
|
use linkify::{LinkFinder, LinkKind};
|
||||||
|
|
||||||
use crate::ui::input::{key, InputEvent, KeyBindingsList, KeyEvent};
|
use crate::ui::input::{key, InputEvent, KeyBindingsList, KeyEvent};
|
||||||
use crate::ui::widgets::list::ListState;
|
use crate::ui::widgets::list::ListState;
|
||||||
|
|
@ -23,12 +24,14 @@ pub enum EventResult {
|
||||||
|
|
||||||
impl LinksState {
|
impl LinksState {
|
||||||
pub fn new(content: &str) -> Self {
|
pub fn new(content: &str) -> Self {
|
||||||
// TODO Extract links
|
let links = LinkFinder::new()
|
||||||
|
.links(content)
|
||||||
|
.filter(|l| *l.kind() == LinkKind::Url)
|
||||||
|
.map(|l| l.as_str().to_string())
|
||||||
|
.collect();
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
links: vec![
|
links,
|
||||||
"https://example.com/".to_string(),
|
|
||||||
"https://plugh.de/".to_string(),
|
|
||||||
],
|
|
||||||
list: ListState::new(),
|
list: ListState::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue