Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Spawnmon

Hierarchy

  • Spawnmon

Index

Constructors

constructor

Properties

commands

commands: Map<string, Command> = ...

groups

groups: {} = ...

Type declaration

Private indexes

indexes: Command[] = ...

inputCommand

inputCommand: Command

maxPrefix

maxPrefix: number = 0

options

Private prevChar

prevChar: any

robot

robot: { keyTap: any }

Type declaration

  • keyTap: function
    • keyTap(key: string, modifier?: string | string[]): void
    • Parameters

      • key: string
      • Optional modifier: string | string[]

      Returns void

Accessors

pids

  • get pids(): number[]

Methods

add

  • Inits a new command by options object without adding to group or instance.

    Parameters

    Returns Command

  • Inits existing Command without adding to group or instance. This method a bit circular used as normalizer may set defaults or other options in the future.

    Parameters

    • command: Command

      a command instance.

    • Optional as: string

      an optional alias for the command.

    Returns Command

  • Inits a new command by args without adding to group or commands.

    Parameters

    • command: string

      the command to be executed.

    • Optional args: string | string[]

      the arguments to be pased.

    • Optional as: string

      an alias name for the command.

    Returns Command

  • Inits a new command by args without adding to group or commands.

    Parameters

    • command: string

      the command to be executed.

    • Optional args: string | string[]

      the arguments to be pased.

    • Optional options: Omit<ICommandOptions, "command" | "args">

      additional command options.

    • Optional as: string

      an alias name for the command.

    Returns Command

ensure

  • Ensures that a command exists in the Spawnmon command instance.

    Parameters

    • command: string | Command

      the command to ensure.

    • Optional as: string

    Returns Spawnmon

Protected formatLines

  • formatLines(output: string, command?: string | Command): string
  • Formats string for log output.

    Parameters

    • output: string

      the data to be formatted.

    • Optional command: string | Command

    Returns string

get

  • A lookup and normalizer to find command. For most actions involving finding a command this method should be called as it simplifies the find.

    Parameters

    • command: string | Command

      the command name, alias or an instance of Command.

    • strict: boolean = false

      when false will get based on alias or command name.

    Returns Command

getCommandGroups

  • getCommandGroups(command: Command): string[]
  • getCommandGroups(command: Command, first: true): string
  • Gets the groups the command belongs to..

    Parameters

    • command: Command

      a command to get the group for.

    Returns string[]

  • Gets the first group the command belongs to..

    Parameters

    • command: Command

      a command to get the group for.

    • first: true

      when true gets only the first group.

    Returns string

getGroup

  • getGroup(...groups: string[]): Command[]
  • Gets commands for a group.

    Parameters

    • Rest ...groups: string[]

      the groups to get commands for.

    Returns Command[]

Protected getIndex

  • getIndex(command: string | Command): [number, number]
  • Gets the index of a command.

    Parameters

    • command: string | Command

      the command name, alias or instance to get an index for.

    Returns [number, number]

Protected getPrefix

  • getPrefix(command: string | Command, color?: string): string
  • Gets and formats the prefix for logging to output stream.

    Parameters

    • command: string | Command

      the command to get and format prefix for.

    • color: string = ...

      the color of the prefix if any.

    Returns string

Protected getPrefixKey

  • getPrefixKey(): string
  • Gets the prefix key from known keys in the prefix template.

    Returns string

handleInput

handleSignals

  • handleSignals(): void

has

  • has(command: string | Command): boolean
  • Checks if a the Spawnmon instance knows of the command.

    Parameters

    • command: string | Command

      the command name or Command instance.

    Returns boolean

hasGroup

  • hasGroup(group: string): boolean
  • Checks if commands have a specific group.

    Parameters

    • group: string

      the group to inpect if exists.

    Returns boolean

kill

  • kill(): any
  • kill(...commands: string[]): any
  • kill(...commands: Command[]): any

log

  • log(data: string | Error, command?: string | Command): Promise<void>
  • Outputs data to specified write stream.

    Parameters

    • data: string | Error

      the data or error to throw to write out to the write stream.

    • Optional command: string | Command

      the command instance or name requesting output.

    Returns Promise<void>

Protected padPrefix

  • padPrefix(prefix: string, offset: number, align?: "left" | "right" | "center"): string
  • Pads the prefix for display in console.

    Parameters

    • prefix: string

      the prefix to be padded.

    • offset: number

      the offset in spaces.

    • align: "left" | "right" | "center" = ...

      the alignment for the padding.

    Returns string

Protected prepareOutput

  • prepareOutput(data: any): string
  • Ensures data is as string and that we don't have unnecessary line returns.

    Parameters

    • data: any

      the data to be output.

    Returns string

remove

  • remove(command: string | Command): boolean
  • Removes a command from the instance. Not likely to be used but for good measure it's here, also removes from any assigned groups.

    Parameters

    • command: string | Command

      the command to be removed.

    Returns boolean

run

  • run(...commands: string[]): void
  • run(...commands: Command[]): void
  • Runs commands by name.

    Parameters

    • Rest ...commands: string[]

      the name of the commands to run in group.

    Returns void

  • Runs commands by instance.

    Parameters

    • Rest ...commands: Command[]

      the Command instances to run.

    Returns void

runGroup

  • runGroup(...groups: string[]): void
  • Runs by group name(s).

    Parameters

    • Rest ...groups: string[]

      additional groups to be run.

    Returns void

Protected setMaxPrefix

  • setMaxPrefix(commands: (string | Command)[]): number
  • Sets the maximum allowable prefix VALUE length based on prefix key type. This is NOT based on the length of the entire prefix but rather the defined value e.g. index, command name, pid or timestamp.

    Parameters

    • commands: (string | Command)[]

      list of command names or Command instances.

    Returns number

write

  • write(data: string): Promise<boolean>

Generated using TypeDoc