Commits

Anonymous committed a1be3b4

fix margin handling and cw_color.sh arg handling

Comments (0)

Files changed (2)

 
 void print_line(char *line)
 {
-	int i, len, cols = ws.ws_col;
 	char *m;
+	int i, len, w, cols = ws.ws_col;
 
-	if (!margin) {
+	len = strlen(line);
+	m = strchr(line, margin);
+	w = m - line;
+
+	if (!margin || !m || w + 5 >= cols) { // 5, pretty random choice
 		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%c %.*s\n", (int)(m - line), "", margin, cols - (int)(m - line), line + i);
+	for (i = cols; i < len; i += cols - 2 - w)
+		printf("%*s%c %.*s\n", w, "", margin, cols - 2 - w, line + i);
 }
 
 void sigwinch(int unused)
 NICK="$USER"
 MARGIN=
 
-while $#; do
+while [ $# -gt 0 ]; do
 	case $1 in
 		-i) IN="$2"
 			;;