Set title bas on the output found on the screen.
authorRui Guo <firemeteor.guo@gmail.com>
Mon, 10 Aug 2009 16:37:52 +0000 (11 00:37 +0800)
committerRui Guo <firemeteor.guo@gmail.com>
Mon, 10 Aug 2009 16:37:52 +0000 (11 00:37 +0800)
src/scripts/autoaka.lua [new file with mode: 0644]

diff --git a/src/scripts/autoaka.lua b/src/scripts/autoaka.lua
new file mode 100644 (file)
index 0000000..5188754
--- /dev/null
@@ -0,0 +1,30 @@
+-- not a full implementation, but demonstrates the idea.
+-- A full implementation is not that easy...
+function winhook(win)
+  local buf = ""
+  local saw_anchor = 0
+
+function aka(win, out)
+  buf = buf .. out
+  title = string.match(buf, "\027k\027.$ (%w+).-\n")
+  if title ~= nil and title ~= win.title then
+    win.title = title
+    saw_anchor = 0
+    buf = ""
+    return 0
+  end
+
+  new = string.match(buf, ".*\n(.*)")
+  if (new ~= nil) then
+    buf = new
+  else
+    if string.len(buf) >= 20 then
+      buf = ""
+    end
+  end
+  return 0
+end
+  win:hook("onoutput", aka)
+end
+
+ticket1 = screen.hook("oncreatewindow", winhook)