How to use the printj.sprintf function in printj

To help you get started, we’ve selected a few printj examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github SheetJS / wk / view.ts View on Github external
ncol = ((screen.cols - colhdr)/colwidth)|0, nrow = screen.rows - 4;

	/* row labels */
	for(let i = 0; i < nrow; ++i) O += sprintf("%*s\n", colhdr, XLSX.utils.encode_row(base_cell.r + i));
	H5.setContent(O);

	/* column labels */
	H4l.width = (ncol * colwidth + colhdr);
	O = center_str("", colhdr);
	for(let i = 0; i < ncol; ++i) O += center_str(XLSX.utils.encode_col(base_cell.c + i), colwidth);
	H4l.setContent(O);

	for(let i = D.length; i < nrow; ++i) {
		D[i] = blessed.box({ top:4+i, left:colhdr, height:1, width:DW, bg:BG, fg:FG });
		body.append(D[i]);
		D[i].setContent(sprintf("haha %d", i));
	}

	const fmt = "%2$ *1$.*1$s ";
	for(let i = 0; i < nrow; ++i) {
		O = "";
		for(let j = 0; j < ncol; ++j) {
			const cell: XLSX.CellObject = ws[XLSX.utils.encode_cell({r:base_cell.r+i, c:base_cell.c+j})];
			let o = "";
			if(cell) {
				/* TODO: cell alignment */
				o = cell.w ? cell.w : String(cell.v);
				switch(cell.t) {
					case 'n':
						if(!cell.w) o = sprintf("%2$*1$g", colwidth-1, cell.v);
						/* falls through */
					case 'd':
github SheetJS / wk / view.js View on Github external
var O = "";
        ncol = ((screen.cols - colhdr) / colwidth) | 0, nrow = screen.rows - 4;
        /* row labels */
        for (var i = 0; i < nrow; ++i)
            O += printj_1.sprintf("%*s\n", colhdr, XLSX.utils.encode_row(base_cell.r + i));
        H5.setContent(O);
        /* column labels */
        H4l.width = (ncol * colwidth + colhdr);
        O = center_str("", colhdr);
        for (var i = 0; i < ncol; ++i)
            O += center_str(XLSX.utils.encode_col(base_cell.c + i), colwidth);
        H4l.setContent(O);
        for (var i = D.length; i < nrow; ++i) {
            D[i] = blessed.box({ top: 4 + i, left: colhdr, height: 1, width: DW, bg: BG, fg: FG });
            body.append(D[i]);
            D[i].setContent(printj_1.sprintf("haha %d", i));
        }
        var fmt = "%2$ *1$.*1$s ";
        for (var i = 0; i < nrow; ++i) {
            O = "";
            for (var j = 0; j < ncol; ++j) {
                var cell = ws[XLSX.utils.encode_cell({ r: base_cell.r + i, c: base_cell.c + j })];
                var o = "";
                if (cell) {
                    /* TODO: cell alignment */
                    o = cell.w ? cell.w : String(cell.v);
                    switch (cell.t) {
                        case 'n':
                            if (!cell.w)
                                o = printj_1.sprintf("%2$*1$g", colwidth - 1, cell.v);
                        /* falls through */
                        case 'd':
github SheetJS / wk / view.ts View on Github external
body.append(D[i]);
		D[i].setContent(sprintf("haha %d", i));
	}

	const fmt = "%2$ *1$.*1$s ";
	for(let i = 0; i < nrow; ++i) {
		O = "";
		for(let j = 0; j < ncol; ++j) {
			const cell: XLSX.CellObject = ws[XLSX.utils.encode_cell({r:base_cell.r+i, c:base_cell.c+j})];
			let o = "";
			if(cell) {
				/* TODO: cell alignment */
				o = cell.w ? cell.w : String(cell.v);
				switch(cell.t) {
					case 'n':
						if(!cell.w) o = sprintf("%2$*1$g", colwidth-1, cell.v);
						/* falls through */
					case 'd':
						o = right_str(o, colwidth - 1); break;
					case 's': o = left_str(o, colwidth + 1); break;
					case 'b': case 'e': o = center_str(o, colwidth - 1); break;
					case 'z': o = ""; break;
				}
			}
			O += sprintf(fmt,colwidth-1,o);
		}
		D[i].setContent(O);
	}
}
github SheetJS / wk / view.js View on Github external
function rebuild_screen() {
        var O = "";
        ncol = ((screen.cols - colhdr) / colwidth) | 0, nrow = screen.rows - 4;
        /* row labels */
        for (var i = 0; i < nrow; ++i)
            O += printj_1.sprintf("%*s\n", colhdr, XLSX.utils.encode_row(base_cell.r + i));
        H5.setContent(O);
        /* column labels */
        H4l.width = (ncol * colwidth + colhdr);
        O = center_str("", colhdr);
        for (var i = 0; i < ncol; ++i)
            O += center_str(XLSX.utils.encode_col(base_cell.c + i), colwidth);
        H4l.setContent(O);
        for (var i = D.length; i < nrow; ++i) {
            D[i] = blessed.box({ top: 4 + i, left: colhdr, height: 1, width: DW, bg: BG, fg: FG });
            body.append(D[i]);
            D[i].setContent(printj_1.sprintf("haha %d", i));
        }
        var fmt = "%2$ *1$.*1$s ";
        for (var i = 0; i < nrow; ++i) {
            O = "";
            for (var j = 0; j < ncol; ++j) {
github SheetJS / wk / view.ts View on Github external
function rebuild_screen(): void {
	let O = "";
	ncol = ((screen.cols - colhdr)/colwidth)|0, nrow = screen.rows - 4;

	/* row labels */
	for(let i = 0; i < nrow; ++i) O += sprintf("%*s\n", colhdr, XLSX.utils.encode_row(base_cell.r + i));
	H5.setContent(O);

	/* column labels */
	H4l.width = (ncol * colwidth + colhdr);
	O = center_str("", colhdr);
	for(let i = 0; i < ncol; ++i) O += center_str(XLSX.utils.encode_col(base_cell.c + i), colwidth);
	H4l.setContent(O);

	for(let i = D.length; i < nrow; ++i) {
		D[i] = blessed.box({ top:4+i, left:colhdr, height:1, width:DW, bg:BG, fg:FG });
		body.append(D[i]);
		D[i].setContent(sprintf("haha %d", i));
	}

	const fmt = "%2$ *1$.*1$s ";
	for(let i = 0; i < nrow; ++i) {
github SheetJS / js-cfb / types / roundtrip.ts View on Github external
].forEach(path => {
	if(!CFB.find(cfb1, path)) return;
	const d1 = CFB.find(cfb1, path).content, c1 = buf(d1);
	const d2 = CFB.find(cfb2, path).content, c2 = buf(d2);
	if(c1 === c2) return;
	console.log(path); console.log(d1); console.log(d2);
	throw sprintf("%s mismatch: %08X != %08X", path, c1, c2);
});
github SheetJS / wk / view.ts View on Github external
const H1l = blessed.text({ top:0, left:0, width:'100%-2', bg:FG, fg:BG, parent: H1 });

const H2 = blessed.box({ top:1, height:1, width:'100%', bg:FG, fg:BG, parent:body });
const H2r = blessed.text({ top:0, right:0, width:2, bg:BG, fg:FG, parent:H2 });
H2r.setContent('JS');
const H2l = blessed.text({ top:0, left:0, width:'100%-2', bg:FG, fg:BG, parent:H2 });

const H3 = blessed.box({ top:2, height:1, width:'100%', bg:BG, fg:FG, tags:true, parent:body });

const H4 = blessed.box({ top:3, height:1, width:'100%', bg:BG, fg:FG, parent:body });
const H4l = blessed.box({ top:0, height:1, width:'50%', bg:FG, fg:BG, parent:H4 });

const H5 = blessed.box({ top:4, height:'100%-4', width:colhdr, bg:FG, fg:BG, parent:body });

const D: blessed.box[] = [];
let DW = sprintf('100%%-%d', colhdr);


function center_str(s: string, w: number): string {
	if(s.length >= w) return s.substr(0,w);
	const pl = (w - s.length) >> 1;
	return new Array(pl+1).join(" ") + s + new Array(w - s.length - pl + 1).join(" ");
}

function right_str(s: string, w: number): string {
	if(s.length >= w) return s.substr(0, w);
	const l = (w - s.length);
	return new Array(l+1).join(" ") + s;
}

function left_str(s: string, w: number): string {
	if(s.length >= w) return s.substr(0, w);
github SheetJS / wk / view.js View on Github external
case 'd':
                            o = right_str(o, colwidth - 1);
                            break;
                        case 's':
                            o = left_str(o, colwidth + 1);
                            break;
                        case 'b':
                        case 'e':
                            o = center_str(o, colwidth - 1);
                            break;
                        case 'z':
                            o = "";
                            break;
                    }
                }
                O += printj_1.sprintf(fmt, colwidth - 1, o);
            }
            D[i].setContent(O);
        }
    }
    rebuild_screen();
github SheetJS / wk / view.ts View on Github external
function move_sel_to_cell(cell: XLSX.CellAddress): void {
	recenter_screen(cell);
	selcell.c = cell.c; selcell.r = cell.r;
	sel.top = 4 + cell.r - base_cell.r; if(sel.top < 4) sel.top = -1;
	sel.left = colhdr + (cell.c - base_cell.c) * colwidth; if(sel.left < colhdr) sel.left = -colwidth;
	const addr = XLSX.utils.encode_cell(cell);
	let text = addr;
	if(ws[addr]) {
		text += sprintf(" (%c) |%s|", ws[addr].t, ws[addr].w||ws[addr].v);
		if(ws[addr].t === 'n' || ws[addr].t === 'd') text += sprintf(" raw %s", ws[addr].v);
		if(ws[addr].f) {
			show_version([(ws[addr].F || addr) + "=" + ws[addr].f ]);
		} else if(ws[addr].F) {
			const base_c = XLSX.utils.encode_cell(XLSX.utils.decode_range(ws[addr].F).s);
			show_version([ws[addr].F + "=" + ws[base_c].f ]);
		} else show_version();
	} else { text += sprintf(" EMPTY"); show_version(); }
	H1l.setText(text);
}

printj

Pure-JS printf

Apache-2.0
Latest version published 3 years ago

Package Health Score

67 / 100
Full package analysis

Popular printj functions