aboutsummaryrefslogtreecommitdiff
path: root/mingling_core/src/program/hook/hook_info.rs
blob: 060e368fb5f50224a8173975d2c581a089fe6ff8 (plain) (blame)
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
use crate::{AnyOutput, ProgramCollect, RenderResult};

/// Represents the data passed to `begin` hook.
pub struct HookBeginInfo {}

/// Represents the data passed to `pre_dispatch` hook.
pub struct HookPreDispatchInfo<'a> {
    /// Arguments entered by the user before dispatching
    pub arguments: &'a [String],
}

/// Represents the data passed to `post_dispatch` hook.
pub struct HookPostDispatchInfo<'a, C>
where
    C: ProgramCollect<Enum = C>,
{
    /// The entry point of dispatching
    pub entry: &'a C,
}

/// Represents the data passed to `pre_chain` hook.
pub struct HookPreChainInfo<'a, C>
where
    C: ProgramCollect<Enum = C>,
{
    /// Input to the chain
    pub input: &'a C,

    /// Raw data
    pub raw: &'a dyn std::any::Any,
}

/// Represents the data passed to `post_chain` hook.
pub struct HookPostChainInfo<'a, C>
where
    C: ProgramCollect<Enum = C>,
{
    /// Output of the chain
    pub output: &'a AnyOutput<C>,
}

/// Represents the data passed to `pre_render` hook.
pub struct HookPreRenderInfo<'a, C>
where
    C: ProgramCollect<Enum = C>,
{
    /// Render input
    pub input: &'a C,

    /// The raw data to be rendered
    pub raw: &'a dyn std::any::Any,
}

/// Represents the data passed to `post_render` hook.
pub struct HookPostRenderInfo<'a> {
    /// The rendering result
    pub result: &'a RenderResult,
}

/// Represents the data passed to `finish` hook.
pub struct HookFinishInfo {}

/// Represents the data passed to `exec_panic` hook.
#[cfg(not(feature = "async"))]
pub struct HookPanicInfo<'a> {
    /// Raw data of the panic
    pub panic: &'a crate::error::ProgramPanic,
}

#[cfg(feature = "repl")]
mod repl_hook {
    use crate::RenderResult;

    /// Represents the data passed to `repl_on_begin` hook.
    pub struct HookREPLBeginInfo {}

    /// Represents the data passed to `repl_pre_readline` hook.
    pub struct HookREPLPreReadlineInfo {}

    /// Represents the data passed to `repl_readline` hook.
    pub struct HookREPLReadlineInfo {}

    /// Represents the data passed to `repl_post_readline` hook.
    pub struct HookREPLPostReadlineInfo<'a> {
        /// The read line (mutable for editing)
        pub line: &'a mut String,
    }

    /// Represents the data passed to `repl_pre_exec` hook.
    pub struct HookREPLPreExecInfo<'a> {
        /// Arguments for the command
        pub args: &'a [String],
    }

    /// Represents the data passed to `repl_post_exec` hook.
    pub struct HookREPLPostExecInfo {}

    /// Represents the data passed to `repl_on_receive_result` hook.
    pub struct HookREPLOnReceiveResultInfo<'a> {
        /// The rendering result
        pub result: &'a RenderResult,
    }

    /// Represents the data passed to `repl_exit` hook.
    pub struct HookREPLExitInfo {}

    /// Represents the data passed to `repl_loop_once` hook.
    pub struct HookREPLLoopOnceInfo {}

    /// Represents the data passed to `repl_on_panic` hook.
    #[cfg(not(feature = "async"))]
    pub struct HookREPLOnPanicInfo<'a> {
        /// Raw data of the panic
        pub panic: &'a crate::error::ProgramPanic,
    }
}

#[cfg(feature = "repl")]
pub use repl_hook::*;