xtd 0.2.0
Loading...
Searching...
No Matches

◆ cursor_top() [1/2]

static int32 xtd::console::cursor_top ( )
static

Gets the row position of the cursor within the buffer area.

Returns
The current position, in rows, of the cursor.
Examples
This example demonstrates the cursor_left and cursor_top properties, and the set_cursor_position and clear methods. The example positions the cursor, which determines where the next write will occur, to draw a 5 character by 5 character rectangle using a combination of "+", "|", and "-" strings. Note that the rectangle could be drawn with fewer steps using a combination of other strings.
#include <xtd/console>
using namespace xtd;
auto orig_row = 0;
auto orig_col = 0;
void write_at(const string& s, int x, int y) {
console::set_cursor_position(orig_col + x, orig_row + y);
}
auto main() -> int {
// Clear the screen, then save the top and left coordinates.
orig_row = console::cursor_top();
orig_col = console::cursor_left();
// Draw the left side of a 5x5 rectangle, from top to bottom.
write_at("+", 0, 0);
write_at("|", 0, 1);
write_at("|", 0, 2);
write_at("|", 0, 3);
write_at("+", 0, 4);
// Draw the bottom side, from left to right.
write_at("-", 1, 4); // shortcut: write_at("---", 1, 4)
write_at("-", 2, 4); // ...
write_at("-", 3, 4); // ...
write_at("+", 4, 4);
// Draw the right side, from bottom to top.
write_at("|", 4, 3);
write_at("|", 4, 2);
write_at("|", 4, 1);
write_at("+", 4, 0);
// Draw the top side, from right to left.
write_at("-", 3, 0); // shortcut: write_at("---", 1, 0)
write_at("-", 2, 0); // ...
write_at("-", 1, 0); // ...
//
write_at("All done!", 0, 6);
}
// This code produces the following output :
//
// +---+
// | |
// | |
// | |
// +---+
//
// All done!
static void write(arg_t &&value)
Writes the text representation of the specified value to the standard output stream.
Definition console.h:462
static int32 cursor_top()
Gets the row position of the cursor within the buffer area.
static void clear()
Clears the console buffer and corresponding console window of display information.
static void set_cursor_position(int32 left, int32 top)
Sets the position of the cursor.
static int32 cursor_left()
Gets the column position of the cursor within the buffer area.
static void write_line()
Writes the current line terminator to the standard output stream using the specified format informati...
@ s
The S key.
@ y
The Y key.
@ x
The X key.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10