{"size": 2098, "ext": "js", "max_stars_repo_path": "src/revoker-cli.js", "max_stars_repo_name": "natsu-anon/STOWAWAY", "max_stars_repo_stars_event_min_datetime": "2021-08-22T08:57:38.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-15T18:38:44.000Z", "max_issues_repo_path": "src/revoker-cli.js", "max_issues_repo_name": "natsu-anon/STOWAWAY", "max_issues_repo_issues_event_min_datetime": "2021-08-22T08:32:31.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-10T06:11:22.000Z", "max_forks_repo_path": "src/revoker-cli.js", "max_forks_repo_name": "natsu-anon/STOWAWAY", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 3, "max_issues_count": 4, "max_forks_count": null, "avg_line_length": 17.0569105691, "max_line_length": 52, "alphanum_fraction": 0.59914204}
const blessed = require('blessed');

function setupEvents(elem, keyEvents) {
	for (const key in keyEvents) {
		elem.onceKey(key, keyEvents[key]);
	}
}

function revocationForm (screen, label, keyEvents) {
	const form = blessed.form({
		parent: screen,
		tags: true,
		keys: true,
		height: 40,
		width: 120,
		top: 'center',
		left: 'center',
		label: ` {red-fg}${label}{/red-fg} `,
		padding: 1,
		border: {
			type: 'line',
			fg: 'red'
		}
	});
	blessed.text({
		parent: form,
		top: 0,
		content: 'Enter new key nickname:',
		fg: 'red',
	});
	const nickname = blessed.textbox({
		parent: form,
		top: 1,
		height: 1,
		inputOnFocus: true,
		name: 'nickname',
		content: 'nickname...',
		style: {
			fg: 'red',
			focus: {
				inverse: true
			}
		}
	});
	blessed.text({
		parent: form,
		top: 2,
		content: 'Enter new key passphrase:',
		fg: 'red',
	});
	const passphrase0 = blessed.textbox({
		parent: form,
		censor: true,
		top: 3,
		height: 1,
		inputOnFocus: true,
		name: 'passphrase0',
		content: 'passphrase...',
		style: {
			fg: 'red',
			focus: {
				inverse: true
			}
		}
	});
	blessed.text({
		parent: form,
		top: 4,
		content: 'Re-enter new key passphrase:',
		fg: 'red',
	});
	const passphrase1 = blessed.textbox({
		parent: form,
		censor: true,
		top: 5,
		height: 1,
		inputOnFocus: true,
		name: 'passphrase1',
		content: 'passphrase...',
		style: {
			fg: 'red',
			focus: {
				inverse: true
			}
		}
	});
	const button = blessed.button({
		parent: form,
		name: 'submit',
		content: ' [ REVOKE ] ',
		top: 7,
		left: 'center',
		shrink: true,
		style: {
			fg: 'red',
			focus: {
				inverse: true
			}
		}
	});
	button.on('press', () => {
		form.submit();
		screen.render();
	});
	const output = blessed.text({
		parent: form,
		top: 8,
		tags: true,
		fg: 'red',
	});
	form.focusNext();
	screen.grabKeys = false;
	screen.render();
	setupEvents(form, keyEvents);
	setupEvents(nickname, keyEvents);
	setupEvents(passphrase0, keyEvents);
	setupEvents(passphrase1, keyEvents);
	setupEvents(button, keyEvents);
	return { form, output };
}

module.exports = revocationForm;
