Skip to content
Snippets Groups Projects
Select Git revision
  • main default protected
1 result

README.md

Blame
  • README.md 1.22 KiB

    swindows

    A window management library for Synchronet JS (and TypeScript) modules. In tests, it's up to 11 times faster than frame.js.

    Usage

    Fill the terminal with 20 pages of junk, scroll back up to the top line by line, then scroll back to the bottom line by line:

    import type { ICgaDefs } from '@swag/ts4s';
    import type { uint8 } from './types';
    
    import { load } from '@swag/ts4s';
    import WindowManager from './WindowManager';
    import Window from './Window';
    import { WRAP } from './defs';
    
    const cgadefs: ICgaDefs = load('cga_defs.js');
    const { console, mswait } = js.global;
    
    console.clear(cgadefs.BG_BLACK|cgadefs.LIGHTGRAY);
    
    const wm = new WindowManager();
    wm.hideCursor();
    
    const window = new Window({ x : 0, y: 0 }, { width: wm.size.width, height: wm.size.height }, wm);
    window.wrap = WRAP.HARD;
    const len = window.size.width * window.size.height * 20;
    for (let n = 0; n < len; n++) {
    	window.write(`${n % 10}`, ((Math.floor(Math.random() * 16))|((Math.floor(Math.random() * 8))<<4)) as uint8);
    }
    
    wm.refresh();
    
    while (window.offset.y > 0) {
    	window.scroll(0, -1);
    	wm.refresh();
    }
    
    mswait(1000);
    
    while (window.offset.y < window.dataHeight - window.size.height) {
    	window.scroll(0, 1);
    	wm.refresh();
    }
    
    mswait(1000);