shithub: irc.myr

Download patch

ref: ef08aacd4da78b5e0e5bdf1963f23f15dc7d109b
parent: c62a976e77e3fa7f12a2f105c4fc1adcf40fb194
author: Ori Bernstein <ori@eigenstate.org>
date: Fri Jan 5 18:14:20 EST 2018

Wrap channel list.

--- a/draw.myr
+++ b/draw.myr
@@ -11,7 +11,7 @@
 ;;
 
 const redraw = {irc
-	var c, x, y, w, h
+	var c, x, y, w, h, lh
 
 	if irc.term.width < 10 || irc.term.height < 5
 		-> void
@@ -23,9 +23,10 @@
 	h = irc.term.height
 	c = curchan(irc)
 	if irc.chandirty
+		lh = listheight(irc, 0, 1, w, h - 1)
 		drawbanner(irc, 0, 0, w, 1, c)
-		drawtext(irc, 0, 1, w, h - 2, c)
-		drawlist(irc, 0, h - 2, w, h - 1, c)
+		drawtext(irc, 0, 1, w, h - lh - 1, c)
+		drawlist(irc, 0, h - lh - 1, w, h - 1, c)
 		irc.chandirty = false
 	;;
 	if irc.cmddirty
@@ -184,8 +185,10 @@
 }
 
 const drawlist = {irc, x0, y0, x1, y1, c
-	var t
+	var t, h
 
+
+	h = 1
 	t = irc.term
 	termdraw.setbg(t, termdraw.Blue)
 	termdraw.clear(t, x0, y0, x1, y1)
@@ -194,6 +197,10 @@
 	termdraw.put(t, "[{}]", irc.self.name)
 	for s : irc.srv
 		for ch : s.chan
+			if t.x + strwidth(t.x, 0, ch.name) + 4 >= x1
+				h++
+				termdraw.move(t, x0, y0 + h - 1)
+			;;
 			if ch.flagged
 				termdraw.setattr(t, termdraw.Bold)
 				termdraw.put(t, "[@{}]", ch.name)
@@ -201,12 +208,13 @@
 			elif ch.stale
 				termdraw.put(t, "[*{}]", ch.name)
 			else
-				termdraw.put(t, "[{}]", ch.name)
+				termdraw.put(t, "[ {}]", ch.name)
 			;;
 		;;
 		termdraw.setattr(t, termdraw.Normal)
 		termdraw.putc(t, '|')
 	;;
+	-> h
 }
 
 const drawinput = {irc, x0, y0, x1, y1, c
@@ -227,6 +235,28 @@
 	termdraw.cursorpos(t, cx, y0)
 	std.slfree(chan)
 	std.slfree(ln)
+}
+
+const listheight = {irc, x0, y0, x1, y1
+	var w, h
+	w = 0
+
+	h = 1
+	w += strwidth(x0, 0, "|")
+	w += strwidth(x0 + w, 0, "[ ]")
+	w += strwidth(x0 + w, 0, irc.self.name)
+	for s : irc.srv
+		for ch : s.chan
+			if x0 + w + strwidth(w, 0, ch.name) + 4 >= x1
+				h++
+				w = 0
+			;;
+			w += strwidth(x0 + w, 0, "[ ]")
+			w += strwidth(x0 + w, 0, ch.name)
+		;;
+		w += strwidth(x0 + w, 0, "|")
+	;;
+	-> h
 }
 
 const lineattr = {irc, ln
--