-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
115 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#include "watch-mode.h" | ||
#include <iostream> | ||
#include <termios.h> | ||
#include <unistd.h> | ||
|
||
#define ASCII_GRAY "\u001b[38;5;243m" | ||
#define ASCII_BLACK "\u001b[38;5;232m" | ||
#define ASCII_BOLD "\u001b[1m" | ||
#define ASCII_RESET "\033[0m" | ||
|
||
static char waitForKey() | ||
{ | ||
struct termios old_term, new_term; | ||
tcgetattr(STDIN_FILENO, &old_term); | ||
|
||
new_term = old_term; | ||
new_term.c_lflag &= ~(ICANON | ECHO); | ||
|
||
tcsetattr(STDIN_FILENO, TCSANOW, &new_term); | ||
char ch = getchar(); | ||
tcsetattr(STDIN_FILENO, TCSANOW, &old_term); | ||
|
||
return ch; | ||
} | ||
|
||
WatchMode::Option WatchMode::waitForInput() | ||
{ | ||
auto key = waitForKey(); | ||
|
||
switch (key) | ||
{ | ||
case 'f': | ||
return Option::Failed; | ||
break; | ||
case 'p': | ||
return Option::FileName; | ||
break; | ||
case 't': | ||
return Option::TestName; | ||
break; | ||
case 'q': | ||
return Option::Quit; | ||
break; | ||
case '\n': | ||
return Option::Trigger; | ||
break; | ||
} | ||
|
||
return Option::None; | ||
} | ||
|
||
void WatchMode::showHelp() | ||
{ | ||
std::cout << std::endl; | ||
std::cout << ASCII_BOLD << "Watch Usage" << ASCII_RESET << std::endl; | ||
std::cout << ASCII_GRAY << " › Press " << ASCII_BLACK << "f" << ASCII_GRAY <<" to run only failed tests." << ASCII_RESET << std::endl; | ||
std::cout << ASCII_GRAY << " › Press " << ASCII_BLACK << "p" << ASCII_GRAY <<" to filter by a filename regex pattern." << ASCII_RESET << std::endl; | ||
std::cout << ASCII_GRAY << " › Press " << ASCII_BLACK << "t" << ASCII_GRAY <<" to filter by a test name regex pattern." << ASCII_RESET << std::endl; | ||
std::cout << ASCII_GRAY << " › Press " << ASCII_BLACK << "q" << ASCII_GRAY <<" to quit watch mode." << ASCII_RESET << std::endl; | ||
std::cout << ASCII_GRAY << " › Press " << ASCII_BLACK << "Enter" ASCII_GRAY << " to trigger a test run." << ASCII_RESET << std::endl; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#pragma once | ||
|
||
namespace WatchMode | ||
{ | ||
enum class Option | ||
{ | ||
Failed, | ||
FileName, | ||
TestName, | ||
Trigger, | ||
Quit, | ||
None | ||
}; | ||
|
||
void showHelp(); | ||
Option waitForInput(); | ||
} |