/* 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 CFconsole::clear() {

 for (int i = 0; i < 25; i++) {cout << endl;}
}
//-----------------------------------------------------------------------------
// Pauses the output ----------------------------------------------------------
void CFconsole::pause() {

 cout << "\t\t\t*Press Enter key to continue*"; 
 cin.get();
 cin.get();
}
//-----------------------------------------------------------------------------
// Quietly Pauses the output --------------------------------------------------
void CFconsole::pause_quiet() {
 cin.get();
}
//-----------------------------------------------------------------------------
// Pauses the output when output reaches bottom -------------------------------
void CFconsole::auto__pause(int scroll) {

 if (scroll % 24 == 0 && scroll != 0) {pause();}
}
//-----------------------------------------------------------------------------
// Pauses the output when output reaches bottom -------------------------------
void CFconsole::auto__pause_quiet(int scroll) {

 if (scroll % 25 == 0 && scroll != 0) {cin.get();}
}
//-----------------------------------------------------------------------------
// prints line by line a text file --------------------------------------------
void CFconsole::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 CFconsole::draw_a_line(char fill, int length) {

 for (int i = 0; i < length; i++) {cout << fill;}
}
//-----------------------------------------------------------------------------
char CFconsole::ask(string question) {
 char answer;
 cerr << question << ": ";
 cin  >> answer;
 return answer;
}

void CFconsole::title(string t) {
 draw_a_line('=',80);
 cout << "\t\t\t\t" << t << "\n";
 draw_a_line('=',80);
 cout << endl;
}

char CFconsole::make_menu(vector<string> &ops) {

 clear();
 title(ops[0]);

 for(int i=1; i < ops.size() -1; i++) {
  cout << "\t\t\t" << i << "\t" << ops[i] << endl;
 }
 cout << endl;
 cout << endl;
 draw_a_line('=',80);
 cout << " ";
 for(int j=1; j < ops.size() -1; j++) {
  cout << j << "=" << ops[j] << " | ";
 }
 return (ask(ops[ops.size() -1]));
}

char CFconsole::make_menu(vector<string> &ops, vector<char> &key) {

 if((ops.size()) != (key.size() +2)) {
  cerr << "malformed menu...aborting.";
  return '\0';
 }

 clear();
 title(ops[0]);

 for(int i=1; i < ops.size() -1; i++) {
  cout << "\t\t\t" << key[i-1] << "\t" << ops[i] << endl;
 }
 cout << endl;
 cout << endl;
 draw_a_line('=',80);
 cout << " ";
 for(int j=1; j < ops.size() -1; j++) {
  cout << key[j-1] << "=" << ops[j] << " | ";
 }
 return (ask(ops[ops.size() -1]));
}



w e b c p p
web c plus plus