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",
|
||||
"edit",
|
||||
"euphoxide",
|
||||
"linkify",
|
||||
"log",
|
||||
"open",
|
||||
"parking_lot",
|
||||
|
|
@ -545,6 +546,15 @@ dependencies = [
|
|||
"vcpkg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "linkify"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "96dd5884008358112bc66093362197c7248ece00d46624e2cf71e50029f8cff5"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lock_api"
|
||||
version = "0.4.7"
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ tokio = { version = "1.20.1", features = ["full"] }
|
|||
toml = "0.5.9"
|
||||
unicode-segmentation = "1.9.0"
|
||||
unicode-width = "0.1.9"
|
||||
linkify = "0.9.0"
|
||||
|
||||
[dependencies.time]
|
||||
version = "0.3.13"
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ use std::io;
|
|||
|
||||
use crossterm::event::KeyCode;
|
||||
use crossterm::style::{ContentStyle, Stylize};
|
||||
use linkify::{LinkFinder, LinkKind};
|
||||
|
||||
use crate::ui::input::{key, InputEvent, KeyBindingsList, KeyEvent};
|
||||
use crate::ui::widgets::list::ListState;
|
||||
|
|
@ -23,12 +24,14 @@ pub enum EventResult {
|
|||
|
||||
impl LinksState {
|
||||
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 {
|
||||
links: vec![
|
||||
"https://example.com/".to_string(),
|
||||
"https://plugh.de/".to_string(),
|
||||
],
|
||||
links,
|
||||
list: ListState::new(),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue