text-editor

i am making simple text editor having some problem with this these are the works i have to do 1-typing(without using cout) 2-complete keyboard control i-e cursor movement . 3-I should be able to write from middle of line .

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
 #include <cstdio>
#include <iostream>
#include <stdlib.h>
#include <conio.h>
#include <windows.h>

using namespace std;

#define BLACK 0
#define BLUE 1
#define GREEN 2
#define CYAN 3
#define RED 4
#define MAGENTA 5
#define BROWN 6
#define LIGHTGRAY 7
#define DARKGRAY 8
#define LIGHTBLUE 9
#define LIGHTGREEN 10
#define LIGHTCYAN 11
#define LIGHTRED 12
#define LIGHTMAGENTA 13
#define YELLOW 14
#define WHITE 15
#define DONT_BLINK 0
#define BLINK 1

void gotoxyinput(short x, short y)
{
COORD pos = {x, y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}

void gotoxyColorPrint(char cstr[], int x, int y, int color= WHITE) 
{ 
HANDLE hConsoleOutput; 
COORD dwCursorPosition;
cout.flush(); 
dwCursorPosition.X = x; 
dwCursorPosition.Y = y; 
hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hConsoleOutput,dwCursorPosition); 
SetConsoleTextAttribute(hConsoleOutput,color);
cout<<cstr;
SetConsoleTextAttribute(hConsoleOutput,YELLOW);
}

int main()
{

//Following will put a character at the given place
//gotoxyColorPrint("",30,10,YELLOW);

//Following will just take the cursor to the given place
//gotoxyColorPrint("", 31,10); 

int CP_x=0;
int CP_y=0;
gotoxyinput(CP_x,CP_y);

char input;
//char input[2]={'\0','\0'};
char text[2000];
int CP=0;

while(true)
{
input=getch();
text[CP]=input;
//gotoxyColorPrint("",CP_x,CP_y);
//gotoxyColorPrint(input,CP_x,CP_y);

if(input>=65 && input<=90)
{
gotoxyinput(CP_x,CP_y);
text[CP]=input;
CP_x++;
CP_y++;
CP++;
}

input=getch();

if(input==-32)
{
//arrow key pressed
input = getch();

if(input==72)//Up Arrow
{
CP_y=CP_y-1;
gotoxyinput(CP_x , CP_y);
}
else if(input==77)//Right Arrow
{
CP_x=CP_x+1;
gotoxyinput(CP_x , CP_y);
} 
else if(input==80)//Down Arrow
{
CP_y=CP_y+1;
gotoxyinput(CP_x , CP_y);
}
else if(input==75)//Left Arrow
{
CP_x=CP_x-1;
gotoxyinput(CP_x , CP_y);
}
}

if(input==32)//Space
{
CP_x=CP_x+1;
gotoxyinput(CP_x , CP_y);
}
else if(input==13)//Enter
{
CP_x=0;
CP_y=CP_y++;
gotoxyinput(CP_x , CP_y);
}
else if(input==8)//Backspace
{
CP_x=CP_x-1;
gotoxyinput(CP_x , CP_y);
}
else if(input==127)//Delete
{
CP_x=CP_x+1;
gotoxyinput(CP_x,CP_y);
}
else if(input==27)//Esc
{
break;
}

}

cin.get();
getch();
return 0;
}
Topic archived. No new replies allowed.