add readme & makefile + small typo fixes.

This commit is contained in:
NunoSempere 2023-08-20 12:11:47 +02:00
parent 24f3108395
commit 168b4f092c
3 changed files with 43 additions and 11 deletions

26
README.md Normal file
View File

@ -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.

8
makefile Normal file
View File

@ -0,0 +1,8 @@
build:
gcc pomo.c -o pomo
install:
mv ./pomo /bin/pomo
lint:
clang-tidy pomo.c --

View File

@ -1,6 +1,6 @@
#include <unistd.h> // for the "sleep" & exec functions #include <stdio.h>
#include <stdio.h> // snprintf #include <stdlib.h>
#include <stdlib.h> // exit #include <unistd.h>
#define MAX_MSG_LEN 100 #define MAX_MSG_LEN 100
#define LEN(a) (sizeof(a) / sizeof(a[0])) #define LEN(a) (sizeof(a) / sizeof(a[0]))
@ -22,37 +22,35 @@ static Timers timers[] = {
{ 900, "Time to take a longer rest!" }, { 900, "Time to take a longer rest!" },
}; };
void spawn(char *argv[]) void spawn(char *argv[]){
{
if (fork() == 0) { if (fork() == 0) {
// we need to fork the process so that // we need to fork the process so that
// when we exit the sent screen // when we exit the sent screen
// this program continues. // this program continues.
setsid(); setsid();
execvp(argv[0], argv); execvp(argv[0], argv);
// printfn("spt: execvp %s\n", argv[0]);
perror(" failed"); perror(" failed");
exit(0); exit(0);
} }
} }
void display_message_with_sent(char *msg){ void display_message(char *msg){
char sh_command[MAX_MSG_LEN]; 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. 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); printf("%s", sh_command);
char *spawn_args[] = { char *spawn_args[] = {
"/bin/bash", "/bin/sh",
"-c", "-c",
sh_command, sh_command,
NULL NULL
}; };
fprintf(stderr, "%s\n", msg);
spawn(spawn_args); spawn(spawn_args);
// fprintf(stderr, "%s\n", msg);
} }
int main(int argc, char *argv[]){ int main(int argc, char *argv[]){
for(int i=0; ; i = (i+1) % LEN(timers)){ for(int i=0; ; i = (i+1) % LEN(timers)){
display_message_with_sent(timers[i].msg); display_message(timers[i].msg);
sleep(timers[i].t); sleep(timers[i].t);
} }
} }