Print a newline around user interactions

This commit is contained in:
Sebastian Messmer 2015-09-04 16:09:37 +02:00
parent a665e6cdd7
commit 117930fad2
4 changed files with 18 additions and 6 deletions

View File

@ -63,7 +63,7 @@ bool CryConfigLoader::_showWarningForCipherAndReturnIfOk(const string &cipherNam
}
void CryConfigLoader::_generateEncKey(CryConfig *config) {
_console->print("Generating secure encryption key...");
_console->print("\nGenerating secure encryption key...");
config->SetEncryptionKey(CryCiphers::find(config->Cipher()).createKey());
_console->print("done\n");
}

View File

@ -65,7 +65,7 @@ unsigned int IOStreamConsole::ask(const string &question, const vector<string> &
if(options.size() == 0) {
throw std::invalid_argument("options should have at least one entry");
}
_output << question << "\n";
_output << "\n" << question << "\n";
for (unsigned int i = 0; i < options.size(); ++i) {
_output << " [" << (i+1) << "] " << options[i] << "\n";
}
@ -88,7 +88,7 @@ function<optional<bool>(const string &input)> parseYesNo() {
}
bool IOStreamConsole::askYesNo(const string &question) {
_output << question << "\n";
_output << "\n" << question << "\n";
return _askForChoice("Your choice [y/n]: ", parseYesNo());
}

View File

@ -20,6 +20,7 @@ TEST_F(ConsoleTest_Ask, CrashesWithoutOptions) {
TEST_F(ConsoleTest_Ask, OneOption) {
auto chosen = ask("My Question?", {"First Option"});
EXPECT_OUTPUT_LINES({
"",
"My Question?",
" [1] First Option"
});
@ -31,6 +32,7 @@ TEST_F(ConsoleTest_Ask, OneOption) {
TEST_F(ConsoleTest_Ask, TwoOptions_ChooseFirst) {
auto chosen = ask("My Question?", {"First Option", "Second Option"});
EXPECT_OUTPUT_LINES({
"",
"My Question?",
" [1] First Option",
" [2] Second Option"
@ -43,6 +45,7 @@ TEST_F(ConsoleTest_Ask, TwoOptions_ChooseFirst) {
TEST_F(ConsoleTest_Ask, TwoOptions_ChooseSecond) {
auto chosen = ask("My Question?", {"First Option", "Second Option"});
EXPECT_OUTPUT_LINES({
"",
"My Question?",
" [1] First Option",
" [2] Second Option"
@ -55,6 +58,7 @@ TEST_F(ConsoleTest_Ask, TwoOptions_ChooseSecond) {
TEST_F(ConsoleTest_Ask, ThreeOptions_ChooseFirst) {
auto chosen = ask("My Other Question?", {"1st Option", "2nd Option", "3rd Option"});
EXPECT_OUTPUT_LINES({
"",
"My Other Question?",
" [1] 1st Option",
" [2] 2nd Option",
@ -68,6 +72,7 @@ TEST_F(ConsoleTest_Ask, ThreeOptions_ChooseFirst) {
TEST_F(ConsoleTest_Ask, ThreeOptions_ChooseSecond) {
auto chosen = ask("My Question?", {"1st Option", "2nd Option", "3rd Option"});
EXPECT_OUTPUT_LINES({
"",
"My Question?",
" [1] 1st Option",
" [2] 2nd Option",
@ -81,6 +86,7 @@ TEST_F(ConsoleTest_Ask, ThreeOptions_ChooseSecond) {
TEST_F(ConsoleTest_Ask, ThreeOptions_ChooseThird) {
auto chosen = ask("My Question?", {"1st Option", "2nd Option", "3rd Option"});
EXPECT_OUTPUT_LINES({
"",
"My Question?",
" [1] 1st Option",
" [2] 2nd Option",
@ -94,6 +100,7 @@ TEST_F(ConsoleTest_Ask, ThreeOptions_ChooseThird) {
TEST_F(ConsoleTest_Ask, InputWithLeadingSpaces) {
auto chosen = ask("My Question?", {"First Option", "Second Option"});
EXPECT_OUTPUT_LINES({
"",
"My Question?",
" [1] First Option",
" [2] Second Option"
@ -106,6 +113,7 @@ TEST_F(ConsoleTest_Ask, InputWithLeadingSpaces) {
TEST_F(ConsoleTest_Ask, InputWithFollowingSpaces) {
auto chosen = ask("My Question?", {"First Option", "Second Option"});
EXPECT_OUTPUT_LINES({
"",
"My Question?",
" [1] First Option",
" [2] Second Option"
@ -118,6 +126,7 @@ TEST_F(ConsoleTest_Ask, InputWithFollowingSpaces) {
TEST_F(ConsoleTest_Ask, InputWithLeadingAndFollowingSpaces) {
auto chosen = ask("My Question?", {"First Option", "Second Option"});
EXPECT_OUTPUT_LINES({
"",
"My Question?",
" [1] First Option",
" [2] Second Option"
@ -130,6 +139,7 @@ TEST_F(ConsoleTest_Ask, InputWithLeadingAndFollowingSpaces) {
TEST_F(ConsoleTest_Ask, InputEmptyLine) {
auto chosen = ask("My Question?", {"First Option", "Second Option"});
EXPECT_OUTPUT_LINES({
"",
"My Question?",
" [1] First Option",
" [2] Second Option"
@ -146,6 +156,7 @@ TEST_F(ConsoleTest_Ask, InputEmptyLine) {
TEST_F(ConsoleTest_Ask, InputWrongNumbers) {
auto chosen = ask("My Question?", {"1st Option", "2nd Option"});
EXPECT_OUTPUT_LINES({
"",
"My Question?",
" [1] 1st Option",
" [2] 2nd Option",
@ -168,6 +179,7 @@ TEST_F(ConsoleTest_Ask, InputWrongNumbers) {
TEST_F(ConsoleTest_Ask, InputNonNumbers) {
auto chosen = ask("My Question?", {"1st Option", "2nd Option"});
EXPECT_OUTPUT_LINES({
"",
"My Question?",
" [1] 1st Option",
" [2] 2nd Option",

View File

@ -14,7 +14,7 @@ public:
void EXPECT_RESULT_ON_INPUT(const bool expected, const string &input) {
auto chosen = askYesNo("Are you sure blablub?");
EXPECT_OUTPUT_LINES({"Are you sure blablub?"});
EXPECT_OUTPUT_LINES({"", "Are you sure blablub?"});
EXPECT_OUTPUT_LINE("Your choice [y/n]", ':', " ");
sendInputLine(input);
EXPECT_EQ(expected, chosen.get());
@ -67,7 +67,7 @@ TEST_F(ConsoleTest_AskYesNo, InputWithLeadingAndFollowingSpaces) {
TEST_F(ConsoleTest_AskYesNo, InputEmptyLine) {
auto chosen = askYesNo("My Question?");
EXPECT_OUTPUT_LINES({"My Question?"});
EXPECT_OUTPUT_LINES({"", "My Question?"});
EXPECT_OUTPUT_LINE("Your choice [y/n]", ':', " ");
sendInputLine("");
EXPECT_OUTPUT_LINE("Your choice [y/n]", ':', " ");
@ -79,7 +79,7 @@ TEST_F(ConsoleTest_AskYesNo, InputEmptyLine) {
TEST_F(ConsoleTest_AskYesNo, WrongInput) {
auto chosen = askYesNo("My Question?");
EXPECT_OUTPUT_LINES({"My Question?"});
EXPECT_OUTPUT_LINES({"", "My Question?"});
EXPECT_OUTPUT_LINE("Your choice [y/n]", ':', " ");
sendInputLine("0");
EXPECT_OUTPUT_LINE("Your choice [y/n]", ':', " ");