shithub: irc.myr

Download patch

ref: 3c12de48c887a96f448830c9ac32af729caf5abc
parent: adb285ccf935148ce2e936b870d55c2159ed563e
author: Ori Bernstein <ori@eigenstate.org>
date: Sun Nov 26 16:44:42 EST 2017

Update to latest termdraw apis.

--- a/main.myr
+++ b/main.myr
@@ -805,7 +805,7 @@
 		match termdraw.poll(irc.term)
 		| `std.None:
 			break
-		| `std.Some `termdraw.Winsz _:
+		| `std.Some `termdraw.Winsz:
 			irc.chandirty = true
 			irc.cmddirty = true
 		| `std.Some `termdraw.Kc '\t':
@@ -990,17 +990,17 @@
 		margin = 0
 		match ent
 		| `Msg (m, ln):
-			margin = c.gutter + termdraw.strwidth(t, " | ")
-			width = termdraw.strwidth(t, ln)
+			margin = strwidth(x0, c.gutter, " | ")
+			width = strwidth(x0, margin, ln)
 		| `Join user:
-			margin = termdraw.strwidth(t, "#joined: ")
-			width = termdraw.strwidth(t, user)
+			margin = strwidth(x0, 0, "#joined: ")
+			width = strwidth(x0, margin, user)
 		| `Part user:
-			margin = termdraw.strwidth(t, "#parted: ")
-			width = termdraw.strwidth(t, user)
+			margin = strwidth(x0, 0, "#parted: ")
+			width = strwidth(x0, margin, user)
 		| `Status msg:
-			margin = termdraw.strwidth(t, "! ")
-			width = termdraw.strwidth(t, msg)
+			margin = strwidth(x0, 0, "! ")
+			width = strwidth(x0, margin, msg)
 		;;
 		/* no point in drawing if all we draw is gutter */
 		if dx - margin <=  0
@@ -1026,7 +1026,7 @@
 		| `Msg (m, ln):
 			termdraw.setattr(t, termdraw.Bold)
 
-			x = std.clamp(x0 + c.gutter - termdraw.strwidth(t, m), 0, dx)
+			x = std.clamp(x0 + c.gutter - strwidth(x0, 0, m), 0, dx)
 			(x, y) = draw(t, m, x, y, x1, y1)
 			(x, y) = draw(t, " | ", x, y, x1, y1)
 			termdraw.setattr(t, lineattr(irc, ln[off:]))
@@ -1050,6 +1050,19 @@
 	;;
 }
 
+const strwidth = {x0, margin, str
+	var x
+
+	x = x0 + margin
+	for c : std.bychar(str)
+		match c
+		| '\t':	x = (x / 8 + 1) * 8
+		| _:	x += (std.cellwidth(c) : int)
+		;;
+	;;
+	-> x - (x0 + margin)
+}
+
 const draw = {t, msg, x0, y0, x1, y1
 	var x, y
 
@@ -1140,7 +1153,7 @@
 
 	s = irc.cmd
 	o = (irc.off : int)
-	dx -= termdraw.strwidth(irc.term, chan)
+	dx -= strwidth(0, 0, chan)
 	w = 0
 	start = 0
 	end = 0
--