-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
150 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* cpp-terminal | ||
* C++ library for writing multi-platform terminal applications. | ||
* | ||
* SPDX-FileCopyrightText: 2019-2024 cpp-terminal | ||
* | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <cstddef> | ||
#include <cstdint> | ||
|
||
namespace Term | ||
{ | ||
|
||
class Row | ||
{ | ||
public: | ||
Row() = default; | ||
explicit Row(const std::uint16_t& row) : m_row(row) {} | ||
operator std::size_t() const noexcept { return m_row; } | ||
|
||
private: | ||
std::uint16_t m_row{0}; | ||
}; | ||
|
||
class Column | ||
{ | ||
public: | ||
Column() = default; | ||
explicit Column(const std::uint16_t& column) : m_column(column) {} | ||
operator std::size_t() const noexcept { return m_column; } | ||
|
||
private: | ||
std::uint16_t m_column{0}; | ||
}; | ||
|
||
class Position | ||
{ | ||
public: | ||
Position() = default; | ||
Position(const Row& row, const Column& column) : m_row(row), m_column(column) {}; | ||
Position(const Column& column, const Row& row) : m_row(row), m_column(column) {}; | ||
const Row& row() const noexcept { return m_row; } | ||
const Column& column() const noexcept { return m_column; } | ||
|
||
private: | ||
Row m_row{1}; | ||
Column m_column{1}; | ||
}; | ||
|
||
} // namespace Term |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* cpp-terminal | ||
* C++ library for writing multi-platform terminal applications. | ||
* | ||
* SPDX-FileCopyrightText: 2019-2024 cpp-terminal | ||
* | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
#include "cpp-terminal/cursor.hpp" | ||
|
||
#include "cpp-terminal/exception.hpp" | ||
#include "cpp-terminal/input.hpp" | ||
#include "cpp-terminal/iostream.hpp" | ||
#include "cpp-terminal/options.hpp" | ||
#include "cpp-terminal/terminal.hpp" | ||
|
||
#include <ostream> | ||
|
||
int main() | ||
{ | ||
try | ||
{ | ||
// check if the terminal is capable of handling input | ||
Term::terminal.setOptions(Term::Option::ClearScreen, Term::Option::NoSignalKeys, Term::Option::Cursor, Term::Option::Raw); | ||
Term::Cursor cursor{Term::cursor_position()}; | ||
Term::cout << "Cursor position : " << cursor.row() << " " << cursor.column() << std::endl; | ||
|
||
Term::cout << "Press any key ( 3 time 'q' to quit):" << std::endl; | ||
int quit{0}; | ||
while(quit != 3) | ||
{ | ||
Term::Event event = Term::read_event(); | ||
switch(event.type()) | ||
{ | ||
case Term::Event::Type::Key: | ||
{ | ||
Term::Key key(event); | ||
if(key == Term::Key::q) { quit++; } | ||
else | ||
{ | ||
quit = 0; | ||
Term::cout << key.name() << std::flush; | ||
Term::cout << " " << Term::cursor_position_report() << std::flush; | ||
} | ||
break; | ||
} | ||
case Term::Event::Type::Cursor: | ||
{ | ||
Term::Cursor cursor(event); | ||
Term::cout << " [Column(X) : " << cursor.column() << " Row(Y) : " << cursor.row() << "]"; | ||
break; | ||
} | ||
default: break; | ||
} | ||
} | ||
} | ||
catch(const Term::Exception& re) | ||
{ | ||
Term::cerr << "cpp-terminal error: " << re.what() << std::endl; | ||
return 2; | ||
} | ||
catch(...) | ||
{ | ||
Term::cerr << "Unknown error." << std::endl; | ||
return 1; | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters