AppStatus

Ditto

class AppStatus {}

Constructors

this
this(cstring app_name, cstring app_version, cstring app_build_date, cstring app_build_author, uint size, ulong ms_between_calls, OutputStream stream, TerminalOutput terminal_output, HeadingLineComponents heading_line_components, int terminal_columns)

Constructor. Saves the current time as the program start time.

Members

Aliases

TerminalOutput
alias TerminalOutput = .TerminalOutput

Convenience aliases for derived classes.

black
alias black = saveColour!(true, Terminal.Foreground.BLACK)
Undocumented in source.
black_bg
alias black_bg = saveColour!(false, Terminal.Background.BLACK)
Undocumented in source.
blue
alias blue = saveColour!(true, Terminal.Foreground.BLUE)
Undocumented in source.
blue_bg
alias blue_bg = saveColour!(false, Terminal.Background.BLUE)
Undocumented in source.
cyan
alias cyan = saveColour!(true, Terminal.Foreground.CYAN)
Undocumented in source.
cyan_bg
alias cyan_bg = saveColour!(false, Terminal.Background.CYAN)
Undocumented in source.
default_bg
alias default_bg = saveColour!(false, Terminal.Background.DEFAULT)

Convenience aliases for setting the background colour.

default_colour
alias default_colour = saveColour!(true, Terminal.Foreground.DEFAULT)

Convenience aliases for setting the foreground colour.

green
alias green = saveColour!(true, Terminal.Foreground.GREEN)
Undocumented in source.
green_bg
alias green_bg = saveColour!(false, Terminal.Background.GREEN)
Undocumented in source.
magenta
alias magenta = saveColour!(true, Terminal.Foreground.MAGENTA)
Undocumented in source.
magenta_bg
alias magenta_bg = saveColour!(false, Terminal.Background.MAGENTA)
Undocumented in source.
red
alias red = saveColour!(true, Terminal.Foreground.RED)
Undocumented in source.
red_bg
alias red_bg = saveColour!(false, Terminal.Background.RED)
Undocumented in source.
white
alias white = saveColour!(true, Terminal.Foreground.WHITE)
Undocumented in source.
white_bg
alias white_bg = saveColour!(false, Terminal.Background.WHITE)
Undocumented in source.
yellow
alias yellow = saveColour!(true, Terminal.Foreground.YELLOW)
Undocumented in source.
yellow_bg
alias yellow_bg = saveColour!(false, Terminal.Background.YELLOW)
Undocumented in source.

Enums

HeadingLineComponents
enum HeadingLineComponents

Set of components to show on the heading line.

Functions

bold
typeof(this) bold(bool is_bold)

Sets / unsets the configured boldness. This setting will be used when displaying the next streaming line or when formatting the next static line.

connectOutput
void connectOutput(OutputStream stream, TerminalOutput terminal_output)

Connects output for AppStatus to output. Useful if the output doesn't exist during entire lifetime of AppStatus.

connectedSocketHandler
void connectedSocketHandler(cstring[] command, void delegate(cstring) write_line, void delegate(ref mstring) read_line, IODevice socket)

UnixSocketExt's handler which connects the connected socket to the registered AppStatus instance, displays static lines and waits until user disconnects. The optional parameter is the wanted terminal width to assume.

disconnectOutput
void disconnectOutput()

Disconnects output from the AppStatus to output. All subsequent display* methods will be no-op.

displayStaticLines
void displayStaticLines()

Print the current static lines set by the calling program to this.terminal_output with a title line showing the current time, runtime, and memory and cpu usage and a footer line showing the version information.

displayStreamingLine
typeof(this) displayStreamingLine(cstring format, Args args)

Print a formatted streaming line above the static lines.

displayStreamingLine
typeof(this) displayStreamingLine()

Print the contents of this.msg as streaming line above the static lines.

eraseStaticLines
void eraseStaticLines()

Clear all the bottom static lines from the console (including header and footer).

formatStaticLine
typeof(this) formatStaticLine(uint index, cstring format, T args)

Format one of the static lines. The application can set the number of static lines either when constructing this module or by calling the 'num_static_lines' method. This method is then used to format the contents of the static lines.

getCpuUsage
void getCpuUsage(long usage)

Get the current cpu usage of this program. Uses the clock() method that returns the total current time used by this program. This is then used to compute the current cpu load of this program.

getMemoryUsage
bool getMemoryUsage(float mem_allocated, float mem_free)

Calculate the current memory usage of this program using the GC stats

getUptime
void getUptime(uint weeks, uint days, uint hours, uint mins, uint secs)

Get the current uptime for the program using the start time and current time. Then divide the uptime in to weeks, days, hours, minutes, and seconds.

num_static_lines
void num_static_lines(size_t size)

Resizes the number of lines in the app status static display and clears the current content of the static lines. Also resets the cursor position so that the static lines are still at the bottom of the display.

num_static_lines
size_t num_static_lines()

Gets the current number of lines in the app status static display.

printExtraVersionInformation
void printExtraVersionInformation(TerminalOutput output, char[] buffer, size_t max_length)

Prints additional text after the standard version info. The default implementation prints nothing, but sub-classes may override this method to provide specialised version information.

truncateLength
char[] truncateLength(char[] buffer)

Check the length of the buffer against the number of columns in the terminal. If the buffer is too long, set it to the terminal width.

truncateLength
char[] truncateLength(char[] buffer, size_t max)

Check the length of the buffer against the specified maximum length. If the buffer is too long, set it to maximum.

Variables

msg
StringBuffer msg;

Message buffer used for formatting streaming lines. The buffer is public so that, if more complex formatting is needed than is provided by the displayStreamingLine() methods, then it can be used externally to format any required messages. The version of displayStreamingLine() with no arguments can then be called to print the contents of the buffer.

Examples

void example ()
{
    static immutable number_of_static_lines = 2;
    static immutable ms_between_calls = 1000;

    AppStatus app_status = new AppStatus("test",
        "revision", "build_date", "build_author",
        number_of_static_lines, ms_between_calls);

    ulong c1, c2, c3, c4, c5, c6;

    app_status.formatStaticLine(0, "{} count1, {} count2", c1, c2);
    app_status.formatStaticLine(1, "{} count3, {} count4", c3, c4);

    app_status.displayStaticLines();

    app_status.displayStreamingLine("{} count5, {} count6", c5, c6);

    // The colour and boldness of the static/streaming lines can be
    // controlled in the following manner:

    app_status.bold.red
        .formatStaticLine(0, "this static line will be in red and bold");
    app_status.bold(false).green
        .formatStaticLine(1, "and this one will be in green and not bold");

    app_status.blue.displayStreamingLine("here's a blue streaming line");
}

Meta