Text editor
Version 1.0

SPECIFICATION


OVERVIEW

A simple text editor that allows the user to add, remove and replace entire lines of text.  It doesn't allow the user to edit the contents of the lines.  (The only way to accomplish this is to replace the entire line by a new one.)


DETAILS

The editor has a buffer that contains lines of text, usually an edited copy of the contents of some file.  The editor interacts with the user as shown in the following example:

co-op.txt
--------------------------------------------------
  1 List for Co-op
  2
  3 bread
  4 yogurt
> 5 cumin
  6 black beans
  7 chick pea flour
  8 toothpaste
  9 
  
--------------------------------------------------
  next      jump     insert  open  quit 
  previous  replace  delete  save
-------
choice: i
new line: ginger

The program begins by asking the user for a window height.  This is the maximum number of lines that will be displayed at any time.  The displayed lines are numbered starting at 1 for the first line of the file.  If the number of lines on the last page is smaller than the window height, the rest of the window is filled with unnumbered empty lines. 

Buffer lines are displayed between two lines of 50 dashes.  The name of the file is printed above the first line of dashes.  A cursor (>) indicates the position of the current line.  Below the second line of dashes, a menu of commands is displayed.  Below that menu, the prompt "choice:" is displayed.  The user types the first letter of a command, the command executes and everything is redisplayed.  Some commands prompt the user for more information.  

The displayed contents of the buffer always includes an extra empty line that we call the "end line".  That line is not really part of the buffer but the cursor can move there.  This is how the user would insert a new line at the end of the buffer.  This is also the line that the crusor points to when the buffer is empty.

Here is a description of the various commands:

next: The next line becomes the current line.  Does nothing if the current line is the end line.

previous: The previous line becomes the current line.  Does nothing if the current line is the first one.

jump: Asks for a line number (with prompt "line number:") and makes that line become the current line.  The new current line is displayed at the top.  If the user enters an invalid line number N, the message "ERROR: N is not a valid line number" is displayed just before the file name is redisplayed.

replace: Asks for a new line (with prompt "new line:") and replaces the current line.  

insert: Asks for a new line (with prompt "new line:") and inserts it before the current line.  The line that follows the new one becomes the current one.  (This makes it easy to add a sequence of new lines, in order.)

delete: Deletes the current line.  The next line becomes the current one.  Nothing happens if the user tries to delete the end line.

open: Asks for a file name (with prompt "file name:") and reads that file into the buffer.  If a file named X does not open, the message "ERROR: Could not open X" is displayed just before the file name is redisplayed.

save: Asks for a file name (with prompt "file name:") and saves the contents of the buffer to that file.  If a file named X does not open, the message "ERROR: Could not open X" is displayed just before the file name is redisplayed.

quit: Stops the editor.


NOTES FOR LATER VERSIONS

open and quit should check if the buffer has been saved.

Add more error-checking.  (Check that commands are entered properly and that the window height is a positive integer.)
