cpp-terminal 1.0.0
Small C++ library for writing multiplatform terminal applications
Loading...
Searching...
No Matches
cursor.cpp
Go to the documentation of this file.
1/*
2* cpp-terminal
3* C++ library for writing multi-platform terminal applications.
4*
5* SPDX-FileCopyrightText: 2019-2024 cpp-terminal
6*
7* SPDX-License-Identifier: MIT
8*/
9
11
12Term::Cursor::Cursor(const std::size_t& row, const std::size_t& column) : m_position({row, column}) {}
13
14std::size_t Term::Cursor::row() const { return m_position.first; }
15
16std::size_t Term::Cursor::column() const { return m_position.second; }
17
18bool Term::Cursor::empty() const { return (0 == m_position.first) && (0 == m_position.second); }
19
20void Term::Cursor::setRow(const std::size_t& row) { m_position.first = row; }
21
22void Term::Cursor::setColum(const std::size_t& column) { m_position.second = column; }
23
24bool Term::Cursor::operator==(const Term::Cursor& cursor) const { return (this->row() == cursor.row()) && (this->column() == cursor.column()); }
25
26bool Term::Cursor::operator!=(const Term::Cursor& cursor) const { return !(*this == cursor); }
27
28std::string Term::cursor_off() { return "\u001b[?25l"; }
29
30std::string Term::cursor_on() { return "\u001b[?25h"; }
31
32std::string Term::cursor_move(const std::size_t& row, const std::size_t& column) { return "\u001b[" + std::to_string(row) + ';' + std::to_string(column) + 'H'; }
33
34std::string Term::cursor_up(const std::size_t& rows) { return "\u001b[" + std::to_string(rows) + 'A'; }
35
36std::string Term::cursor_down(const std::size_t& rows) { return "\u001b[" + std::to_string(rows) + 'B'; }
37
38std::string Term::cursor_right(const std::size_t& columns) { return "\u001b[" + std::to_string(columns) + 'C'; }
39
40std::string Term::cursor_left(const std::size_t& columns) { return "\u001b[" + std::to_string(columns) + 'D'; }
41
42std::string Term::cursor_position_report() { return "\u001b[6n"; }
43
44std::string Term::clear_eol() { return "\u001b[K"; }
std::size_t column() const
Definition cursor.cpp:16
void setColum(const std::size_t &)
Definition cursor.cpp:22
bool operator!=(const Term::Cursor &cursor) const
Definition cursor.cpp:26
void setRow(const std::size_t &)
Definition cursor.cpp:20
Cursor()=default
bool empty() const
Definition cursor.cpp:18
std::size_t row() const
Definition cursor.cpp:14
bool operator==(const Term::Cursor &cursor) const
Definition cursor.cpp:24
std::string clear_eol()
Definition cursor.cpp:44
std::string cursor_position_report()
Definition cursor.cpp:42
std::string cursor_off()
Definition cursor.cpp:28
std::string cursor_left(const std::size_t &columns)
Definition cursor.cpp:40
std::string cursor_move(const std::size_t &row, const std::size_t &column)
Definition cursor.cpp:32
std::string cursor_on()
Definition cursor.cpp:30
std::string cursor_up(const std::size_t &rows)
Definition cursor.cpp:34
std::string cursor_right(const std::size_t &columns)
Definition cursor.cpp:38
std::string cursor_down(const std::size_t &rows)
Definition cursor.cpp:36