The ConsoleOutput Object

Command method processing routines use the various Write methods on ConsoleOutput in order to display text feedback during command processing. There are a number of different kinds of Write methods, including Write(), WriteLine(), WriteIndented(), WriteColored(), and WriteFormatted(). These methods may also have overloads which provide more variety in their usage.

Write() and WriteLine() output a simple string in the interpreter's current text color.

WriteIndented(), WriteColored(), and WriteIndentedColored() are good when you want a single line of output in a specified color and/or with a certain indent.

When you want to provide full formatting with various colors, lines, and spacing, use the WriteFormatted() method.

For more information on full formatting, see Framework Markup Format.

Example Ping Command with Formatted Output

<CommandMethod("Sends a test ICMP packet to a remote host.")>
<CommandMethodArgument("Remote Host", "The host name or IP address to ping")>
Public Shared Sub Ping(line As CommandLine)
    Dim pinger As New Ping
    Try
        Dim entry As IPHostEntry
        entry = Dns.GetHostEntry(line.ArgumentString.Trim)
        If entry IsNot Nothing Then
            Dim reply As PingReply = pinger.Send(entry.HostName)
            ConsoleOutput.WriteFormatted("\[r3]\[c6]Ping: \[c16]{0}\[c6] With: \[c16]{1} bytes\[c6] In: \[c16]{2} ms\[c6] Status: \[c16]{3}\[n]",
                                         reply.Address, reply.Buffer.Length, reply.RoundtripTime, reply.Status)
        Else
            line.SetResultMessage("Unknown Host", True)
        End If
    Catch ex As Exception
        line.SetResultMessage("Ping Error: " & ex.Message, True)
    Finally
        pinger.Dispose()
    End Try
End Sub

Last edited May 17, 2012 at 9:58 PM by ReedKimble, version 1

Comments

No comments yet.