commit 168b4f092caff12d2dddcf24fd85718d48e44a9a
parent 24f3108395e14e752c6f8fa2052a5c97309f595c
Author: NunoSempere <nuno.sempere@protonmail.com>
Date: Sun, 20 Aug 2023 12:11:47 +0200
add readme & makefile + small typo fixes.
Diffstat:
| A | README.md | | | 26 | ++++++++++++++++++++++++++ |
| A | makefile | | | 8 | ++++++++ |
| A | pomo.c | | | 56 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| D | spt.c | | | 58 | ---------------------------------------------------------- |
4 files changed, 90 insertions(+), 58 deletions(-)
diff --git a/README.md b/README.md
@@ -0,0 +1,26 @@
+# pomo - a simple pomodoro timer
+
+## about
+
+pomo is a simple timer that uses the pomodoro technique. It is based on [spt](https://github.com/pickfire/spt), which is a bit less simple.
+
+## dependencies
+
+Instead of inotify, this pomodoro timer uses [sent](https://tools.suckless.org/sent/), displaying messages to the user by spawning a process that calls `echo 'msg' | sent`.
+
+## installation
+
+Read pomo.c, then:
+
+```
+make
+sudo make install
+```
+
+## usage
+
+In a terminal, call the "pomo" command. Then, an initial message will appear in its own window. Close it and start working. By default, the timer runs by 4 pomodoro timer (25 mins) with subsequent rests in between (5 mins) followed by a long rest (15 mins) in an infinite loop.
+
+## configuration
+
+read through the <60 lines of C, and change as appropriate. If this functionality is too simple, consider looking at [spt](https://github.com/pickfire/spt) instead.
diff --git a/makefile b/makefile
@@ -0,0 +1,8 @@
+build:
+ gcc pomo.c -o pomo
+
+install:
+ mv ./pomo /bin/pomo
+
+lint:
+ clang-tidy pomo.c --
diff --git a/pomo.c b/pomo.c
@@ -0,0 +1,56 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#define MAX_MSG_LEN 100
+#define LEN(a) (sizeof(a) / sizeof(a[0]))
+
+typedef struct {
+ unsigned int t;
+ char *msg;
+} Timers;
+
+static Timers timers[] = {
+ /* timer(s) comment */
+ { 1500, "Time to start working!"},
+ { 300, "Time to start resting!"},
+ { 1500, "Time to start working!"},
+ { 300, "Time to start resting!"},
+ { 1500, "Time to start working!"},
+ { 300, "Time to start resting!"},
+ { 1500, "Time to start working!"},
+ { 900, "Time to take a longer rest!" },
+};
+
+void spawn(char *argv[]){
+ if (fork() == 0) {
+ // we need to fork the process so that
+ // when we exit the sent screen
+ // this program continues.
+ setsid();
+ execvp(argv[0], argv);
+ perror(" failed");
+ exit(0);
+ }
+}
+
+void display_message(char *msg){
+ char sh_command[MAX_MSG_LEN];
+ snprintf(sh_command, MAX_MSG_LEN, "echo '%s' | sent", msg); // NOLINT: We are being carefull here by considering MAX_MSG_LEN explicitly.
+ printf("%s", sh_command);
+ char *spawn_args[] = {
+ "/bin/sh",
+ "-c",
+ sh_command,
+ NULL
+ };
+ spawn(spawn_args);
+ // fprintf(stderr, "%s\n", msg);
+}
+
+int main(int argc, char *argv[]){
+ for(int i=0; ; i = (i+1) % LEN(timers)){
+ display_message(timers[i].msg);
+ sleep(timers[i].t);
+ }
+}
diff --git a/spt.c b/spt.c
@@ -1,58 +0,0 @@
-#include <unistd.h> // for the "sleep" & exec functions
-#include <stdio.h> // snprintf
-#include <stdlib.h> // exit
-
-#define MAX_MSG_LEN 100
-#define LEN(a) (sizeof(a) / sizeof(a[0]))
-
-typedef struct {
- unsigned int t;
- char *msg;
-} Timers;
-
-static Timers timers[] = {
- /* timer(s) comment */
- { 1500, "Time to start working!"},
- { 300, "Time to start resting!"},
- { 1500, "Time to start working!"},
- { 300, "Time to start resting!"},
- { 1500, "Time to start working!"},
- { 300, "Time to start resting!"},
- { 1500, "Time to start working!"},
- { 900, "Time to take a longer rest!" },
-};
-
-void spawn(char *argv[])
-{
- if (fork() == 0) {
- // we need to fork the process so that
- // when we exit the sent screen
- // this program continues.
- setsid();
- execvp(argv[0], argv);
- // printfn("spt: execvp %s\n", argv[0]);
- perror(" failed");
- exit(0);
- }
-}
-
-void display_message_with_sent(char *msg){
- char sh_command[MAX_MSG_LEN];
- snprintf(sh_command, MAX_MSG_LEN, "echo '%s' | sent", msg); // NOLINT: We are being carefull here by considering MAX_ERROR_LENGTH explicitly.
- printf("%s", sh_command);
- char *spawn_args[] = {
- "/bin/bash",
- "-c",
- sh_command,
- NULL
- };
- fprintf(stderr, "%s\n", msg);
- spawn(spawn_args);
-}
-
-int main(int argc, char *argv[]){
- for(int i=0; ; i = (i+1) % LEN(timers)){
- display_message_with_sent(timers[i].msg);
- sleep(timers[i].t);
- }
-}