mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-03-04 17:07:55 +00:00
27 lines
679 B
TypeScript
27 lines
679 B
TypeScript
import postRobot from "post-robot";
|
|
import create, { UseStore } from "zustand";
|
|
|
|
interface TerminalState {
|
|
terminalWindow: Window;
|
|
setTerminal: (terminalWindow: Window) => void;
|
|
sendMessage: (message: string) => void;
|
|
}
|
|
|
|
export const useTerminal: UseStore<TerminalState> = create((set, get) => ({
|
|
terminalWindow: undefined,
|
|
setTerminal: (terminalWindow: Window) => {
|
|
set({ terminalWindow });
|
|
},
|
|
sendMessage: (message: string) => {
|
|
const terminalWindow = get().terminalWindow;
|
|
postRobot.send(
|
|
terminalWindow,
|
|
"sendMessage",
|
|
{ type: "stdin", content: [message] },
|
|
{
|
|
domain: window.location.origin,
|
|
}
|
|
);
|
|
},
|
|
}));
|