Permalink
Browse files

Like seriously, fuck them hard

  • Loading branch information...
1 parent dd20ee4 commit b11c5a7f7b12b4697d13b3147638d19696291fa6 Daniel Herman committed Feb 17, 2017
Showing with 78 additions and 0 deletions.
  1. +59 −0 src/main.cpp
  2. +19 −0 src/utils/README.md
View
@@ -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;
+}
View
@@ -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.