Skip to content

Latest commit

 

History

History
60 lines (46 loc) · 1.56 KB

File metadata and controls

60 lines (46 loc) · 1.56 KB

Examples

The crate ships with minimal examples that compile with the public API.

Included Examples

  • crates/plugin-api/examples/info-plugin.rs
  • crates/plugin-api/examples/logo-animation-plugin.rs

Info Provider Example

use serde::Deserialize;
use xfetch_plugin_api::{read_info_plugin_args_or_default, write_info_lines};

#[derive(Debug, Default, Deserialize)]
struct ExampleArgs {
    label: Option<String>,
}

fn main() {
    let args = match read_info_plugin_args_or_default::<ExampleArgs>() {
        Ok(value) => value,
        Err(err) => {
            eprintln!("{}", err);
            std::process::exit(1);
        }
    };

    let label = args.label.unwrap_or_else(|| "example".to_string());

    if let Err(err) = write_info_lines(vec![format!("plugin says: {}", label)]) {
        eprintln!("{}", err);
        std::process::exit(1);
    }
}

Logo Animation Example

use xfetch_plugin_api::{AnimationFrame, read_logo_animation_request, write_logo_animation_frames};

fn main() {
    let request = match read_logo_animation_request() {
        Ok(value) => value,
        Err(err) => {
            eprintln!("{}", err);
            std::process::exit(1);
        }
    };

    let frames = vec![AnimationFrame::new(80, request.lines)];

    if let Err(err) = write_logo_animation_frames(frames) {
        eprintln!("{}", err);
        std::process::exit(1);
    }
}