comparison 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
comparison
equal deleted inserted replaced
77:f8bb37f48d58 78:06375a159188
384 function setup() { 384 function setup() {
385 keyHexCodes.init(); 385 keyHexCodes.init();
386 termemu.init("termwrap", 24, 80); 386 termemu.init("termwrap", 24, 80);
387 setTitle("Not connected."); 387 setTitle("Not connected.");
388 setmode("login"); 388 setmode("login");
389 /* Set up the text size. */
390 var cssSize = termemu.view.style.fontSize;
391 var match = cssSize.match(/\d*/);
392 if (!match) {
393 return;
394 }
395 var csize = Number(match[0]);
396 var allscreen = document.getElementById("termwrap");
397 while (csize > 9 && csize < 48) {
398 if (allscreen.scrollWidth * 1.2 > window.innerWidth) {
399 csize = textsize(false);
400 }
401 else if (allscreen.scrollWidth * 2 < window.innerWidth) {
402 csize = textsize(true);
403 }
404 else
405 break;
406 }
389 return; 407 return;
390 } 408 }
391 409
392 function toggleshift() { 410 function toggleshift() {
393 termemu.toggleshift(); 411 termemu.toggleshift();
788 } 806 }
789 807
790 function textsize(larger) { 808 function textsize(larger) {
791 var cssSize = termemu.view.style.fontSize; 809 var cssSize = termemu.view.style.fontSize;
792 if (!cssSize) { 810 if (!cssSize) {
793 return; 811 return null;
794 } 812 }
795 var match = cssSize.match(/\d*/); 813 var match = cssSize.match(/\d*/);
796 if (!match) { 814 if (!match) {
797 return; 815 return null;
798 } 816 }
799 var csize = Number(match[0]); 817 var csize = Number(match[0]);
800 var nsize; 818 var nsize;
801 if (larger) { 819 if (larger) {
802 if (csize >= 48) 820 if (csize >= 48)
825 var cssvalstr = nsize.toString() + "px"; 843 var cssvalstr = nsize.toString() + "px";
826 document.getElementById("term").style.fontSize = cssvalstr; 844 document.getElementById("term").style.fontSize = cssvalstr;
827 document.getElementById("keys").style.fontSize = cssvalstr; 845 document.getElementById("keys").style.fontSize = cssvalstr;
828 termemu.fixsize(); 846 termemu.fixsize();
829 debug(1, "Changing font size to " + nsize.toString()); 847 debug(1, "Changing font size to " + nsize.toString());
830 return; 848 return nsize;
831 } 849 }
832 850
833 function idlestr(ms) { 851 function idlestr(ms) {
834 if (typeof(ms) != "number") 852 if (typeof(ms) != "number")
835 return "?"; 853 return "?";