PCL
|
A high-level interface to a PixInsight processing console. More...
#include <Console.h>
Public Member Functions | |
Console () | |
Console (Console &&x) | |
Console (const Console &)=delete | |
virtual | ~Console () |
void | Abort () |
bool | AbortEnabled () const |
bool | AbortRequested () const |
void | Clear () |
void | Critical (const String &s) |
void | CriticalLn (const String &s) |
void | DisableAbort () |
void | EnableAbort () |
void | ExecuteScript (const String &filePath, const StringKeyValueList &arguments=StringKeyValueList()) |
void | ExecuteScriptGlobal (const String &filePath, const StringKeyValueList &arguments=StringKeyValueList()) |
void | ExecuteScriptOn (const View &view, const String &filePath, const StringKeyValueList &arguments=StringKeyValueList()) |
void | Flush () |
bool | Hide (bool hide=true) |
bool | IsCurrentThreadConsole () const |
bool | IsValid () const |
void | Note (const String &s) |
void | NoteLn (const String &s) |
Console & | operator= (Console &&x) |
Console & | operator= (const Console &)=delete |
int | ReadChar () |
String | ReadString () |
void | ResetStatus () |
bool | Show (bool show=true) |
bool | Suspended () const |
bool | Waiting () const |
void | Warning (const String &s) |
void | WarningLn (const String &s) |
void | Write (const String &s) |
void | WriteLn () |
void | WriteLn (const String &s) |
The PixInsight platform provides three different user interfaces implemented in the PixInsight core application: a graphical user interface (GUI), a scripting interface (the PixInsight JavaScript runtime), and a command-line interface. The Console class is a high-level abstraction that represents the Process Console window of the PixInsight core application, which implements the entire command-line and console text input/output functionality in PixInsight.
A module can instantiate Console to perform direct text input/output operations. Console objects are often used to display information about ongoing processes, to let the user abort a process, or to put a process in a wait state to perform a modal user interface operation (e.g., showing a message box) in a thread-safe way.
From the module developer perspective, each module has an associated console. Such associations between modules and consoles are managed automatically by internal core and PCL routines: module developers just need to instantiate the Console class and use its member functions.
For example, writing a message to the console can be as simple as:
Stream-style console insertion and extraction operators are also available. For example, this is equivalent to the above code:
When you need to output formatted data, you can use the String::Format() family of functions. These functions are similar to the standard printf() C runtime function:
PixInsight consoles can understand and reproduce the full set of ISO-8859-1 HTML entities. You see an example on the code fragment above: the "°"
entity prints a degree symbol on the console.
PixInsight consoles can also interpret a number of tags, similar to HTML, to perform special actions and formatting operations. For example:
In this example, the "<end>" tag moves the cursor after the last character in the console, then the "<cbr>" tag (conditional break) generates a new line only if the current line is not empty. This ensures that subsequent text output will start on an empty line at the end of the current console contents. The "<b>" and "</b>" tags write text in a bold type face, and the "<i>" and "</i>" pair write text in italics. This is just a minimal fraction of the rich set of tags understood by PixInsight consoles.
As we describe in detail below, PixInsight consoles support standard ANSI escape codes, and can also be used to render inline HTML contents.
It must be pointed out that the entire text output functionality of Console is also available for TextBox controls. A module can instantiate a TextBox control to provide rich text-based output as a process log, the output of an external process, or an information panel based on HTML tables, just to name a few possibilities implemented frequently.
Here is a comprehensive list of supported console tags at the time of publishing this documentation. New functionality implemented through console tags will be documented here as new versions are released.
<b></b> | Enables/disables bold text. |
<i></i> | Enables/disables italics text. |
<u></u> | Enables/disables underlined text. |
<o></o> | Enables/disables overlined text. |
<sub></sub> | Enables/disables subscript text. |
<sup></sup> | Enables/disables superscript text. |
<br> | Line break. |
<br/> | Line break, XML compliant (same as <br>). |
<cbr> | Conditional line break: sends a line break if the cursor is not at the beginning of an empty line. |
<cbr/> | Conditional line break, XML compliant (same as <cbr>). |
<bsp> | Backspace: deletes the previous character and moves the cursor one step left, only if it is not at the beginning of a line. |
<end> | Moves the cursor to the end of the console. |
<beg> | Moves the cursor to the beginning of the console. |
<bwd> | Moves the cursor to the previous character, only if it is not at the beginning of a line. |
<fwd> | Moves the cursor to the next character, only if it is not at the end of a line. |
<eol> | Moves the cursor to the end of the current line. |
<bol> | Moves the cursor to the beginning of the current line. |
<up> | Moves the cursor to the previous line, if it is not already at the first line. |
<down> | Moves the cursor to the next line, if it is not already at the last line. |
<clr> | Clears the console. Avoid issuing this tag arbitrarily - please see the documentation for Console::Clear() for more information. |
<clreol> | Deletes the text from the current cursor position (included) to the end of the current line. |
<clrbol> | Deletes the text from the current cursor position (included) to the beginning of the current line. |
<clrend> | Deletes the text from the current cursor position (included) to the end of the console. |
<clrbeg> | Deletes the text from the current cursor position (included) to the beginning of the console. Avoid issuing this tag arbitrarily - please see the documentation for Console::Clear() for more information. |
<nowrap></nowrap> | Disables/enables word wrapping of text lines. |
<notags></notags> | Disables/enables tag interpretation, except the </notags> tag, which is always interpreted. |
<noentities></noentities> | Disables/enables interpretation of ISO-8859-1 entities. |
<raw></raw> | Disables/enables interpretation of tags, except the </raw> tag, and ISO-8859-1 entities. <raw> is equivalent to (but faster than) <noentities><notags>. |
<code></code> | Equivalent to <monospace><raw>. Useful to show source code fragments. |
<monospace> | Selects a platform-dependent, monospaced font. |
<sans> | Selects a platform-dependent, sans-serif font. |
<serif> | Selects a platform-dependent, serif font. |
<courier> | Selects the Courier font, or the nearest available monspaced font, depending on the platform. |
<helvetica> | Selects the Helvetica font, or the nearest available sans-serif font, depending on the platform. |
<times> | Selects the Times font, or the nearest available serif font, depending on the platform. |
<default-font> | Selects the default console font (usually a monospaced font; but user-selectable through preferences). |
<reset-font> | Resets all text settings and styles to default values. |
<show> | If this console corresponds to the processing console window, shows it if it's currently hidden and docked in the PixInsight core application window; otherwise this tag is ignored. Equivalent to calling the Console::Show() member function. |
<hide> | If this console corresponds to the processing console window, hides it if it's currently visible and docked in the PixInsight core application window; otherwise this tag is ignored. Equivalent to calling the Console::Hide() member function. |
<flush> | Causes any pending data to be written immediately to the console. If there is no unwritten data for this console, this tag has no effect. Equivalent to calling the Console::Flush() member function. |
<html></html> | Enables/disables HTML mode. In HTML mode, the console interprets and renders a comprehensive set of HTML 4 tags, including full support of tables, as well as a significant part of Level 2 CSS (Cascading Style Sheets) directives. In HTML mode, PixInsight console tags are either ignored or interpreted with their corresponding meaning in HTML 4. |
In addition, the \n, \r and \b escape characters can be used in place of the <br>, <bol> and <bsp> tags, respectively.
PixInsight consoles fully recognize and interpret the whole set of HTML 4 character entities, including all ISO 8859-1 characters and all character entities for symbols, mathematical symbols, Greek letters, markup-significant and internationalization characters.
Character entities are of the form:
<entity-name>;
where <entity-name> is one of the references included in the following W3C Recommendation document:
http://www.w3.org/TR/REC-html40/sgml/entities.html
The <html> tag allows you to put a PixInsight console in HTML mode. In this mode you can embed HTML 4 contents directly. For example, this code:
generates an HTML table with two rows and two columns. PixInsight consoles support most of the HTML 4 specification, including a subset of CSS2. For detaled information, this document describes HTML support in Qt, which is the underlying implementation in current versions of PixInsight:
http://qt-project.org/doc/qt-4.8/richtext-html-subset.html
In HTML mode, that is, within a pair of <html></html> tags, no PixInsight console tags or ANSI escape codes are recognized or interpreted.
Since version 1.8.1 of the PixInsight core application, PixInsight consoles support a large set of ANSI CSI (Control Sequence Introducer) codes. For a detailed description of ANSI escape codes, refer to the following documents:
http://en.wikipedia.org/wiki/ANSI_escape_code http://invisible-island.net/xterm/ctlseqs/ctlseqs.html
The following table describes the supported CSI codes in the current version of PixInsight. ESC represents the escape control character, whose ASCII code is 2710 = 1B16. The CSI sequence is ESC followed by the left square bracket character, represented as the ESC[ sequence. See the examples given at the end of the table.
ESC[ n A | Cursor up n Times (default n=1) (CUU) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
ESC[ n B | Cursor down n Times (default n=1) (CUD) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
ESC[ n C | Cursor forward n Times (default n=1) (CUF) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
ESC[ n D | Cursor backward n Times (default n=1) (CUB) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
ESC[ n E | Cursor to next line n Times (default n=1) (CNL) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
ESC[ n F | Cursor to preceding line n Times (default n=1) (CPL) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
ESC[ n G | Cursor to character absolute column n (default n=1) (CHA) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
ESC[ n;m H | Cursor position to row n and column m (default n=m=1) (CUP) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
ESC[ n;m f | Horizontal & Vertical Position (HVP). Same as H. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
ESC[ n J | Erase in Display (ED)
| ||||||||||||||||||||||||||||||||||||||||||||||||||||
ESC[ n K | Erase in Line (EL)
| ||||||||||||||||||||||||||||||||||||||||||||||||||||
ESC[ n L | Insert n line(s) (default n=1) (IL) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
ESC[ n M | Delete n line(s) (default n=1) (DL) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
ESC[ n P | Delete n character(s) (default n=1) (DCH) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
ESC[ ... m | Set graphics rendition (SGR)
| ||||||||||||||||||||||||||||||||||||||||||||||||||||
ESC[s | Save Cursor Position (SCP) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
ESC[u | Restore Cursor Position (RCP) |
KDE Konsole 24-bit colors use the following format:
Select RGB foreground color: ESC[ ... 38;2;r;g;b ... m
Select RGB background color: ESC[ ... 48;2;r;g;b ... m
where r, g and b are the red, green and blue components in the [0,255] range. For detailed information on these codes, see the following document:
Examples
Write a text line using a bold font:
Write a text line in orange color using an italic font:
Write some text at the beginning of the current line, removing any previous contents:
pcl::Console::Console | ( | ) |
Constructs a Console object.
|
delete |
Copy constructor, disabled because Console instances represent unique objects that cannot be copied.
|
inline |
|
virtual |
Destroys a Console object.
void pcl::Console::Abort | ( | ) |
Accepts a pending abort request.
bool pcl::Console::AbortEnabled | ( | ) | const |
Returns true iff the current processing thread can be aborted by the user.
bool pcl::Console::AbortRequested | ( | ) | const |
Returns true iff the user has requested to abort execution of the current processing thread.
void pcl::Console::Clear | ( | ) |
Clears the console. This is a convenience function that simply writes the <clr> tag to the console.
|
inline |
|
inline |
Writes a critical error message to this console and appends a newline escape character ('\n').
See the description of Critical( const String& ).
void pcl::Console::DisableAbort | ( | ) |
Disables abort requests for the current processing thread.
void pcl::Console::EnableAbort | ( | ) |
Enables abort requests for the current processing thread.
void pcl::Console::ExecuteScript | ( | const String & | filePath, |
const StringKeyValueList & | arguments = StringKeyValueList() |
||
) |
Executes a script file.
filePath | Path to the script file that will be executed. Must be a path to an existing script on the local filesystem. |
arguments | A dynamic array, possibly empty, of StringKeyValue objects. Each object in this array represents a script argument. The key member is the parameter name, and the value member is the corresponding parameter value. |
The core application will load, parse, authorize and execute the specified script file. The scripting language will be detected automatically from the file name suffix in filePath. Currently the .scp and .js suffixes are interpreted for command-line shell scripts and JavaScript scripts, respectively. Future versions may accept more languages and apply language detection heuristics besides file suffixes.
This member function returns normally if the script was loaded and executed. In the event of error, for example if the specified file does not exist or can't be accessed, or in the event of security errors or failure to authorize script execution from the calling module, this member function throws an Error exception.
Note that command-line or JavaScript runtime execution errors cannot be reported by this function. That means that this function knows nothing about whether the script worked or not correctly, or if it did what was expected.
For execution of JavaScript scripts, this function is equivalent to ExecuteScriptGlobal(), that is, JavaScript scripts are always executed in the global context by default. When executed, the JavaScript script will see the following static properties of the Parameters JS runtime object:
Parameters.isGlobalTarget
will be set to true.
Parameters.isViewTarget
will be set to false.
Parameters.targetView
will be set to undefined
.
See ExecuteScriptOn() for execution of scripts in view contexts.
void pcl::Console::ExecuteScriptGlobal | ( | const String & | filePath, |
const StringKeyValueList & | arguments = StringKeyValueList() |
||
) |
Executes a script file in the global context. This is the default execution execution mode for all scripts.
When a JavaScript script is executed through this member function, the following static properties of the Parameters runtime object will be defined as described below:
Parameters.isGlobalTarget
will be set to true.
Parameters.isViewTarget
will be set to false.
Parameters.targetView
will be set to undefined
.
See ExecuteScript() for a detailed description of script execution from PCL/C++ code.
void pcl::Console::ExecuteScriptOn | ( | const View & | view, |
const String & | filePath, | ||
const StringKeyValueList & | arguments = StringKeyValueList() |
||
) |
Executes a script file in the context of the specified view.
When a JavaScript script is executed through this member function, the following static properties of the Parameters runtime object will be defined as described below:
Parameters.isGlobalTarget
will be set to false.
Parameters.isViewTarget
will be set to true.
Parameters.targetView
will reference the specified view.
See ExecuteScript() for a detailed description of script execution from PCL/C++ code.
void pcl::Console::Flush | ( | ) |
Causes any pending data to be written immediately to this console. If there is no unwritten data for this console, this function has no effect.
|
inline |
Hides the Process Console window in the PixInsight core application.
This is a convenience function, equivalent to: Show( !hide )
Returns true iff the console could be hidden (or shown) successfully. Refer to the Show() member function for more information.
bool pcl::Console::IsCurrentThreadConsole | ( | ) | const |
Returns true iff this console is valid and has been created by the calling thread; either by the root thread or by a running Thread object.
bool pcl::Console::IsValid | ( | ) | const |
Returns true iff this is a valid console object associated to an active processing thread.
|
inline |
|
inline |
Writes an informative note message to this console and appends a newline escape character ('\n').
See the description of Note( const String& ).
Copy assignment operator, disabled because Console instances represent unique objects that cannot be copied.
int pcl::Console::ReadChar | ( | ) |
Reads a single character from this console and returns it.
This function puts the current thread in wait state, then waits until a character can be obtained in the core application's GUI thread. This usually involves waiting for a keyboard event.
Referenced by pcl::operator>>().
String pcl::Console::ReadString | ( | ) |
Reads a string from this console and returns it.
This function puts the current thread in wait state, then opens a simple modal dialog box with a single-line edit control, where the user may enter a string. If the user cancels the input dialog, an empty string is returned.
Referenced by pcl::operator>>().
void pcl::Console::ResetStatus | ( | ) |
Resets the current processing thread status.
This function is useful to ignore an abort request for the current processing thread. For example, if the user requests to abort execution, a module may ask if she or he really wants to cancel, and if the user answers 'No', then this member function can be called to clear the existing abort request condition.
bool pcl::Console::Show | ( | bool | show = true | ) |
Shows the Process Console window in the PixInsight core application.
The visibility of a console can only be controlled if it is the process console window. Furthermore, a module cannot show or hide the console if it is not owned by a docked window; the visibility of a floating window cannot be changed programmatically from a module.
This function returns true if the console could be shown (or hidden) successfully. Unlike most interface operations, console hide/show operations are not cached, so if this function returns true then you know that the Process Console window is currently visible.
bool pcl::Console::Suspended | ( | ) | const |
Returns true iff the current processing thread has been suspended by the PixInsight core application.
bool pcl::Console::Waiting | ( | ) | const |
Returns true iff the current processing thread is in wait state.
|
inline |
|
inline |
Writes a warning message to this console and appends a newline escape character ('\n').
See the description of Warning( const String& ).
void pcl::Console::Write | ( | const String & | s | ) |
Writes an Unicode string s to this console.
Referenced by pcl::operator<<().
void pcl::Console::WriteLn | ( | ) |
Sends a single newline escape character ('\n') to the console.
Note that this function is faster than writing a newline directly with a call to Write( '\n' ).
void pcl::Console::WriteLn | ( | const String & | s | ) |
Writes an Unicode string s to this console and appends a newline escape character ('\n').
Note that this function is faster than appending a newline character to the string, such as a call to Write( s + '\n' ).