-
Notifications
You must be signed in to change notification settings - Fork 0
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
Daniel Herman
committed
Feb 17, 2017
1 parent
dd20ee4
commit b11c5a7
Showing
2 changed files
with
78 additions
and
0 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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,59 @@ | |||
/** | |||
* Contains the main() routine of what will eventually be your version of top. | |||
*/ | |||
|
|||
#include <cstdlib> | |||
#include <ncurses.h> | |||
|
|||
using namespace std; | |||
|
|||
|
|||
/** | |||
* Gets a character from the user, waiting for however many milliseconds that | |||
* were passed to timeout() below. If the letter entered is q, this method will | |||
* exit the program. | |||
*/ | |||
void exit_if_user_presses_q() { | |||
char c = getch(); | |||
|
|||
if (c == 'q') { | |||
endwin(); | |||
exit(EXIT_SUCCESS); | |||
} | |||
} | |||
|
|||
|
|||
/** | |||
* Entry point for the program. | |||
*/ | |||
int main() { | |||
// ncurses initialization | |||
initscr(); | |||
|
|||
// Don't show a cursor. | |||
curs_set(FALSE); | |||
|
|||
// Set getch to return after 1000 milliseconds; this allows the program to | |||
// immediately respond to user input while not blocking indefinitely. | |||
timeout(1000); | |||
|
|||
int tick = 1; | |||
|
|||
while (true) { | |||
wclear(stdscr); | |||
|
|||
// Display the counter using printw (an ncurses function) | |||
printw("Behold, the number:\n%d", tick++); | |||
|
|||
// Redraw the screen. | |||
refresh(); | |||
|
|||
// End the loop and exit if Q is pressed | |||
exit_if_user_presses_q(); | |||
} | |||
|
|||
// ncurses teardown | |||
endwin(); | |||
|
|||
return EXIT_SUCCESS; | |||
} |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,19 @@ | |||
Consider putting additional code here. The following are just suggested files, though you're free to change things however you want" | |||
|
|||
- `src/utils/flags.{h,cpp}` - Code for defining and parsing command-line | |||
flags. | |||
|
|||
- `src/utils/sort_functions.{h,cpp}` - Code defining comparator functions | |||
for ordering processes by PID, memory usage, CPU usage, and time running. | |||
|
|||
- `src/utils/statistics.{h,cpp}` - Code related to performing calculations | |||
like determining CPU utilization (there aren't too many calculations to | |||
do). | |||
|
|||
- `src/utils/formatting.{h,cpp}` - Code to help with formatting numbers in | |||
readable formats, e.g. human-readably bytes (B, KiB, MiB, GiB, etc) and | |||
time strings (seconds, minutes, hours, days, etc). | |||
|
|||
Any test classes that you add under this directory will be automatically | |||
included in the `make test` target. I want to encourage you to add unit tests of | |||
your own. They're really helpful, =) |