Serenity Operating System
1/*
2 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
3 *
4 * SPDX-License-Identifier: BSD-2-Clause
5 */
6
7#pragma once
8
9#include <AK/Types.h>
10
11namespace VT {
12
13class Position {
14public:
15 Position() = default;
16 Position(int row, int column)
17 : m_row(row)
18 , m_column(column)
19 {
20 }
21
22 bool is_valid() const { return m_row >= 0 && m_column >= 0; }
23 int row() const { return m_row; }
24 int column() const { return m_column; }
25
26 bool operator<(Position const& other) const
27 {
28 return m_row < other.m_row || (m_row == other.m_row && m_column < other.m_column);
29 }
30
31 bool operator<=(Position const& other) const
32 {
33 return *this < other || *this == other;
34 }
35
36 bool operator>=(Position const& other) const
37 {
38 return !(*this < other);
39 }
40
41 bool operator==(Position const& other) const
42 {
43 return m_row == other.m_row && m_column == other.m_column;
44 }
45
46 bool operator!=(Position const& other) const
47 {
48 return !(*this == other);
49 }
50
51private:
52 int m_row { -1 };
53 int m_column { -1 };
54};
55
56struct CursorPosition {
57 size_t row { 0 };
58 size_t column { 0 };
59
60 void clamp(u16 max_row, u16 max_column)
61 {
62 row = min(row, max_row);
63 column = min(column, max_column);
64 }
65};
66
67}