Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
60 lines (59 sloc) 2.73 KB
An.object().named('Page').plural('Pages').from(Widget).
has('width',128*10).has('height',32*16).has('font',A.font('16 Monaco')).has('cursor',0).has('inserting',true).has('size',128*32).has('columns',128).
does('init', function() { return this.clone().has('memory',new Uint8Array(this.size())).clear().instance().here() }).
does('draw', function() {
Screen.save().as(this).save().color(64,64,64,0.1).fill().restore()
this.font().use()
for (var J = 0; J < this.size(); ++J)
Screen.at(this.x() + (J%this.columns())*10,this.y() + Math.floor(J/this.columns())*16 + 16).print(String.fromCharCode(this.memory()[J]))
Screen.at(this.x() + (this.cursor()%this.columns())*10,this.y() + Math.floor(this.cursor()/this.columns())*16).by(10,16).color(64,64,64,0.5).fill().restore()
}).
does('clear', function() {
var I = this
this.has('cursor',0);
(0).to(this.size()-1, function(J) { I.memory()[J] = ' ' })
return this
}).
does('nextline', function() { return Math.floor((this.cursor() + this.columns())/this.columns())*this.columns() }).
does('eol', function() { return this.nextline() - 1 }).
does('enter', function() {this.has('cursor',Math.min(this.size()-1,this.nextline())) }).
does('tab', function() { this.has('cursor',Math.min(this.size()-1,this.cursor() + (8 - (this.cursor() % 8)))) }).
does('write', function(K) {
switch (K) {
case Keyboard.backspace():
for (var J = this.cursor()-1; J <= Math.min(this.size()-1, this.eol());++J)
this.memory()[J] = this.memory()[J+1]
this.memory()[Math.min(this.size()-1, this.eol())] = 32
this.has('cursor', Math.max(this.cursor()-1,0))
break
case '\n': case Keyboard.newline():
case '\r': case Keyboard.enter():
this.enter(); break;
case '\t': case Keyboard.tab(): this.tab(); break
case '':
if (Keyboard.left()) this.has('cursor', Math.max(0,this.cursor()-1))
if (Keyboard.right()) this.has('cursor', Math.min(this.size()-1,this.cursor()+1))
if (Keyboard.up()) this.has('cursor', Math.max(0,this.cursor()-this.columns()))
if (Keyboard.down()) this.has('cursor', Math.min(this.size()-1,this.cursor()+this.columns()))
break
default:
if (this.inserting())
for (var J = Math.min(this.size()-1, this.eol()); J > this.cursor(); --J)
this.memory()[J] = this.memory()[J-1]
this.memory()[this.cursor()] = K.charCodeAt(0)
this.has('cursor',Math.min(this.size()-1,this.cursor()+1))
}
return this
}).
does('print', function(T) {
for (var J = 0; J < T.length && J < this.size()-1; ++J) this.write(T[J])
return this
}).
does('load', function(U) {
var I = this
this.clear()
U.get(function(T) { I.print(T) })
return this
}).
does('source',function(O) { this.load(document.location.href.append('object/', O)) }).
does('press', function(E) { return !Mouse.on(this) ? this : this.write(E.key()) })
Something went wrong with that request. Please try again.