Firefox 3.5.5 crapping itself (redux)

N

Nik Coughlin

Not all terminals are line-oriented. The IBM 3270 and the Tandem 65xx series
support both line- and block-mode communication. (In block mode, an entire
screen is transmitted or received at once.) Before commenting on the method
the OP has chosen to implement a terminal emulator, it's important to know
*which* terminal he's trying to emulate.

Of course, I wouldn't choose a cell-by-cell method for emulating a block-mode
terminal either.

Most terminals support a cursor paradigm where you can set the current
position of the cursor to any point on the screen and then proceed to
write from that point.

http://en.wikipedia.org/wiki/Curses_(programming_library)

Additionally most terminals also have the ability to set the current
foreground/background color, with any subsequent writes displayed with
that combination.

This means you can do things like:

Set foreground color to red
Set background color to yellow
Move cursor to column 5, row 12
Write the string "hello"
Set foreground color to silver
Set background color to black
Move cursor to column 3, row 1
Write the string "world"

I have something fairly much equivalent to curses working, but at the
moment it relies on the cell-based approach that I have been talking
about it.

I am *very* open to alternatives at this point!
 
T

The Natural Philosopher

Nik said:
Most terminals support a cursor paradigm where you can set the current
position of the cursor to any point on the screen and then proceed to
write from that point.

http://en.wikipedia.org/wiki/Curses_(programming_library)

Additionally most terminals also have the ability to set the current
foreground/background color, with any subsequent writes displayed with
that combination.

This means you can do things like:

Set foreground color to red
Set background color to yellow
Move cursor to column 5, row 12
Write the string "hello"
Set foreground color to silver
Set background color to black
Move cursor to column 3, row 1
Write the string "world"

I have something fairly much equivalent to curses working, but at the
moment it relies on the cell-based approach that I have been talking
about it.

I am *very* open to alternatives at this point!
Haven't really been following this, but why not set up an 80x25 table,
and grab some terminal code and port it to javascript.

At the base level there should be som eputchar_screen(x,y) type function
that you can just replicate.
 
N

Nik Coughlin

Haven't really been following this, but why not set up an 80x25 table,
and grab some terminal code and port it to javascript.

At the base level there should be som eputchar_screen(x,y) type function
that you can just replicate.

I've already done this, except I'm not using a table (presuming you mean
an HTML table).

Most of the discussion is currently about not using a cell-based
approach, that is, one where you use one HTML element for each character.
 
T

Thomas 'PointedEars' Lahn

Nik said:
Please tell me what you had in mind. The reason I was trying to use
addressable cells is that any or all of the cells may change at any
time, and the terminal also supports color, so I need the ability to
style the background-color and color of the cells individually as well.

In that case, consider an 80 by 25 cells table instead. After all, it has
cells built-in and the only basic DOM operations you would need is to change
the cell's colors and their text nodes' values. It would scale well with
font size, and if you needed it to change shape or size you could easily
appendChild() the needed cells (like

var rs = table.rows;
rs[0].appendChild(rs[1].cells[0]);

aso. for making it one column wider.)

However, I agree that you should probably use the DOM for presentation only;
a 80 by 25 cells terminal screen can easily be stored in an array of object
references. Modifying the array and then running an update() method that
updates all changed cells would probably be best.
I've been using Windows Mail (replaces OE) because it's what I'm used to
and because the last time I used Thunderbird (a long time ago) it had
some peculiarities about its interface that I didn't like. I just
downloaded it again and am pleasantly surprised at how much better it's
become, so won't be using WM again. Thanks.

You are welcome.

I have since noticed that insideoe.com does not feature as much about
Windows Mail as I expected it to (although the FAQ might still provide
useful, and Tom Koch's insidewinmail.com as referred to at tomsterdam.com is
404-compliant af of now. Thanks in advance to anyone pointing me to an
English-speaking Web site about OE bugs that were fixed or not fixed in
Windows Mail, or new bugs.


PointedEars
 
N

Nik Coughlin

In that case, consider an 80 by 25 cells table instead. After all, it has
cells built-in and the only basic DOM operations you would need is to change
the cell's colors and their text nodes' values.

Makes sense. It's also a trivial change from the code I already have,
which is using an outer div (so, -> table), a div for each row (->tr)
and a span for each cell (->td).

For the color changing I'm leaning towards generating a stylesheet,
adding rules to it for each foreground/background combination as
required (if not css rule exists create css rule), then switching the
cell's class to match the rule, rather than setting the style directly
on the cells. I understand that this is faster[1] and it also seems more
elegant to me.

It would scale well with
font size, and if you needed it to change shape or size you could easily
appendChild() the needed cells (like

var rs = table.rows;
rs[0].appendChild(rs[1].cells[0]);

aso. for making it one column wider.)

While the interface that I'm emulating does allow for changing the
window size while running, in practise I've *never* seen it done.
However, as you point out, it's easy to do so I should implement it just
in case.
However, I agree that you should probably use the DOM for presentation only;
a 80 by 25 cells terminal screen can easily be stored in an array of object
references. Modifying the array and then running an update() method that
updates all changed cells would probably be best.

This is not too far off what I'm already doing. One thing that I'm not
doing at present is checking the existing text and color values to see
if the cell actually needs to be changed or not.
I have since noticed that insideoe.com does not feature as much about
Windows Mail as I expected it to (although the FAQ might still provide
useful, and Tom Koch's insidewinmail.com as referred to at tomsterdam.com is
404-compliant af of now. Thanks in advance to anyone pointing me to an
English-speaking Web site about OE bugs that were fixed or not fixed in
Windows Mail, or new bugs.

I had a quick look around but either there isn't really anything, or the
signal to noise ratio on Google is too high for it to show up with a
casual search.
 
R

rf

For the color changing I'm leaning towards generating a stylesheet, adding
rules to it for each foreground/background combination as required (if not
css rule exists create css rule), then switching the cell's class to match
the rule, rather than setting the style directly on the cells. I
understand that this is faster[1] and it also seems more elegant to me.

Er, have a set of foreground colour rules and a set of background colour
rules and combine them, as in

whatever.className = 'forerule backrule';
This is not too far off what I'm already doing. One thing that I'm not
doing at present is checking the existing text and color values to see if
the cell actually needs to be changed or not.

Don't check it "in the DOM". Check it in the array of colour values you have
squirreled away. Only *set* it in the DOM;
 
N

Nik Coughlin

For the color changing I'm leaning towards generating a stylesheet, adding
rules to it for each foreground/background combination as required (if not
css rule exists create css rule), then switching the cell's class to match
the rule, rather than setting the style directly on the cells. I
understand that this is faster[1] and it also seems more elegant to me.

Er, have a set of foreground colour rules and a set of background colour
rules and combine them, as in

whatever.className = 'forerule backrule';

Good thinking. I'm now doing this instead.
Don't check it "in the DOM". Check it in the array of colour values you have
squirreled away. Only *set* it in the DOM;

Right you are. Done.

The terminal emulation seems to be working very well indeed. As a test
I 'ported'[1] a C# console application to it and it seems to be working
nicely, aside from I haven't even thought about key handling yet, which
is going to be a nightmare by the look of things:

http://unixpapa.com/js/key.html
http://www.quirksmode.org/js/keys.html

[1] When I say ported, I copied and pasted the C# code, changed some
List methods to their equivalent JS array methods, changed all the
Console.* calls to call my terminal emulator instead, changed all the
int x = 0; etc. to be var x = 0; etc. and got rid of the keyboard stuff
entirely... for now. Nice that C syntax based languages are close enough
together that I could even get away with this.
 
T

Thomas 'PointedEars' Lahn

Nik said:
Thomas said:
In that case, consider an 80 by 25 cells table instead. After all, it
has cells built-in and the only basic DOM operations you would need is to
change the cell's colors and their text nodes' values.

Makes sense. It's also a trivial change from the code I already have,
which is using an outer div (so, -> table), a div for each row (->tr)
and a span for each cell (->td).
ACK

For the color changing I'm leaning towards generating a stylesheet,
adding rules to it for each foreground/background combination as
required (if not css rule exists create css rule), then switching the
cell's class to match the rule, rather than setting the style directly
on the cells. I understand that this is faster[1] and it also seems more
elegant to me.

[1] <http://www.quirksmode.org/dom/classchange.html>

It is certainly more elegant in general. That is, if you want only certain
foreground colors and certain background colors like in a terminal, it does
make a certain sense to define classes for those colors. However, note that
most if not all colors commonly used in terminals can also be selected by
name in CSS. So this only appears to make sense if you want to have
specific combinations of foreground and background colors, and ISTM that
would somewhat contradict your specifications of being as flexible as
possible.

I doubt the `className' property it is generally faster, though, as the
`style' property allows setting the style property as if the `style'
attribute was used (to take precedence over all but !important rules, but
the latter is not formally specified [yet?]) instead of deriving its
computed value from the cascade for *all* the class names in the whitespace-
separated list plus considering possible inline `style' properties. Also
note that speed difference, except for that Opera version, is negligibly
small, could be attributed to a measurement error, and the tested browsers
are not the newest versions anymore, some have even met their end-of-life by
now, as the "Page last changed 22 months ago". It stands to reason that
layout engines and DOM implementations become more efficient in new browser
versions, not less. As a rule of thumb, take everything said about client-
side scripting at the Web with a grain, if not a handful, of salt.
This is not too far off what I'm already doing. One thing that I'm not
doing at present is checking the existing text and color values to see
if the cell actually needs to be changed or not.

You should set up a stack (or similar) with references to changed cells
instead. It would probably be much faster than your approach (which
compares string values), even faster than setting a flag on the cell object
in the array (because you only need L iterations for L changed cells as
compared to M×N iterations every time).

Say, if the array looked so:

var cells = [
[{fg: "#abc", bg: "#def", content: "X"}]
];

(i.e, the first cell of the first row contained an "X") you could have

var changeList = [];

If the background color of the cell were to change, like

cells[0][0].bg = "#012";

you could note that in the change list:

changeList.push(cells[0][0]);

Then the update() method would only need to iterate over `changeList'.
(This is obviously slower for single cells than direct DOM access but
probably a lot faster than it for accessing blocks of cells like ncurses
does.)

I would put all of this in one object, though:

var screenData = {
cells: [...],
changes: []
};


HTH

PointedEars
 
T

Thomas 'PointedEars' Lahn

Thomas said:
I would put all of this in one object, though:

var screenData = {
cells: [...],
changes: []
};

And don't forget update() and all the other properties :)

var terminal = {
table: null,
cells: [],
changes: [],

/* or use a constructor if you need several terminals */
init: function() {
// ...
},

setCell: function(fg, bg, c) {
// ...
},

update: function() {
// ...
},

// ...
};


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top