Terminal | myPhysicsLab Docs

Constructors

constructor

  • new Terminal(term_input, term_output): Terminal
  • Parameters

    • term_input: null | HTMLInputElement
    • term_output: null | HTMLTextAreaElement

    Returns Terminal

Properties

afterErrorFn

afterErrorFn: (() => void)

Type declaration

    • (): void
    • Returns void

Private Optional afterEvalFn_

afterEvalFn_?: (() => void) = undefined

Type declaration

    • (): void
    • Returns void

Private Optional changeFn_

changeFn_?: ((e) => void) = undefined

Type declaration

    • (e): void
    • Parameters

      • e: Event

      Returns void

Private error

error: string

Private evalCalls_

evalCalls_: number = 0

Private hasAlerted_

hasAlerted_: boolean = false

Private histIndex_

histIndex_: number = -1

Private history_

history_: string[] = []

Private keyDownFn_

keyDownFn_: ((e) => void)

Type declaration

    • (e): void
    • Parameters

      • e: Event

      Returns void

Private prompt_

prompt_: string = '> '

Private regexs_

Private result

result: any = undefined

Private resultStack_

resultStack_: any[] = []

Private term_input_

term_input_: null | HTMLInputElement

Private term_output_

term_output_: null | HTMLTextAreaElement

vars_

vars_: string = ''

Private verbose_

verbose_: boolean = false

z

z: object = {}

Methods

addRegex

  • addRegex(names, prefix, opt_addToVars?, opt_prepend?): boolean
  • Parameters

    • names: string
    • prefix: string
    • Optional opt_addToVars: boolean
    • Optional opt_prepend: boolean

    Returns boolean

    whether the regex rule was added (returns false if the regex rule already exists)

addRegex2

  • addRegex2(regex, replace, opt_prepend?): boolean
  • Parameters

    • regex: RegExp
    • replace: string
    • Optional opt_prepend: boolean

    Returns boolean

    whether the regex rule was added (returns false if the regex rule already exists)

addToVars

  • addToVars(name): void
  • Parameters

    • name: string

    Returns void

alertOnce

  • alertOnce(msg): void
  • Parameters

    • msg: string

    Returns void

clear

  • clear(): void
  • Returns void

commands

  • commands(): string[]
  • Returns string[]

    array of command strings in current Terminal output

destroy

  • destroy(): void
  • Returns void

eval

  • eval(script, output?, showAlert?): any
  • Parameters

    • script: string
    • output: boolean = true
    • showAlert: boolean = true

    Returns any

    the result of executing the script

expand

  • expand(script): string
  • Parameters

    • script: string

    Returns string

    the script expanded by registered regular expressions

focus

  • focus(): void
  • Returns void

getError

  • getError(): string
  • Returns string

handleKey

  • handleKey(e): void
  • Parameters

    • e: Event

    Returns void

Private hasRegex

  • hasRegex(q): boolean
  • Returns boolean

    true if q is already on the list of regex's to execute.

Private inputCallback

  • inputCallback(_evt): void
  • Parameters

    • _evt: Event

    Returns void

parseURL

  • parseURL(): boolean
  • Returns boolean

    returns true if there was a URL query script

println

  • println(text): void
  • Parameters

    • text: string

    Returns void

Private replaceVar

  • replaceVar(script): string
  • Parameters

    • script: string

    Returns string

    the script with the var removed

scrollDown

  • scrollDown(): void
  • Returns void

setAfterEval

  • setAfterEval(afterEvalFn?): void
  • Parameters

    • Optional afterEvalFn: (() => void)
        • (): void
        • Returns void

    Returns void

setParser

  • setParser(parser): void
  • Returns void

setPrompt

  • setPrompt(prompt): void
  • Parameters

    • prompt: string

    Returns void

setVerbose

  • setVerbose(expand): void
  • Parameters

    • expand: boolean

    Returns void

Private splitAtSemicolon

  • splitAtSemicolon(text): string[]
  • Parameters

    • text: string

    Returns string[]

    array with two elements: array[0] = the section up to and including the first top-level semicolon; array[1] = the remaining text.

toString

  • toString(): string
  • Returns string

vars

  • vars(): string[]
  • Returns string[]

    names of defined variables, in alphabetic order

Static encodeURIComponent

  • encodeURIComponent(str): string
  • Parameters

    • str: string

    Returns string

    the encoded string

Static stdRegex

  • stdRegex(terminal): void
  • Returns void

Static version

  • version(): string
  • Returns string

    version information