Signed-off-by: Ari Archer <ari.web.xyz@gmail.com>
This commit is contained in:
Ari Archer 2022-05-10 00:11:05 +03:00
commit d64475d8c0
Signed by untrusted user who does not match committer: ari
GPG key ID: A50D5B4B599AF8A2
11 changed files with 199 additions and 0 deletions

19
.clang-format Normal file
View file

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

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
/clrz
.ccls-cache

14
LICENSE Normal file
View file

@ -0,0 +1,14 @@
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2022 Ari Archer <ari.web.xyz@gmail.com>
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.

24
README.md Normal file
View file

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

26
com/clrz.99.c.sh Executable file
View file

@ -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 "$@"

1
envs/clang.env Normal file
View file

@ -0,0 +1 @@
export CC='clang'

1
envs/debug.env Normal file
View file

@ -0,0 +1 @@
export CFLAGS='-g -g3 -O0 -fno-eliminate-unused-debug-types -std=c99 -D_DEBUG'

5
envs/prod.env Normal file
View file

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

1
envs/reset.env Normal file
View file

@ -0,0 +1 @@
unset CC CFLAGS STRIP

84
src/clrz.99.c Normal file
View file

@ -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 <stdio.h>
#include <unistd.h>
#include <sys/ioctl.h>
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

22
src/clrz.sh Executable file
View file

@ -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 "$@"