📄 cui.h
字号:
/**********************************************************************************
* *
* Henry Banking System ATM Module *
* Copyright (c) 2004 by Henry. All rights reserved. *
* *
* Permission to use, copy, modify, and distribute this software for any purpose *
* is hereby granted without fee, provided that this copyright and permissions *
* notice appear in all copies and derivatives, and that no charge may be made *
* for the software and its documentation except to cover cost of distribution. *
* *
* This software is provided "as is" without express or implied warranty. *
* *
**********************************************************************************/
/*
* Description:
*
* Generate component in a CUI way.
*
* Notes:
*
* This code has been written to conform to standard C++ and STL. It has been
* compiled successfully using Visual C++ 7.0.
*/
#ifndef GUARD_cui_h
#define GUARD_cui_h
#include <iostream>
#include <string>
#include <vector>
using namespace std;
namespace cui
{
class Menu
{
private:
vector<string> items[2];
public:
void (*onSelect)(size_t index);
static size_t language;
Menu();
static void showWelcome();
void add(string, string);
void clear();
size_t show();
};
template <class T>
class Input
{
public:
static T show(string title0, string title1)
{
T value;
if(Menu::language == 0)
cout << title0;
else
cout << title1;
cin >> value;
string str;
getline(cin, str);
cout << endl;
return value;
}
static bool validateString(const string& value, size_t maxLen, size_t minLen)
{
if(value.length() > maxLen) return false;
if(value.length() < minLen) return false;
return true;
}
};
class Alert
{
public:
static void show(string title0, string title1)
{
if(Menu::language == 0)
cout << title0 << " (Press enter to continue)";
else
cout << title1 << "(按回车键继续)";
string str;
getline(cin, str);
cout << endl;
}
};
class Confirm
{
public:
static bool show(string title0, string title1)
{
string response;
while(response != "y" && response != "Y" && response != "n" && response != "N")
{
if(Menu::language == 0)
cout << title0 << " (Y = Yes, N = No)";
else
cout << title1 << "(Y = 是,N = 否)";
cin >> response;
}
string str;
getline(cin, str);
cout << endl;
if(response == "y" || response == "Y")
return true;
else
return false;
}
};
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -