-
Notifications
You must be signed in to change notification settings - Fork 0
/
rim.h
60 lines (50 loc) · 1.46 KB
/
rim.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#ifndef RIM_H
#define RIM_H
#include <ncurses.h>
#include <vector>
#include <string>
#include <cctype>
#include "screen.h"
#include "cursor.h"
enum class Mode{
NORMAL = 0,
INSERT,
REPLACE
};
static const int ESCAPE_KEY = '\x1B';
static const int BACKSPACE_KEY = '\x7F';
static const int SPACES_FOR_TAB = 4;
// To-Do - let users/programmers customize the number of spaces for tabs
static const int ENTER_KEY = '\xA';
class Rim{
FILE* file;
Screen screen;
Mode current_mode{Mode::NORMAL};
std::vector<std::string> file_contents{create_file_contents()};
Cursor cursor{};
std::size_t file_contents_index = 0;
std::size_t top_of_screen_index = 0;
std::vector<std::string> create_file_contents() noexcept;
void move_cursor_down() noexcept;
void move_cursor_up() noexcept;
void move_cursor_left() noexcept;
void move_cursor_right() noexcept;
void move_cursor_x_considering_lines(
const std::string& line_considered,
const std::string& current_line) noexcept;
void normal_mode_action(int character) noexcept;
void insert_mode_action(int character) noexcept;
void replace_mode_action(int character) noexcept;
void insert_char(int character) noexcept;
void replace_char(int character) noexcept;
void delete_char() noexcept;
void save() noexcept;
void add_new_line() noexcept;
public:
Rim(const char* file_name = "") noexcept;
Rim(const Rim& r) = delete;
Rim& operator=(const Rim& r) = delete;
void process_keypress(int character) noexcept;
~Rim();
};
#endif