commit d64475d8c0ae63bfed9d8a5a8ea8c51fa7070ded Author: Ari Archer Date: Tue May 10 00:11:05 2022 +0300 Init Signed-off-by: Ari Archer diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..1f4f375 --- /dev/null +++ b/.clang-format @@ -0,0 +1,19 @@ +--- +BasedOnStyle: LLVM +IndentWidth: 4 +SortIncludes: false +AlignConsecutiveAssignments: true +AlignConsecutiveBitFields: true +AlignConsecutiveMacros: true +AlignEscapedNewlines: true +AllowShortCaseLabelsOnASingleLine: true +AllowShortEnumsOnASingleLine: true +AllowShortFunctionsOnASingleLine: true +AllowShortLambdasOnASingleLine: true +BinPackParameters: false +IndentCaseBlocks: true +IndentCaseLabels: true +IndentExternBlock: true +IndentGotoLabels: true +--- + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ece9045 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/clrz +.ccls-cache diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..a3085cf --- /dev/null +++ b/LICENSE @@ -0,0 +1,14 @@ + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + Version 2, December 2004 + + Copyright (C) 2022 Ari Archer + + Everyone is permitted to copy and distribute verbatim or modified + copies of this license document, and changing it is allowed as long + as the name is changed. + + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. You just DO WHAT THE FUCK YOU WANT TO. + diff --git a/README.md b/README.md new file mode 100644 index 0000000..c3936f6 --- /dev/null +++ b/README.md @@ -0,0 +1,24 @@ +# Clrz + +> Fancy clear + +# Building + +Run any compilation script with your selected +(or custom) environment(s) + +```bash +$ . envs/reset.env && . envs/.... +$ ./com/.... +``` + +Or if it's a script, directly use it + +# Versions + +- C (C99) +- POSIX sh + +# License + +Do whatever the fuck you want lmfao diff --git a/com/clrz.99.c.sh b/com/clrz.99.c.sh new file mode 100755 index 0000000..7cac8ff --- /dev/null +++ b/com/clrz.99.c.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env sh + +set -e + +main() { + CC="${CC:-gcc}" + CFLAGS="${CFLAGS:--std=c99}" + SRC="${SRC:-./src/clrz.99.c}" + SFLAGS="${SFLAGS:--R .comment -R .GCC.command.line -R .note.gnu.gold-version -R .note.gnu.build-id -R .note.ABI-tag -R .note -R .gnu.version --strip-debug --strip-unneeded}" + + { + echo ' * Compiling C code' + echo " Source file: $SRC" + echo " C compiler: $CC" + echo " C Compiler Flags: $CFLAGS" + echo " Strip: ${STRIP:-No}" + echo " Strip flags: ${SFLAGS}" + } >&2 + + set -x + eval -- "$CC $SRC -o clrz $CFLAGS" + [ "$STRIP" ] && eval -- "strip $SFLAGS clrz" + set +x +} + +main "$@" diff --git a/envs/clang.env b/envs/clang.env new file mode 100644 index 0000000..a000b69 --- /dev/null +++ b/envs/clang.env @@ -0,0 +1 @@ +export CC='clang' diff --git a/envs/debug.env b/envs/debug.env new file mode 100644 index 0000000..2c54a61 --- /dev/null +++ b/envs/debug.env @@ -0,0 +1 @@ +export CFLAGS='-g -g3 -O0 -fno-eliminate-unused-debug-types -std=c99 -D_DEBUG' diff --git a/envs/prod.env b/envs/prod.env new file mode 100644 index 0000000..3560b21 --- /dev/null +++ b/envs/prod.env @@ -0,0 +1,5 @@ +export CFLAGS="-Ofast -std=c99 -s -flto -march=native \ + -Wall -Wextra -Wpedantic -pedantic -pie -fPIE -Werror \ + -Wconversion -Wsign-conversion \ + -Wl,-z,relro,-z,now,-z,noexecstack" +export STRIP='Yes' diff --git a/envs/reset.env b/envs/reset.env new file mode 100644 index 0000000..cc29533 --- /dev/null +++ b/envs/reset.env @@ -0,0 +1 @@ +unset CC CFLAGS STRIP diff --git a/src/clrz.99.c b/src/clrz.99.c new file mode 100644 index 0000000..fb6e3db --- /dev/null +++ b/src/clrz.99.c @@ -0,0 +1,84 @@ +#ifndef _XOPEN_SOURCE +#define _XOPEN_SOURCE 500 +#endif + +/* ************* + * ANSI stuff + */ + +#define CSI "\033[" + +#define ANSI_CUR_SAVE CSI "s" +#define ANSI_CUR_RES CSI "u" +#define ANSI_CUR_HIDE CSI "?25l" +#define ANSI_CUR_SHOW CSI "?25h" + +#define ANSI_CLEAR CSI "2J" CSI "1;1H" + +#define NONL(code) fputs(code, stdout) + +/* ************* + * Config + */ + +#ifndef SLEEP_TIME +#define SLEEP_TIME 15000 +#endif + +#ifdef _DEBUG +#define DP(msg) \ + fputs("[DEBUG] " msg "\n Press enter to continue....", stderr); \ + getchar(); +#else +#define DP(msg) +#endif + +#include +#include +#include + +static unsigned char clrz(void) { + DP("Getting terminal size"); + + struct winsize ws; + if (ioctl(1, TIOCGWINSZ, &ws) != 0) { + perror("ioctl()"); + return 1; + } + + DP("Making a column"); + + char col[ws.ws_col]; + + for (unsigned short int idx = 0; idx < ws.ws_col; ++idx) + col[idx] = ' '; + + DP("Setting up cursor"); + + NONL(ANSI_CUR_HIDE); + NONL(ANSI_CUR_SAVE); + + DP("Filling up columns"); + + for (unsigned short int line = 0; line < ws.ws_row; ++line) { + printf(CSI "%d;%dH", line, 0); // ANSI_CUP + NONL(col); + +#ifndef HAVE_BUFFERING + fflush(stdout); +#endif + usleep(SLEEP_TIME); + } + + DP("Cleanup"); + + NONL(ANSI_CUR_RES); + NONL(ANSI_CLEAR); + NONL(ANSI_CUR_SHOW); + + return 0; +} + +#ifndef CLRZ_H +int main(void) { return clrz(); } +#endif diff --git a/src/clrz.sh b/src/clrz.sh new file mode 100755 index 0000000..1dfef63 --- /dev/null +++ b/src/clrz.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env sh + +set -e + +main() { + tput civis + printf "\033[s" + + for line in 0 $(seq "$(tput lines)"); do + for col in 0 $(seq "$(tput cols)"); do + tput cup "$line" "$col" + printf ' ' + done + done + + printf "\033[u" + clear + + tput cnorm +} + +main "$@"