Skip to content

Commit

Permalink
Fixed type conversion mistake and added console colors.
Browse files Browse the repository at this point in the history
  • Loading branch information
StevenJDH committed Jul 19, 2018
1 parent b6d636c commit cb4c122
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Changelog: https://github.com/StevenJDH/The-Terminator/wiki/Changelog
* Kill running processes by name
* Rename or delete a file immediately after killing a process
* Text-based user interface and command line access
* Support for console colors, which could later become a customizable feature
* Support for 32/64-bit Windows systems

## Command line usage
Expand Down
6 changes: 3 additions & 3 deletions TheTerminator.layout
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Order=0
Focused=0
[Editor_0]
CursorCol=23
CursorRow=28
TopLine=10
CursorCol=75
CursorRow=111
TopLine=391
LeftChar=1
Binary file modified terminator-ss.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 19 additions & 4 deletions terminator.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
#define VERSION "1.0.0"
#define VERSION_DATE "2018/07/19"

// Console colors.
enum colors { BLACK = 0, BLUE, GREEN, AQUA, RED, PURPLE, YELLOW, WHITE, GREY, LIGHTBLUE,
LIGHTGREEN, LIGHTAQUA, LIGHTRED, LIGHTPURPLE, LIGHTYELLOW, BRIGHTWHITE };

int argsCLI(int argc, char** argv);
int printUsage(const char *program_name);
Expand All @@ -43,12 +46,16 @@ bool killRenameOption(const char *process_name, const char *old_name, const char
bool killDeleteOption(const char *process_name, const char *filename);
bool killProcessByName(const char *process_name);
const char *gnuBasename(const char *filename);
void setConsoleColors(enum colors textColor, enum colors bgColor);

int main(int argc, char** argv) {
// Using CLI mode if arguments were passed.
if (argc > 1) {
return argsCLI(argc, argv);
}

// Changes the console's foreground and background colors.
setConsoleColors(LIGHTYELLOW, BLUE);

unsigned int choice = 0; // Used for determining which screen to show.

Expand All @@ -73,12 +80,15 @@ int main(int argc, char** argv) {
default:
// A controlled exit from the program.
printf("\nI'll be back. ");
fflush(stdout); // We flush buffer before system() screen I/O, which is required.
system("pause");
// We flush buffer before system() screen I/O, which is required.
fflush(stdout);
// Pauses and then clears screen after unpausing to clean things up.
// We also reset console colors in between calls this way to play well with CLS.
system("pause & COLOR 07 & cls");
}
}
while (99 == choice); // Returns control back to main menu.

return EXIT_SUCCESS;
}

Expand Down Expand Up @@ -389,7 +399,7 @@ bool killProcessByName(const char *process_name)
{
TerminateProcess(hProcess, 9);
CloseHandle(hProcess);
printf("Terminated process - %s (PID: %d)\n", pEntry.szExeFile, pEntry.th32ProcessID);
printf("Terminated process - %s (PID: %lu)\n", pEntry.szExeFile, pEntry.th32ProcessID);
hasKilled = true;
}
}
Expand All @@ -409,3 +419,8 @@ const char *gnuBasename(const char *filename)
const char *base = strrchr(filename, '\\'); // Returns pointer to last occurrence or null if none.
return base ? ++base : filename; // One more than the last occurrence, which is the filename, otherwise it's already the filename.
}

// Changes the foreground and the background of the console. Default Colors: (WHITE, BLACK).
void setConsoleColors(enum colors textColor, enum colors bgColor) {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), (textColor + (bgColor * 16)));
}

0 comments on commit cb4c122

Please sign in to comment.