-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCurses.cc
More file actions
154 lines (118 loc) · 3.97 KB
/
Curses.cc
File metadata and controls
154 lines (118 loc) · 3.97 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// Copyright (c) 2008 National ICT Australia Limited (NICTA)
//
// Author: Charles Gretton (charles.gretton@nicta.com.au)
//
// Redistribution and use in source and binary forms, with or without
// modification and only for non-commercial research and educational
// purposes are permitted provided that the conditions in the
// accompanying file "licence.txt" are met.
#include "Curses.hh"
#ifdef WITH_CURSES
Curses Curses::curses;
#endif
Curses::Curses()
{
wnd = initscr(); // initialise window
cbreak(); // set no waiting for Enter key
noecho(); // set no echoing
getmaxyx(wnd,nrows,ncols); // find size of window
clear(); // clear screen, send cursor to position (0,0)
refresh(); // implement all changes since last refresh
}
void Curses::draw(char ch)
{
move(row,col); // move cursor to row r, column c
// replace character under cursor by ch
delch();
insch(ch);
refresh(); // update screen
col++; // go to next row
// // check for need to shift right or wrap around
// if (row == nrows) {
// row = 0;
// col++;
// if (col == ncols) {
// col = 0;
// }
// }
}
void Curses::writeTopRight(const string& str)
{
/*Make sure that our assumptions are met.*/
if(str.find('\n') != str.length()){
WARNING("\\class{Curses} was given a string with a newline character"<<endl
<<" ** to write to the terminal. This was no expected."<<endl);
}
if(str.length() >= ncols){
WARNING("\\class{Curses} was given too long a string to write to the screen.\n");
}
/*Make sure the cursor is pointing to the right spot on the
* terminal, given the length of our string.*/
row = 0;
col = ncols - str.length() - 1;
for(int i = 0; i < str.length(); i++){
draw(str[i]);
}
move(nrows - 1, 0);
refresh(); // update screen
}
void Curses::writeBottomLeft(const string& str)
{
/*Make sure that our assumptions are met.*/
if(str.find('\n') != str.length()){
WARNING("\\class{Curses} was given a string with a newline character"<<endl
<<" ** to write to the terminal. This was no expected."<<endl);
}
if(str.length() >= ncols){
WARNING("\\class{Curses} was given too long a string to write to the screen.\n");
}
/*Make sure the cursor is pointing to the right spot on the
* terminal, given the length of our string.*/
row = nrows - 1;
col = 0;//ncols - str.length() - 1;
for(int i = 0; i < str.length(); i++){
draw(str[i]);
}
move(nrows - 1, 0);
refresh(); // update screen
}
void Curses::writeTopLeft(const string& str)
{
/*Make sure that our assumptions are met.*/
if(str.find('\n') != str.length()){
WARNING("\\class{Curses} was given a string with a newline character"<<endl
<<" ** to write to the terminal. This was no expected."<<endl);
}
if(str.length() >= ncols){
WARNING("\\class{Curses} was given too long a string to write to the screen.\n");
}
/*Make sure the cursor is pointing to the right spot on the
* terminal, given the length of our string.*/
row = 0;
col = 0;//ncols - str.length() - 1;
for(int i = 0; i < str.length(); i++){
draw(str[i]);
}
move(nrows - 1, 0);
refresh(); // update screen
}
void Curses::writeBottomRight(const string& str)
{
/*Make sure that our assumptions are met.*/
if(str.find('\n') != str.length()){
WARNING("\\class{Curses} was given a string with a newline character"<<endl
<<" ** to write to the terminal. This was no expected."<<endl);
}
if(str.length() >= ncols){
WARNING("\\class{Curses} was given too long a string to write to the screen.\n");
}
/*Make sure the cursor is pointing to the right spot on the
* terminal, given the length of our string.*/
row = nrows - 1;
col = ncols - str.length() - 1;
for(int i = 0; i < str.length(); i++){
draw(str[i]);
}
move(nrows - 1, 0);
refresh(); // update screen
}