0
Reply

Designing a Console Editor

Taklaci Guvercin

Taklaci Guvercin

Dec 20 2011 2:43 PM
1.7k
Project: Console Editor

The goal of the project is to develop a simplified console editor application.

General Information

This project consists of an editor that provides various word processing capabilities in an active work space of 15*50 characters. The editor involves word processing and figure drawing tools. The functions of the editor are performed by key strokes and command line inputs.

Features

The editor supports a text of maximum 200 lines, each consisting of maximum 50 characters.The user has the capability of loading and saving the text files. If texts exceeding the maximum limit are attempted to be loaded, the part that exceeds the allowed limit are ignored.

The editor supports 26 letters of English alphabet (a-z, A-Z), digits (0-9), space and punctuation marks ( . , : ; ! ? * + ). If characters outside these categories are tried to be loaded, the editor disregards them. If the user tries to enter non-supported characters via the keyboard, the editor again disregards them.

The words and "character groups written together" should not be split between two lines. Words/"character groups" that do not fit into a single line should be moved to the next line. Words/groups separate from each other by the space character. Words/groups longer than 50 characters are not supported. Any words/groups longer than 50 characters will be treated as max. 50-character-long parts.

The editor supports cursor movement in all four directions, character insertion or deletion at a desired location.

Special Keys


Cursor keys: Movement across the active work space in four directions. At the end of a line, "right button" moves the cursor to the first character of the next line. At the beginning of a line, "left button" moves the cursor to the last character of the previous line.

Return: Goes to a new paragraph.

Backspace: Deletes the character just before the cursor.

Delete: Deletes the character just after the cursor.
Home: Takes the cursor to the beginning of the line.

End: Takes the cursor to the end of the line.

PageUp: Moves the active work space and the cursor to the previous 15 lines.

PageDown: Moves the active work space and the cursor to the next 15 lines.

Selection and Cut/Copy/Paste

The editor provides cut/copy/paste capability by using the following keys:
F1: Marks the start of selection (SelStart) F2: Marks the end of selection (SelEnd)
F3: Cut F4: Copy F5: Paste

If the SelStart and SelEnd are different, there is a "selection" and it should be highlighted. If the SelStart and SelEnd are the same, it means there is no selection. Selections cannot be longer than one line.

The selection procedure does not only apply to cut/copy/paste actions, but also marks the text which will be processed in other functions. After the function is applied, SelStart will be equal to SelEnd.

Alignment

The editor supports different text alignment options through the F6 key:
1: Aligned to the left (default mode) 2: Aligned to the right 3: Justified
The next alignment option is applied to the text every time the F6 key is pressed.

Command Line

Through the F11 key, the editor enters into command line mode to execute certain functions.

Command and parameters Explanation
load name Loads the file "name".
save name Saves the file "name", in formatted form.
case lower Converts the selected text into lower case characters.
case upper Converts the selected text into upper case characters.
case title Converts the first characters of the selected words into upper case characters and rest of the characters into lower case.
find word style case Finds and selects the "word" inside the text (case sensitive).
style=0 partial word style=1 whole word
case=0 not case sensitive case=1 case sensitive
(F10 searches for next occurrence)
replace word newword style case Finds and replaces all occurrences of the "word" into "newword".
style=0 partial word style=1 whole word
case=0 not case sensitive case=1 case sensitive
draw symbol Chooses drawing symbol (default symbol is "." )

Drawing Tool

The editor supports a drawing tool that draws lines and rectangles using ASCII symbols. Lines can be horizontal, vertical or diagonal (45?). If coordinates are not convenient, line cannot be drawn.

In order to draw a line/rectangle;
1. DrawPoint must be determined first.
DrawPoint represents the start point for line drawing or a corner for rectangle drawing.
Move cursor to the position. Press F7.
2. Move cursor to the end point for line drawing or opposite corner for rectangle drawing. Press F8/F9.



using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{

#region Dizi Olusturma

Console.SetCursorPosition(10, 10);
string[] array = new string[200];

for (int j = 0; j < 200; j++)
for (int i = 0; i < 50; i++)
{
array[j] = array[j] + " ";
}

#endregion

#region Arka Plan Rengini Belirleme
Console.BackgroundColor = ConsoleColor.White;
Console.ForegroundColor = ConsoleColor.Blue;
Console.Clear();
#endregion

#region Tus Blogu








Console.SetCursorPosition(65, 20);
Console.Write("Find :");
Console.SetCursorPosition(65, 21);
Console.Write("FindPos :");

Console.SetCursorPosition(65, 24);
Console.Write("Drawpoint :");
Console.SetCursorPosition(65, 25);
Console.Write("Drawsymbol :");
#endregion

#region Haritanin Çizilmesi
for (int t = 9; t > 0; t = t - 2)
{
Console.SetCursorPosition(t + 9, 8);
Console.Write(t);
}
for (int t = 9; t > 0; t = t - 2)
{
Console.SetCursorPosition(t + 19, 8);
Console.Write(t);
}

for (int t = 9; t > 0; t = t - 2)
{
Console.SetCursorPosition(t + 29, 8);
Console.Write(t);
}
for (int t = 9; t > 0; t = t - 2)
{
Console.SetCursorPosition(t + 39, 8);
Console.Write(t);
}

for (int t = 9; t > 0; t = t - 2)
{
Console.SetCursorPosition(t + 49, 8);
Console.Write(t);
}


for (int f = 9; f >= 1; f = f - 2)
{
Console.SetCursorPosition(8, f + 9);
Console.WriteLine(f);
}

for (int f = 5; f >= 1; f = f - 2)
{
Console.SetCursorPosition(8, f + 19);
Console.WriteLine(f);
}



for (int i = 10; i < 61; i++)
{

Console.SetCursorPosition(i, 9);
Console.Write("#");


}

for (int j = 1; j < 18; j++)
{
Console.SetCursorPosition(9, j + 8);
Console.WriteLine("#");
}

for (int k = 10; k < 61; k++)
{
Console.SetCursorPosition(k, 25);
Console.WriteLine("#");
}

for (int l = 1; l < 18; l++)
{
Console.SetCursorPosition(60, l + 8);
Console.WriteLine("#");
}

#endregion

#region üst konsol
Console.SetCursorPosition(1, 1);
Console.WriteLine("F1:SelStart");

Console.SetCursorPosition(17, 1);
Console.WriteLine("F2:SelEnd");

Console.SetCursorPosition(29, 1);
Console.WriteLine("F3:Cut");

Console.SetCursorPosition(42, 1);
Console.WriteLine("F4:Copy");


Console.SetCursorPosition(55, 1);
Console.WriteLine("F5:Paste");


Console.SetCursorPosition(1, 3);
Console.WriteLine("F6:Left/Right/Just");


Console.SetCursorPosition(22, 3);
Console.WriteLine("F7:Drawpoint");

Console.SetCursorPosition(35, 3);
Console.WriteLine("F8/F9:Line/Rect.");

Console.SetCursorPosition(53, 3);
Console.WriteLine("F10:Next");

Console.SetCursorPosition(63, 3);
Console.WriteLine("F11:");

#endregion

#region özel tuslar
int x = 0;
int y = 0;


bool selcont = false;
int selx = 0;
int sely = 0;

bool selendcont = false;
int selendx = 0;
int selendy = 0;

while (true)
{
Console.SetCursorPosition(10 + x, 10 + y);
ConsoleKeyInfo info = Console.ReadKey();

if (info.Key == ConsoleKey.RightArrow)
{

if (selcont == true && selendcont == false)
{
Console.BackgroundColor = ConsoleColor.Green;
}
Console.SetCursorPosition(x + 10, y + 10);
Console.Write(array[y].Substring(x, 1));
x++;

Console.BackgroundColor = ConsoleColor.White;

if (selx != 0 && sely != 0)
{
Console.BackgroundColor = ConsoleColor.Green;

}


}
else if (info.Key == ConsoleKey.LeftArrow)
{
if (selcont == true && selendcont == false)
{
Console.BackgroundColor = ConsoleColor.Green;
}
Console.SetCursorPosition(x + 10, y + 10);
Console.Write(array[y].Substring(x, 1));
x--;

Console.BackgroundColor = ConsoleColor.White;

}
else if (info.Key == ConsoleKey.DownArrow)
{
Console.SetCursorPosition(x + 10, y + 10);
Console.Write(array[y].Substring(x, 1));
y++;
}
else if (info.Key == ConsoleKey.UpArrow)
{
Console.SetCursorPosition(x + 10, y + 10);
Console.Write(array[y].Substring(x, 1));
y--;
}
else if (info.Key == ConsoleKey.Home)
{
Console.SetCursorPosition(x + 10, y + 10);
Console.Write(array[y].Substring(x, 1));
x = 0;
y = 0;
}
else if (info.Key == ConsoleKey.End)
{
Console.SetCursorPosition(x + 10, y + 10);
Console.Write(array[y].Substring(x, 1));
x = 49;
y = 15;
}


else if (info.Key == ConsoleKey.PageUp)
{
Console.SetCursorPosition(x + 10, y + 10);
Console.Write(array[y].Substring(x, 1));
x = x - 15;

}

else if (info.Key == ConsoleKey.PageDown)
{
Console.SetCursorPosition(x + 10, y + 10);
Console.Write(array[y].Substring(x, 1));
x = x + 15;

}


else if (info.Key == ConsoleKey.Enter)
{
Console.SetCursorPosition(x + 10, y + 10);
Console.Write(array[y].Substring(x, 1));
y = y + 1;

}
else if (info.Key == ConsoleKey.Delete)
{
Console.SetCursorPosition(x + 10, y + 10);
Console.Write(" ");
x = x + 1;

}
else if (info.Key == ConsoleKey.Backspace)
{
Console.SetCursorPosition(x + 10, y + 10);
Console.Write(" ");

x = x - 1;

}

else if (info.Key == ConsoleKey.F1)
{
selx = x;
sely = y;

selcont = true;

Console.SetCursorPosition(x + 10, y + 10);
Console.Write(array[y].Substring(x, 1));
}
else if (info.Key == ConsoleKey.F2)
{
selendx = x;
selendy = y;

selendcont = true;

Console.SetCursorPosition(x + 10, y + 10);
Console.Write(array[y].Substring(x, 1));
}
else if (info.Key == ConsoleKey.F3)//cut
{
Console.SetCursorPosition(x + 10, y + 10);
Console.Write(array[y].Substring(x, 1));

x--;

}

else if (info.Key == ConsoleKey.F4)//copy
{
Console.SetCursorPosition(x + 10, y + 10);
Console.Write(array[y].Substring(x, 1));

x = x - 1;

}

else if (info.Key == ConsoleKey.F5)//paste
{
Console.SetCursorPosition(x + 10, y + 10);
Console.Write(array[y].Substring(x, 1));

selx = 0;
sely = 0;

selendx = 0;
selendy = 0;

selcont = false;
selendcont = false;
}
else if (info.Key == ConsoleKey.F6)//allignment
{
Console.SetCursorPosition(x + 10, y + 10);
Console.Write(array[y].Substring(x, 1));

x = x + 19;

}

else if (info.KeyChar < 'z' && info.KeyChar > 'A')
{
array[y] = array[y].Insert(x, info.KeyChar.ToString());

x++;
}
else if (info.KeyChar == 'g' || info.KeyChar == 'G' || info.KeyChar == 'Ü' || info.KeyChar == 'ü' || info.KeyChar == 's' || info.KeyChar == 'S' || info.KeyChar == 'Ç' || info.KeyChar == 'ç' || info.KeyChar == 'ö' || info.KeyChar == 'Ö' || info.KeyChar == 'i' || info.KeyChar == 'I')
{
Console.SetCursorPosition(x + 10, y + 10);
Console.Write(" ");
}


else if (info.Key == ConsoleKey.F11)
{
string austin = "load";
string moccasin = "save";
string control;
Console.SetCursorPosition(67, 3);
control=Convert.ToString(Console.ReadLine());

if (control==moccasin)
{
StreamWriter f = File.CreateText("d:\\ProjeText.txt");

for (int i = 0; i < 200; i++)
{


f.WriteLine(array[i]);
}
f.Close();

if (control==austin)
{
string str;
StreamReader z = File.OpenText("d:\\ProjeText.txt");
for (int i = 0; i < 200; i++)
{


f.WriteLine(array[i]);
}

z.Close();







}


}

}


else
x++;
if (x < 0)
{
if (y > 0)
{
y--;
x = 49;
}
else
{
x = 0;
}
}
else if (x > 49)
{
if (y < 14)
{
y++;
x = 0;
}
else
{
x = 49;
}
}

if (y < 0)
{
y = 0;
}
else if (y > 14)
{
y = 14;

}



if (x == 0)
{
Console.SetCursorPosition(76, 18);
Console.WriteLine("Left ");

}

if (x == 19)
{
Console.SetCursorPosition(76, 18);
Console.WriteLine("Right");

}

if (x == 38)
{
Console.SetCursorPosition(76, 18);
Console.WriteLine("Just.");

}

Console.SetCursorPosition(65, 10);
if (selcont == true)
Console.Write("SelStart:{0},{1}", selx + 10, sely + 10);
else
Console.Write("SelStart:{0},{1}", 0, 0);

Console.SetCursorPosition(65, 9);
Console.Write("Cursor:{0},{1}", x + 10, y + 10);

Console.SetCursorPosition(65, 11);
if (selendcont == true)
Console.Write("SelEnd:{0},{1}", selendx + 10, selendy + 10);
else
Console.Write("SelEnd:{0},{1}", 0, 0);

Console.SetCursorPosition(65, 18);
Console.Write("Allignment:");

Console.SetCursorPosition(65, 14);
Console.Write("Clipboard:");
Console.SetCursorPosition(65, 15);
Console.Write("processing");



}


#endregion

Console.ReadLine();

}
}
}


Some parts of project were completed but i'm getting stuck in F1:SelStart,F2:SelEnd,F3:Cut,F4:Copy,F5:Paste and File Operations in F11: if you help me i will owe you...