tastty-core 0.1.0

Sans-IO core of the tastty terminal session library: VT parser, screen buffer, and byte encoders.
use std::sync::Arc;

use super::super::Screen;

pub(in crate::screen) fn handle_set(screen: &mut Screen, params: &[&[u8]]) {
    // Only `id=` in the colon-separated params slot is spec-defined;
    // unknown keys are silently dropped per OSC 8.
    let uri = params.get(2).copied().unwrap_or(b"");
    if uri.is_empty() {
        screen.hyperlink = None;
    } else {
        let id = params.get(1).and_then(|raw| parse_id(raw));
        let uri = String::from_utf8_lossy(uri);
        screen.hyperlink = Some(Arc::new(crate::cell::Hyperlink {
            id,
            uri: Arc::from(uri.as_ref()),
        }));
    }
}

fn parse_id(raw: &[u8]) -> Option<Arc<str>> {
    for segment in raw.split(|&b| b == b':') {
        let mut split = segment.splitn(2, |&b| b == b'=');
        let key = split.next()?;
        if key == b"id"
            && let Some(value) = split.next()
            && !value.is_empty()
        {
            let s = String::from_utf8_lossy(value);
            return Some(Arc::from(s.as_ref()));
        }
    }
    None
}