You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
3.1 KiB

3 years ago
3 years ago
3 years ago
  1. File browser
  2. # SPECIFICATION
  3. ## OVERVIEW
  4. A simple file browser that allows the user view the contents of a text file.
  5. ## DETAILS
  6. The program interacts with the user as shown in the following example:
  7. ```
  8. preface.txt
  9. --------------------------------------------------
  10. 1 These notes are for a second course on computer programming and
  11. 2 software development. In a first course, you likely focused on
  12. 3 learning the basics: variables, control statements, input and
  13. 4 output, files, vectors (or arrays), functions and structures. You
  14. 5 may have also had an introduction to classes. These concepts are
  15. 6 critically important and they are sufficient for the creation of
  16. 7 many useful programs. But many other programs, especially large
  17. 8 ones, require more powerful concepts and techniques. And a deeper
  18. 9 understanding of classes and design principles.
  19. 10
  20. 11 In fact, the creation of large computer programs poses three basic
  21. 12 challenges. The overall goal of these notes is to teach you
  22. --------------------------------------------------
  23. next previous open quit
  24. -------
  25. command: o
  26. file: introduction.txt
  27. ```
  28. The program begins by asking the user for a window height. This is the number of lines that will be displayed as each "page". Then, the user will be asked for the maximum number of characters displayed per line. 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.
  29. Each page is displayed between two lines of 50 dashes. The name of the file is printed above the first line of dashes. If no file is currently open, the string "<no file opened>" is printed instead of the file name.
  30. 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.
  31. Here is a description of the various commands:
  32. * open: Asks for a file name (with prompt "file:") and displays that file after parsing the proper tags and links. If a file named X does not open, the message "ERROR: Could not open X" is displayed just before the file name is redisplayed.
  33. * next: The next page is displayed. Does nothing if the last line of the file is already displayed.
  34. * previous: The previous page is displayed. Does nothing if the first line of the file is already displayed.
  35. * go: Asks for the number of the link the user would like to visit. If the file corresponding to that link does not open, the message "ERROR: ....." is displayed.
  36. * back: The last file that was displayed gets re-opened. If there are no files left in the history, the error message "ERROR: ...." is displayed.
  37. * quit: Stops the program.
  38. ## NOTES FOR LATER VERSIONS
  39. Add more error-checking. For example, check that commands are entered properly and that the window height is a positive integer.