1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//! Core types for running completions for your program
//!
//! See
//! - completest-pty
//! - completest-nu

#![cfg_attr(docsrs, feature(doc_auto_cfg))]

/// Terminal that shell's will run completions in
#[derive(Debug)]
pub struct Term {
    width: u16,
    height: u16,
}

impl Term {
    pub fn new() -> Self {
        Self {
            width: 120,
            height: 60,
        }
    }

    pub fn width(mut self, width: u16) -> Self {
        self.width = width;
        self
    }

    pub fn height(mut self, height: u16) -> Self {
        self.height = height;
        self
    }

    pub fn get_width(&self) -> u16 {
        self.width
    }

    pub fn get_height(&self) -> u16 {
        self.height
    }
}

impl Default for Term {
    fn default() -> Self {
        Self::new()
    }
}

pub trait RuntimeBuilder: std::fmt::Debug {
    type Runtime: Runtime;

    fn name() -> &'static str;

    fn new(
        bin_root: std::path::PathBuf,
        home: std::path::PathBuf,
    ) -> std::io::Result<Self::Runtime>;
    fn with_home(
        bin_root: std::path::PathBuf,
        home: std::path::PathBuf,
    ) -> std::io::Result<Self::Runtime>;
}

pub trait Runtime: std::fmt::Debug {
    fn home(&self) -> &std::path::Path;

    /// Register a completion script
    fn register(&mut self, name: &str, content: &str) -> std::io::Result<()>;

    /// Get the output from typing `input` into the shell
    fn complete(&mut self, input: &str, term: &Term) -> std::io::Result<String>;
}