Skip to content

Commit

Permalink
Like seriously, fuck them hard
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Herman committed Feb 17, 2017
1 parent dd20ee4 commit b11c5a7
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
59 changes: 59 additions & 0 deletions src/main.cpp
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;
}
19 changes: 19 additions & 0 deletions src/utils/README.md
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, =)

0 comments on commit b11c5a7

Please sign in to comment.