From d3104d6d78445d9c7ccc21e13d8b075d94343cff Mon Sep 17 00:00:00 2001 From: Peetz0r Date: Mon, 5 Dec 2011 07:10:56 +0100 Subject: Add Apple ][ support --- src/nyancat.c | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/src/nyancat.c b/src/nyancat.c index 47eb26a..f5ba004 100644 --- a/src/nyancat.c +++ b/src/nyancat.c @@ -47,6 +47,7 @@ #include #include #include +#include /* * telnet.h contains some #defines for the various @@ -223,6 +224,7 @@ int main(int argc, char ** argv) { /* I have a bad habit of being very C99, so this may not be everything */ /* The default terminal is ANSI */ char term[1024] = {'a','n','s','i', 0}; + int terminal_width = 80; int k, ttype; uint32_t option = 0, done = 0, sb_mode = 0, do_echo = 0; /* Various pieces for the telnet communication */ @@ -351,6 +353,13 @@ int main(int argc, char ** argv) { * terminal type from the environment. */ char * nterm = getenv("TERM"); strcpy(term, nterm); + + /* Also get the number of columns, but not above 80 */ + struct winsize w; + ioctl(0, TIOCGWINSZ, &w); + terminal_width = w.ws_col; + + if(terminal_width > 80) terminal_width = 80; } /* @@ -383,6 +392,8 @@ ready: ttype = 4; /* Unicode fallback */ } else if (strstr(term, "rxvt")) { ttype = 3; /* Accepts LINUX mode */ + } else if (strstr(term, "vt100") && terminal_width == 40) { + ttype = 7; /* No color support, only 40 columns */ } else { ttype = 2; /* Everything else */ } @@ -490,6 +501,24 @@ ready: colors['%'] = "()"; /* Pink cheeks */ always_escape = 1; break; + case 7: + colors[','] = "."; /* Blue background */ + colors['.'] = "@"; /* White stars */ + colors['\''] = " "; /* Black border */ + colors['@'] = "#"; /* Tan poptart */ + colors['$'] = "?"; /* Pink poptart */ + colors['-'] = "O"; /* Red poptart */ + colors['>'] = "#"; /* Red rainbow */ + colors['&'] = "="; /* Orange rainbow */ + colors['+'] = "-"; /* Yellow Rainbow */ + colors['#'] = "+"; /* Green rainbow */ + colors['='] = "~"; /* Light blue rainbow */ + colors[';'] = "$"; /* Dark blue rainbow */ + colors['*'] = ";"; /* Gray cat face */ + colors['%'] = "o"; /* Pink cheeks */ + always_escape = 1; + terminal_width = 40; + break; default: break; } @@ -570,7 +599,7 @@ ready: double diff = difftime(current, start); /* Now count the length of the time difference so we can center */ int nLen = digits((int)diff); - int width = (80 - 29 - nLen) / 2; + int width = (terminal_width - 29 - nLen) / 2; /* Spit out some spaces so that we're actually centered */ while (width > 0) { printf(" "); @@ -578,9 +607,12 @@ ready: } /* You have nyaned for [n] seconds! * The \033[J ensures that the rest of the line has the dark blue - * background, and the \033[1;37m ensures that our text is bright white + * background, and the \033[1;37m ensures that our text is bright white. + * The \033[0m prevents the Apple ][ from flipping everything, but + * makes the whole nyancat less bright on the vt220 */ - printf("\033[1;37mYou have nyaned for %0.0f seconds!\033[J", diff); + printf("\033[1;37mYou have nyaned for %0.0f seconds!\033[J\033[0m", diff); + /* Reset the last color so that the escape sequences rewrite */ last = 0; /* Update frame crount */ -- cgit v1.2.3 From f36609e9b6f83df1849ef24297bdacdcb9c83659 Mon Sep 17 00:00:00 2001 From: Peetz0r Date: Mon, 5 Dec 2011 17:54:26 +0100 Subject: terminal_width now also working over telnet. --- src/nyancat.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/nyancat.c b/src/nyancat.c index f5ba004..88e0998 100644 --- a/src/nyancat.c +++ b/src/nyancat.c @@ -180,8 +180,8 @@ void set_options() { telnet_willack[ECHO] = DO; /* The client can set a graphics mode */ telnet_willack[SGA] = DO; - /* The client should not change the window size */ - telnet_willack[NAWS] = DONT; + /* The client should not change, but it should tell us its window size */ + telnet_willack[NAWS] = DO; /* The client should tell us its terminal type (very important) */ telnet_willack[TTYPE] = DO; /* No linemode */ @@ -262,7 +262,7 @@ int main(int argc, char ** argv) { alarm(1); /* Let's do this */ - while (!feof(stdin) && !done) { + while (!feof(stdin) && done < 2) { /* Get either IAC (start command) or a regular character (break, unless in SB mode) */ unsigned char i = getchar(); unsigned char opt = 0; @@ -278,7 +278,14 @@ int main(int argc, char ** argv) { * that this should be a terminal type */ alarm(0); strcpy(term, &sb[2]); - goto ready; + done++; + } + else if (sb[0] == NAWS) { + /* This was a response to the NAWS command, meaning + * that this should be a window size */ + alarm(0); + terminal_width = sb[2]; + done++; } break; case NOP: @@ -326,7 +333,7 @@ int main(int argc, char ** argv) { break; case IAC: /* IAC IAC? That's probably not right. */ - done = 1; + done = 2; break; default: break; @@ -338,7 +345,7 @@ int main(int argc, char ** argv) { * but only if it doesn't put us over * our limit; honestly, we shouldn't hit * the limit, as we're only collecting characters - * for a terminal type, but better safe than + * for a terminal type or window size, but better safe than * sorry (and vulernable). */ sb[sb_len] = i; @@ -361,7 +368,7 @@ int main(int argc, char ** argv) { if(terminal_width > 80) terminal_width = 80; } - + /* * Labels. Yes, and I used a goto. * If you're going to complain about this, you -- cgit v1.2.3 From 8fbebea71eeee07497797e9c3db3cdf132ada912 Mon Sep 17 00:00:00 2001 From: Peetz0r Date: Mon, 5 Dec 2011 18:22:58 +0100 Subject: I already removed the goto's, so let's remove the label as well. --- src/nyancat.c | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/nyancat.c b/src/nyancat.c index 88e0998..a0ef847 100644 --- a/src/nyancat.c +++ b/src/nyancat.c @@ -368,16 +368,6 @@ int main(int argc, char ** argv) { if(terminal_width > 80) terminal_width = 80; } - - /* - * Labels. Yes, and I used a goto. - * If you're going to complain about this, you - * really need to reevaluate your approach to getting - * things done. This works, it works well, and there - * is absolutely, positively nothing wrong with using - * goto in C, so I'm going to do it. - */ -ready: /* Convert the entire terminal string to lower case */ for (k = 0; k < strlen(term); ++k) { -- cgit v1.2.3 From 616b5189fac7f6d6b3b284224ba61bbf21ef61bb Mon Sep 17 00:00:00 2001 From: Peetz0r Date: Mon, 5 Dec 2011 18:25:53 +0100 Subject: Added my name in the comments ;) --- src/nyancat.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/nyancat.c b/src/nyancat.c index a0ef847..cb71217 100644 --- a/src/nyancat.c +++ b/src/nyancat.c @@ -1,8 +1,13 @@ /* * Copyright (c) 2011 Kevin Lange. All rights reserved. * - * Developed by: Kevin Lange - * http://github.com/klange/nyancat + * Developed by: Kevin Lange + * http://github.com/klange/nyancat + * http://miku.acm.uiuc.edu + * + * 40-column support by: Peter Hazenberg + * http://github.com/Peetz0r/nyancat + * http://peter.haas-en-berg.nl * * This is a simple telnet server / standalone application which renders the * classic Nyan Cat (or "poptart cat") to your terminal. -- cgit v1.2.3 From 5cc51e5021c5f12eaa9e3b918bb1b025d6dc27b6 Mon Sep 17 00:00:00 2001 From: Peetz0r Date: Mon, 5 Dec 2011 19:37:50 +0100 Subject: Actually limit the terminal width in the right place --- src/nyancat.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/nyancat.c b/src/nyancat.c index cb71217..70348e2 100644 --- a/src/nyancat.c +++ b/src/nyancat.c @@ -121,7 +121,7 @@ int digits(int val) { * (^C) so that we can restore the cursor. */ void SIGINT_handler(int sig){ - printf("\033[?25h\033[0m"); + printf("\\033[?25h\033[0m"); exit(0); } @@ -366,18 +366,19 @@ int main(int argc, char ** argv) { char * nterm = getenv("TERM"); strcpy(term, nterm); - /* Also get the number of columns, but not above 80 */ + /* Also get the number of columns */ struct winsize w; ioctl(0, TIOCGWINSZ, &w); terminal_width = w.ws_col; - - if(terminal_width > 80) terminal_width = 80; } /* Convert the entire terminal string to lower case */ for (k = 0; k < strlen(term); ++k) { term[k] = tolower(term[k]); } + + /* We don't want terminals wider than 80 columns */ + if(terminal_width > 80) terminal_width = 80; /* Do our terminal detection */ if (strstr(term, "xterm")) { -- cgit v1.2.3 From 4f158ad930771ffd0b7cda17ad3bd22bde192ca6 Mon Sep 17 00:00:00 2001 From: Peter Date: Mon, 5 Dec 2011 19:50:52 +0100 Subject: Oops... --- src/nyancat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nyancat.c b/src/nyancat.c index 70348e2..e65576c 100644 --- a/src/nyancat.c +++ b/src/nyancat.c @@ -121,7 +121,7 @@ int digits(int val) { * (^C) so that we can restore the cursor. */ void SIGINT_handler(int sig){ - printf("\\033[?25h\033[0m"); + printf("\033[?25h\033[0m"); exit(0); } -- cgit v1.2.3 From 322de459957620eef0cf8cf6d76c7bed4a63879b Mon Sep 17 00:00:00 2001 From: Peetz0r Date: Mon, 5 Dec 2011 23:41:38 +0100 Subject: remove crontab file --- crontab | 1 - 1 file changed, 1 deletion(-) delete mode 100644 crontab diff --git a/crontab b/crontab deleted file mode 100644 index f11c972..0000000 --- a/crontab +++ /dev/null @@ -1 +0,0 @@ -*/10 * * * * root /local/scratch/nyancat/reset.sh -- cgit v1.2.3 From 187a214e50f283eaf2f7dbe9985507a89b5a28b5 Mon Sep 17 00:00:00 2001 From: Peetz0r Date: Tue, 6 Dec 2011 10:54:48 +0100 Subject: Clear the screen when done (standalone, not telnet). --- src/nyancat.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/nyancat.c b/src/nyancat.c index e65576c..3cbca75 100644 --- a/src/nyancat.c +++ b/src/nyancat.c @@ -118,10 +118,10 @@ int digits(int val) { /* * In the standalone mode, we want to handle an interrupt signal - * (^C) so that we can restore the cursor. + * (^C) so that we can restore the cursor and clear the terminal. */ void SIGINT_handler(int sig){ - printf("\033[?25h\033[0m"); + printf("\033[?25h\033[0m\033[H\033[2J"); exit(0); } -- cgit v1.2.3