Event exampleAn Event is similar to a trigger, but instead of firing when text from the server is received, it is fired internally by TeSSH when a certain situation occurs. For example, the "onConnect" event is fired when TeSSH connects to the server. There are several Pre-defined Events within TeSSH. You can also create your own user-defined events.

Simply use the #EVENT command to create your own event handler, and then use #RAISE to fire the event.

For example, you might want to detect when the server prompt is received from the server:

#TRIGGER {^(*)>} {#RAISE onPrompt %1} "" {prompt}

This will cause all "onPrompt" event handlers to fire, in any package, when the server prompt is received. Arguments are passed to the event handler, just like with aliases. In fact, the #EVENT command can use named-arguments, just like an alias. For example:

#EVENT onPrompt($curdir) {#IF (%left($curdir,5) = "[root") {#STYLE 0 "back:red"}}

This event handler checks the first argument (the current file path in the prompt) and sets the background color to red if in super-user mode (path starts with "[root"). You can create as many event handlers for each event as you want. You can even put these event handlers in different packages.

Add comment

Login or register to post comments