Anyrun!
This commit is contained in:
67
anyrun-interface/src/lib.rs
Normal file
67
anyrun-interface/src/lib.rs
Normal file
@@ -0,0 +1,67 @@
|
||||
use abi_stable::{
|
||||
declare_root_module_statics,
|
||||
library::RootModule,
|
||||
package_version_strings,
|
||||
sabi_types::VersionStrings,
|
||||
std_types::{ROption, RString, RVec},
|
||||
StableAbi,
|
||||
};
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(StableAbi)]
|
||||
#[sabi(kind(Prefix(prefix_ref = PluginRef)))]
|
||||
#[sabi(missing_field(panic))]
|
||||
pub struct Plugin {
|
||||
pub init: extern "C" fn(RString),
|
||||
pub info: extern "C" fn() -> PluginInfo,
|
||||
pub get_matches: extern "C" fn(RString) -> u64,
|
||||
pub poll_matches: extern "C" fn(u64) -> PollResult,
|
||||
pub handle_selection: extern "C" fn(Match) -> HandleResult,
|
||||
}
|
||||
|
||||
/// Info of the plugin. Used for the main UI
|
||||
#[repr(C)]
|
||||
#[derive(StableAbi, Debug)]
|
||||
pub struct PluginInfo {
|
||||
pub name: RString,
|
||||
/// The icon name from the icon theme in use
|
||||
pub icon: RString,
|
||||
}
|
||||
|
||||
/// Represents a match from a plugin
|
||||
#[repr(C)]
|
||||
#[derive(StableAbi, Clone)]
|
||||
pub struct Match {
|
||||
pub title: RString,
|
||||
pub description: ROption<RString>,
|
||||
/// The icon name from the icon theme in use
|
||||
pub icon: RString,
|
||||
/// For runners to differentiate between the matches.
|
||||
pub id: u64,
|
||||
}
|
||||
|
||||
/// For determining how anyrun should proceed after the plugin has handled a match selection
|
||||
#[repr(C)]
|
||||
#[derive(StableAbi)]
|
||||
pub enum HandleResult {
|
||||
/// Shut down the program
|
||||
Close,
|
||||
/// Refresh the items. Useful if the runner wants to alter results in place.
|
||||
Refresh,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(StableAbi)]
|
||||
pub enum PollResult {
|
||||
Ready(RVec<Match>),
|
||||
Pending,
|
||||
Cancelled,
|
||||
}
|
||||
|
||||
impl RootModule for PluginRef {
|
||||
declare_root_module_statics! {PluginRef}
|
||||
|
||||
const BASE_NAME: &'static str = "anyrun_plugin";
|
||||
const NAME: &'static str = "anyrun_plugin";
|
||||
const VERSION_STRINGS: VersionStrings = package_version_strings!();
|
||||
}
|
Reference in New Issue
Block a user