/* Cfour (C++ Common Console Classes) * Copyright (C) 2001 Jeffrey Bakker * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * * Author: Jeffrey Bakker * Filename: cfconsole.cpp * File version: 1.1 * * =========================================================================== * * Created on: June 26th, 2001 * * =========================================================================== * * Remark: * * This is the class implementation for Console, a class which provides * methods for commonly used screen operations. All the methods in this * class are static, so there is no need to create a Console object to * use them. * * =========================================================================== * * void clear(): * * Description: clears the screen by printing 25 newlines. * * Input: * - takes 0 parameters * * Output: * - returns nothing * * =========================================================================== * * void pause(): * * Description: pauses the output until user press a key and tells user * to press the Enter key to continue. * * Input: * - takes 0 parameters * * Output: * - returns nothing * * =========================================================================== * * void pause_quiet(): * * Description: pauses the output until user press a key. * * Input: * - takes 0 parameters * * Output: * - returns nothing * * =========================================================================== * * void auto__pause(int scroll): * * Description: pauses the output until user press a key and tells user * to press the Enter key to continue when the output reaches * the end of the screen. The usage of this method would be * inside a for-loop that prints more than 25 lines. * * Input: * * Parameter 1 * - Name: scroll * - Type: integer * - Description: represents of the number of lines printed * * Output: * - returns nothing * * =========================================================================== * * void auto__pause_quiet(int scroll): * * Description: pauses the output until user press a key when the output * is at the end of the screen. The usage of this method would * be inside a for-loop that prints more than 25 lines. * * Input: * * Parameter 1 * - Name: scroll * - Type: integer * - Description: represents of the number of lines printed * * Output: * - returns nothing * =========================================================================== * * void draw_a_file(string filename): * * Description: prints a text file to the screen * * Input: * * Parameter 1 * - Name: filename * - Type: string * - Description: the name of the file to be printed * * Output: * - returns nothing * =========================================================================== * * void draw_a_line(char fill, int length): * * Description: prints a horizontal line of characters across the screen * * Input: * * Parameter 1 * - Name: fill * - Type: character * - Description: the character to make the line with * * Input: * * Parameter 2 * - Name: length * - Type: integer * - Description: how many characters to print * * * Output: * - returns nothing * * =========================================================================== * _______. .. */ #include <fstream> #include "cfconsole.h" // Clears the screen ---------------------------------------------------------- void Console::clear() { for (int i = 0; i < 25; i++) {cout << endl;} } //----------------------------------------------------------------------------- // Pauses the output ---------------------------------------------------------- void Console::pause() { cout << "\t\t\t*Press Enter key to continue*"; cin.get(); cin.get(); } //----------------------------------------------------------------------------- // Quietly Pauses the output -------------------------------------------------- void Console::pause_quiet() { cin.get(); } //----------------------------------------------------------------------------- // Pauses the output when output reaches bottom ------------------------------- void Console::auto__pause(int scroll) { if (scroll % 24 == 0 && scroll != 0) {pause();} } //----------------------------------------------------------------------------- // Pauses the output when output reaches bottom ------------------------------- void Console::auto__pause_quiet(int scroll) { if (scroll % 25 == 0 && scroll != 0) {cin.get();} } //----------------------------------------------------------------------------- // prints line by line a text file -------------------------------------------- void Console::draw_a_file(string filename) { ifstream in_; in_.open(filename.data()); string linebuf; getline(in_,linebuf); while(in_) { cout << linebuf << endl; getline(in_,linebuf); // cin.get(); // uncomment this line to have this method print line-by-line } in_.close(); } //----------------------------------------------------------------------------- // draws a horizontal line with the given fill and length --------------------- void Console::draw_a_line(char fill, int length) { for (int i = 0; i < length; i++) {cout << fill;} } //-----------------------------------------------------------------------------