useShell

Executes a shell command declared in fluxlay.yaml and optionally renders the output in an xterm terminal.

Import

import { useShell } from "@fluxlay/react";

Signature

function useShell(commandId: string, options?: UseShellOptions): UseShellReturn;

Parameters

ParameterTypeDescription
commandIdstringThe command ID declared in the shell section of fluxlay.yaml.
optionsUseShellOptionsOptional configuration.

UseShellOptions

PropertyTypeDefaultDescription
refreshIntervalnumber30000Interval in milliseconds to re-execute the command.
showStdoutbooleantrueWrite stdout to the terminal.
showStderrbooleanfalseWrite stderr to the terminal.
terminalTerminalInstance | nullundefinedTerminal instance from useTerminal() to render output.
columnsnumberPseudo-terminal column width.
linesnumberPseudo-terminal line height.

Return Value

PropertyTypeDescription
execute() => Promise<void>Manually trigger command execution.
isRunningbooleanWhether the command is currently executing.
errorstring | nullError message if execution failed.
resultShellResult | nullResult of the last execution.

ShellResult

PropertyTypeDescription
successbooleanWhether the command exited with status 0.
stdoutstringStandard output.
stderrstringStandard error.
statusCodenumber | nullExit status code, or null if the process was terminated by a signal.
signalnumber | nullSignal number that terminated the process, or null if it exited normally.

Example

With Terminal

const { terminalRef, instance } = useTerminal({
  theme: TerminalThemes.nord
});
 
const { error } = useShell("macchina", {
  terminal: instance,
  refreshInterval: 60000
});

Without Terminal

const { result, isRunning } = useShell("fetch-ip", {
  refreshInterval: 10000
});
 
return <p>{result?.stdout}</p>;

Behavior

  • Executes once on mount.
  • Re-executes when commandId changes.
  • Re-executes at refreshInterval intervals if set.
  • If a terminal instance is provided, output is written to the terminal with ANSI support.