diff rlgterm.js @ 78:06375a159188

Try to guess a good text size. When starting, resize the fonts if there isn't room for the terminal, or if there is a lot of empty space.
author John "Elwin" Edwards <elwin@sdf.org>
date Sat, 23 Jun 2012 19:13:34 -0700
parents f8bb37f48d58
children e04c8bf6d4da
line wrap: on
line diff
--- a/rlgterm.js	Sat Jun 23 17:41:27 2012 -0700
+++ b/rlgterm.js	Sat Jun 23 19:13:34 2012 -0700
@@ -386,6 +386,24 @@
   termemu.init("termwrap", 24, 80);
   setTitle("Not connected.");
   setmode("login");
+  /* Set up the text size. */
+  var cssSize = termemu.view.style.fontSize;
+  var match = cssSize.match(/\d*/);
+  if (!match) {
+    return;
+  }
+  var csize = Number(match[0]);
+  var allscreen = document.getElementById("termwrap");
+  while (csize > 9 && csize < 48) {
+    if (allscreen.scrollWidth * 1.2 > window.innerWidth) {
+      csize = textsize(false);
+    }
+    else if (allscreen.scrollWidth * 2 < window.innerWidth) {
+      csize = textsize(true);
+    }
+    else
+      break;
+  }
   return;
 }
 
@@ -790,11 +808,11 @@
 function textsize(larger) {
   var cssSize = termemu.view.style.fontSize;
   if (!cssSize) {
-    return;
+    return null;
   }
   var match = cssSize.match(/\d*/);
   if (!match) {
-    return;
+    return null;
   }
   var csize = Number(match[0]);
   var nsize;
@@ -827,7 +845,7 @@
   document.getElementById("keys").style.fontSize = cssvalstr;
   termemu.fixsize();
   debug(1, "Changing font size to " + nsize.toString());
-  return;
+  return nsize;
 }
 
 function idlestr(ms) {