Commits

Anonymous committed aa9ae1b

add margin option

  • Participants
  • Parent commits 4ae841a

Comments (0)

Files changed (3)

File config.def.h

  * Use this if you want colors and bell on your nick. You can first edit
  * cw_color.sh to change the nick if you don't want to use -n nick every time,
  * then place it in your path. It is not installed by default.
- * char *cmd[] = { "urxvt", "-title", path, "-e", "srw", "-p", prompt, "cw_color.sh", out, in, nick, NULL };
+ * char *cmd[] = { "urxvt", "-title", path, "-e", "srw", "-p", prompt, "cw_color.sh", "-i", out, "-o", in, "-n", nick, NULL };
+ *
+ * If you have the nickalign patch and want the text to wrap back to the end of
+ * the nicks instead of the beginning of the terminal, try one of these. You
+ * may have to change the number, which is the number of spaces until the |
+ * char *cmd[] = { "urxvt", "-title", path, "-e", "srw", "-p", prompt, "cw", out, in, "30", NULL };
+ * char *cmd[] = { "urxvt", "-title", path, "-e", "srw", "-p", prompt, "cw_color.sh", "-i", out, "-o", in, "-m", "30", "-n", nick, NULL };
  *
  * Use this if you want to use tabbed (http://tools.suckless.org/tabbed) so
  * that each new channel is it's own tab. Start tabbed with -d, then export the
 FILE *in, *out;
 char buf[4096];
 struct winsize ws;
-int margin = 30;
+char margin = 0;
 
 void print_line(char *line)
 {
-	int len = strlen(line);
-	int i, cols = ws.ws_col;
+	int i, len, cols = ws.ws_col;
+	char *m;
+
+	if (!margin) {
+		fputs(line, stdout);
+		return;
+	}
+
+	len = strlen(line);
+	m = strchr(line, margin);
 
 	if (line[len - 1] == '\n')
 		line[--len] = '\0';
 	printf("%.*s\n", cols, line);
 
 	for (i = cols; i < len; i += cols)
-		printf("%*s| %.*s\n", margin - 2, "", cols - margin, line + i);
+		printf("%*s%c %.*s\n", (int)(m - line), "", margin, cols - (int)(m - line), line + i);
 }
 
 void sigwinch(int unused)
 	int evq, in_wd;
 	fd_set rd;
 
-	if (argc != 3) {
-		printf("Usage: cw infile outfile\n");
+	if (argc == 4) {
+		margin = argv[3][0];
+	} else if (argc != 3) {
+		printf("Usage: cw infile outfile [margin]\n");
 		printf("cw-"VERSION" © Evan Gates\n");
 		exit(1);
 	}

File extras/cw_color.sh

 # Make sure to change NICK to your correct nick and feel free to change the formatting to your liking
 #
 
-NICK="$USER"
-
 reset="$(tput sgr0)"
 
 bold="$(tput bold)"
 bg_cyan="$(tput setab 6)"
 bg_white="$(tput setab 7)"
 
-if [ $# -eq 3 -a -n "$3" ]; then
-    NICK="$3"
-fi
+NICK="$USER"
+MARGIN=
 
-cw "$1" "$2" | sed -e "s/^\([-0-9]\{10,10\}\) \([:0-9]\{5,5\}\) <\([^>]*\)>/${yellow}\1 ${green}\2${reset} <${cyan}\3${reset}>/" \
-                   -e "s/^\([-0-9]\{10,10\}\) \([:0-9]\{5,5\}\) \(-!-\)/${yellow}\1 ${green}\2${reset} ${magenta}\3${reset}/" \
-                   -e "s/^\([-0-9]\{10,10\}\) \([:0-9]\{5,5\}\)/${yellow}\1 ${green}\2${reset}/" \
-                   -e "s/$NICK/\a${red}&${reset}/g" 
+while $#; do
+	case $1 in
+		-i) IN="$2"
+			;;
+		-o) OUT="$2"
+			;;
+		-m) MARGIN="$2"
+			;;
+		-n) NICK="$2"
+			;;
+		*)  echo "bad argument $1"
+			exit 2
+	esac
+	shift 2
+done
+
+cw "$IN" "$OUT" $MARGIN |
+	sed -e "s/^\([-0-9]\{10,10\}\) \([:0-9]\{5,5\}\) <\([^>]*\)>/${yellow}\1 ${green}\2${reset} <${cyan}\3${reset}>/" \
+		-e "s/^\([-0-9]\{10,10\}\) \([:0-9]\{5,5\}\) \(-!-\)/${yellow}\1 ${green}\2${reset} ${magenta}\3${reset}/" \
+		-e "s/^\([-0-9]\{10,10\}\) \([:0-9]\{5,5\}\)/${yellow}\1 ${green}\2${reset}/" \
+		-e "s/$NICK/\a${red}&${reset}/g" 
+
+# vim: set ts=4 sw=4 noexpandtab: