From 197861b4c85c8dd06d3507ab1f4fb6fb846d4703 Mon Sep 17 00:00:00 2001 From: lisiur Date: Mon, 15 May 2023 09:17:55 +0800 Subject: [PATCH] feat(plugin): add host-print --- service/src/plugin/mod.rs | 7 +++++++ service/src/plugin/wit/host.wit | 1 + 2 files changed, 8 insertions(+) diff --git a/service/src/plugin/mod.rs b/service/src/plugin/mod.rs index 8d5d61f..5905661 100644 --- a/service/src/plugin/mod.rs +++ b/service/src/plugin/mod.rs @@ -1,3 +1,4 @@ +use std::io::Write; use std::time::Duration; use crate::services::plugin::PluginService; @@ -127,6 +128,12 @@ impl Host_Imports for RunningPluginState { async fn host_select(&mut self, options: Vec) -> wasmtime::Result> { Ok(self.select(options.iter().map(|x| x.as_str()).collect())) } + + async fn host_print(&mut self, message: String) -> wasmtime::Result<()> { + print!("{}", message); + std::io::stdout().flush().unwrap(); + Ok(()) + } } pub struct RunningPlugin { diff --git a/service/src/plugin/wit/host.wit b/service/src/plugin/wit/host.wit index 7022480..b1e49e0 100644 --- a/service/src/plugin/wit/host.wit +++ b/service/src/plugin/wit/host.wit @@ -6,6 +6,7 @@ default world host { import host-loading: func(loading: bool) import host-input: func(prompt: string) -> option import host-select: func(options: list) -> option + import host-print: func(message: string) export run: func() }