_ _ _ | |_ _____ _| |_ _ __ ___ ___ __| | ___ | __/ _ \ \/ / __| '_ ` _ \ / _ \ / _` |/ _ \ | || __/> <| |_| | | | | | (_) | (_| | __/ \__\___/_/\_\\__|_| |_| |_|\___/ \__,_|\___|
| « v1.5 | v1.5.1 |
Textmode is a mini-library that emulates the classical console textmode.
This is how it works:
HTML<pre id="monitor"></pre>JAVASCRIPT
var m = make_screen(10, 30); m.monitor("monitor"); m.bgcolor("red").textcolor("white").clrscr().gotoxy(2, 1).write("Hello, world!");OUTPUT
While diving inside my old files I found a snake game I wrote in pascal when I was sixteen. Taken by a wave of nostalgia I decided to port it in javascript to make it work in a webpage.
Being it based exclusively on ASCII graphics, I thought to write a textmode compatibility layer.. textmode.
So here it is the snake game based on textmode.
Constructor
make_screen(height, width)
Where possible functions are chainable.
| function | description |
|---|---|
monitor(id) |
Binds this object to a PRE element whose id is id. |
clrscr() clear() cls() |
Clear the screen |
gotoxy(x, y) at(y, x) |
Moves the cursor at the given coordinates |
wherex() |
Returns the current x coordinate |
wherey() |
Returns the current y coordinate |
whereyx() |
Returns the current coordinates as [y, x] |
write(str) |
Prints str on the screen |
writeln(str) |
Prints str on the screen followed by a newline character |
colormode() colormode(true/false) |
If no argument is specified it returns true if the screen is in colormode, false otherwise. If the boolean argument is specified it enables/disables colormode. If colors and styles are not used it is better to disable colormode to improve efficiency. |
textcolor() textcolor(color) |
If color is not supplied it returns current foreground color. If color is supplied it is used as text foreground color. color is a string with a valid CSS color (e.g. "#ffffff", "navy") |
bgcolor() bgcolor(color) |
If color is not supplied it returns current background color. If color is supplied it is used as text background color. color is a string with a valid CSS color (e.g. "#ffffff", "navy") |
bold() bold(true/false) |
If no argument is specified it returns whether current text style is bold or not. If the boolean argument is supplied it sets current text style to bold or not bold. |
italic() italic(true/false) |
If no argument is specified it returns whether current text style is italic or not. If the boolean argument is supplied it sets current text style to italic or not italic. |
saving_style(fn) |
It executes the fn function, restoring previous text styles after the function returns. |
dump() |
Returns current content of the screen |
restore(d) |
Restores the d dump of the screen |
begin() |
Begins a series of operations |
end() |
Ends a series of operations (started by begin.) |
If the output exceeds the last row, the screen won't scroll down.
It doesn't support colors yet (and probably never will :). Colors support added in v1.5.
Very probably many others..
