Browse Source

Merge pull request #26 from alpheratz0/countdown-exit

add `-e` option to exit when the countdown ends
Alexey Kutepov 3 years ago
parent
commit
8e16bddec8
5 changed files with 32 additions and 21 deletions
  1. 15 14
      .github/workflows/ci.yml
  2. 2 1
      .gitignore
  3. 5 5
      Makefile
  4. 3 1
      docs/sowon.6
  5. 7 0
      main.c

+ 15 - 14
.github/workflows/ci.yml

@@ -54,17 +54,18 @@ jobs:
         shell: cmd
         run: |
           ./build_msvc.bat
-  build-freebsd:
-    runs-on: macos-latest
-    name: FreeBSD LLVM Clang build
-    steps:
-      - uses: actions/checkout@v2
-      - name: Build on FreeBSD
-        id: build
-        uses: vmactions/[email protected]
-        with:
-          usesh: true
-          prepare: pkg install -y sdl2 pkgconf
-          run: |
-            freebsd-version
-            make
+# TODO: FreeBSD build is broken
+#  build-freebsd:
+#    runs-on: macos-latest
+#    name: FreeBSD LLVM Clang build
+#    steps:
+#      - uses: actions/checkout@v2
+#      - name: Build on FreeBSD
+#        id: build
+#        uses: vmactions/[email protected]
+#        with:
+#          usesh: true
+#          prepare: pkg install -y sdl2 pkgconf
+#          run: |
+#            freebsd-version
+#            make

+ 2 - 1
.gitignore

@@ -6,4 +6,5 @@ digits.h
 SDL2
 *.obj
 *.exe
-.dSYM/
+.dSYM/
+*.gz

+ 5 - 5
Makefile

@@ -2,7 +2,7 @@ COMMON_CFLAGS=		-Wall -Wextra -std=c99 -pedantic
 CFLAGS+=		`pkg-config --cflags sdl2` $(COMMON_CFLAGS)
 COMMON_LIBS=		-lm
 LIBS=			`pkg-config --libs sdl2` $(COMMON_LIBS)
-PREFIX?=		/usr/local/
+PREFIX?=		/usr/local
 INSTALL?=		install
 
 .PHONY: all
@@ -29,7 +29,7 @@ clean:
 
 .PHONY: install
 install: all
-	$(INSTALL) -d $(DESTDIR)/$(PREFIX)/bin
-	$(INSTALL) -C ./sowon $(DESTDIR)/$(PREFIX)/bin
-	$(INSTALL) -d $(DESTDIR)/$(PREFIX)/man/man6
-	$(INSTALL) -C docs/sowon.6.gz $(DESTDIR)/$(PREFIX)/man/man6
+	$(INSTALL) -d $(DESTDIR)$(PREFIX)/bin
+	$(INSTALL) -C ./sowon $(DESTDIR)$(PREFIX)/bin
+	$(INSTALL) -d $(DESTDIR)$(PREFIX)/man/man6
+	$(INSTALL) -C docs/sowon.6.gz $(DESTDIR)$(PREFIX)/man/man6

+ 3 - 1
docs/sowon.6

@@ -6,7 +6,7 @@
 .Nd Starting soon timer
 .Sh SYNOPSIS
 .Nm
-.Op Fl p
+.Op Fl pe
 .Op Ar seconds | Ar clock
 .Sh DESCRIPTION
 .Nm
@@ -20,6 +20,8 @@ the current time.
 .Bl -tag -width indent
 .It Fl p
 start in paused state
+.It Fl e
+exit the application when the countdown ends
 .Sh KEY BINDINGS
 .Bl -tag -width indent
 .It SPACE

+ 7 - 0
main.c

@@ -153,10 +153,13 @@ int main(int argc, char **argv)
     Mode mode = MODE_ASCENDING;
     float displayed_time = 0.0f;
     int paused = 0;
+    int exit_after_countdown = 0;
 
     for (int i = 1; i < argc; ++i) {
         if (strcmp(argv[i], "-p") == 0) {
             paused = 1;
+        } if (strcmp(argv[i], "-e") == 0) {
+            exit_after_countdown = 1;
         } else if (strcmp(argv[i], "clock") == 0) {
             mode = MODE_CLOCK;
         } else {
@@ -316,6 +319,10 @@ int main(int argc, char **argv)
                     displayed_time -= DELTA_TIME;
                 } else {
                     displayed_time = 0.0f;
+                    if (exit_after_countdown) {
+                        SDL_Quit();
+                        return 0;
+                    }
                 }
             } break;
             case MODE_CLOCK: {