From 25eb781c47bfd43aac02b97f4c3a967c360f4b17 Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Fri, 4 Sep 2020 18:41:04 -0400 Subject: Add nudge --- bin/.gitignore | 1 + bin/Makefile | 1 + bin/README.7 | 4 +++- bin/man1/nudge.1 | 38 +++++++++++++++++++++++++++++++ bin/nudge.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 bin/man1/nudge.1 create mode 100644 bin/nudge.c diff --git a/bin/.gitignore b/bin/.gitignore index cf808c77..6daf18fc 100644 --- a/bin/.gitignore +++ b/bin/.gitignore @@ -14,6 +14,7 @@ glitch hi hnel modem +nudge open order pbcopy diff --git a/bin/Makefile b/bin/Makefile index 61e405c0..28136ad2 100644 --- a/bin/Makefile +++ b/bin/Makefile @@ -28,6 +28,7 @@ BINS += glitch BINS += hi BINS += hnel BINS += modem +BINS += nudge BINS += order BINS += pbd BINS += pngo diff --git a/bin/README.7 b/bin/README.7 index 16d86c67..a0fcb236 100644 --- a/bin/README.7 +++ b/bin/README.7 @@ -1,4 +1,4 @@ -.Dd June 17, 2020 +.Dd September 4, 2020 .Dt BIN 7 .Os "Causal Agency" . @@ -42,6 +42,8 @@ syntax highlighter PTY input remapper .It Xr modem 1 fixed baud rate wrapper +.It Xr nudge 1 +terminal vibrator .It Xr order 1 operator precedence .It Xr pbd 1 diff --git a/bin/man1/nudge.1 b/bin/man1/nudge.1 new file mode 100644 index 00000000..143a24ba --- /dev/null +++ b/bin/man1/nudge.1 @@ -0,0 +1,38 @@ +.Dd September 4, 2020 +.Dt NUDGE 1 +.Os +. +.Sh NAME +.Nm nudge +.Nd terminal vibrator +. +.Sh SYNOPSIS +.Nm +.Op Fl n Ar count +.Op Fl s Ar shake +.Op Fl t Ar delay +. +.Sh DESCRIPTION +The +.Nm +utility +nudges the terminal. +An +.Xr xterm 1 +compatible terminal is required. +. +.Pp +The arguments are as follows: +.Bl -tag -width Ds +.It Fl n Ar count +Set the number of times +to nudge the terminal. +The default is 2. +.It Fl s Ar shake +Set the shake intensity in pixels. +The default is 10. +.It Fl t Ar delay +Set the interval between shakes +in milliseconds. +The default is 20. +.El diff --git a/bin/nudge.c b/bin/nudge.c new file mode 100644 index 00000000..da406acc --- /dev/null +++ b/bin/nudge.c @@ -0,0 +1,68 @@ +/* Copyright (C) 2020 C. McEnroe + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include +#include +#include +#include +#include +#include + +static int shake = 10; +static int delay = 20000; +static int count = 2; + +static void move(int x, int y) { + fprintf(stderr, "\33[3;%d;%dt", x, y); + usleep(delay); +} + +int main(int argc, char *argv[]) { + for (int opt; 0 < (opt = getopt(argc, argv, "n:s:t:"));) { + switch (opt) { + break; case 'n': count = atoi(optarg); + break; case 's': shake = atoi(optarg); + break; case 't': delay = atoi(optarg) * 1000; + break; default: return EX_USAGE; + } + } + + struct termios save; + int error = tcgetattr(STDIN_FILENO, &save); + if (error) err(EX_IOERR, "tcgetattr"); + + struct termios raw = save; + cfmakeraw(&raw); + error = tcsetattr(STDIN_FILENO, TCSAFLUSH, &raw); + if (error) err(EX_IOERR, "tcsetattr"); + + int x, y; + fprintf(stderr, "\33[13t"); + int n = scanf("\33[3;%d;%dt", &x, &y); + + error = tcsetattr(STDIN_FILENO, TCSANOW, &save); + if (error) err(EX_IOERR, "tcsetattr"); + if (n < 2) return EX_CONFIG; + + fprintf(stderr, "\33[5t"); + for (int i = 0; i < count; ++i) { + move(x - shake, y); + move(x, y + shake); + move(x + shake, y); + move(x, y - shake); + move(x, y); + } +} -- cgit 1.4.1