Warning dependency cycle detected when installing lolcat

Because it’s mEMoRy sAFe! :frog:

1 Like

I think it’s code, not memory safety here… :rofl:

My brain could use some memory safety :dotted_line_face:

2 Likes

It’s about time to rewrite brain in rust! :man_beard:

1 Like

I fixed a bug where atrazine would leave the terminal dirty in case it is interrupted by a signal.

LATEST VERSION

Source
// compile with: gcc atrazine.c -o atrazine -lm -O2 -Wpedantic -Wall -Wextra

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

#define CSI "\033["
#define RESET CSI"m"

void cleanup(void) {
  printf(RESET);
}

void rainbow(float phase) {
  printf("%s38;2;%d;%d;%dm", CSI,
    /* red   */ (int) (sinf(phase + 0       ) * 127 + 128),
    /* green */ (int) (sinf(phase + 2*M_PI/3) * 127 + 128),
    /* blue  */ (int) (sinf(phase + 4*M_PI/3) * 127 + 128)
  );
}

inline int is_UTF8_continuation(char c) {
  return (c & 0xc0) == 0x80;
}

/* state machine that detects ANSI escape sequences, somewhat poorly */
int in_ANSI(char c) {
  static int state = 0;
  if (state && (isalpha(c) || c == '~' || c == '\033'))  state = 0;
  if (c == '\033' && !state)                             state = 1;
  return state;
}

int main() {
  float omega = 0.05f;
  int nl_offset = 3, t = 0, line = 0;
  char c, peek;

  atexit(cleanup);

  rainbow(omega * t);

  while ((c = getchar()) != EOF) {
    peek = getchar();
    ungetc(peek, stdin);

    if (c == '\n') {
      t = 0;
      line++;
      printf(RESET);
    }

    printf("%c", c);

    if (!is_UTF8_continuation(peek) && !in_ANSI(c)) {
      rainbow(omega * ((++t) + nl_offset * line));
    }
  }
}

Also, angular frequency is adjusted to make a bigger, smoother rainbow. I should probably randomise it in a later version…

3 Likes

As long as it won’t affect speed it sounds cool! :+1:

P.S. Your slow neofetch makes my fastfetch sad

honka_animated-128px-34

It’s just

float omega = 0.05f;

instead of

float omega = 0.1f;

But “angular frequency” sounds like I know what I’m doing… :frog:

1 Like

Can your fastfetch do this:

?

I don’t freakin’ think so. :frog:

Here is a little secret
~🐸 which neofetch
neofetch: aliased to cat ~/.nf

And I have in my .zshrc

setsid neofetch >| .nf

:rofl:

2 Likes

ChEaTEr!!111 :frog:

Almost, it’s NOT cached btw, written in C.

real    0m0,029s
user    0m0,011s
sys     0m0,004s

If you cache it, you can imagine it will be even faster :rofl:

1 Like