11cb0ef41Sopenharmony_ci'use strict'
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ci// These tables borrowed from `ansi`
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_civar prefix = '\x1b['
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ciexports.up = function up (num) {
81cb0ef41Sopenharmony_ci  return prefix + (num || '') + 'A'
91cb0ef41Sopenharmony_ci}
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ciexports.down = function down (num) {
121cb0ef41Sopenharmony_ci  return prefix + (num || '') + 'B'
131cb0ef41Sopenharmony_ci}
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ciexports.forward = function forward (num) {
161cb0ef41Sopenharmony_ci  return prefix + (num || '') + 'C'
171cb0ef41Sopenharmony_ci}
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_ciexports.back = function back (num) {
201cb0ef41Sopenharmony_ci  return prefix + (num || '') + 'D'
211cb0ef41Sopenharmony_ci}
221cb0ef41Sopenharmony_ci
231cb0ef41Sopenharmony_ciexports.nextLine = function nextLine (num) {
241cb0ef41Sopenharmony_ci  return prefix + (num || '') + 'E'
251cb0ef41Sopenharmony_ci}
261cb0ef41Sopenharmony_ci
271cb0ef41Sopenharmony_ciexports.previousLine = function previousLine (num) {
281cb0ef41Sopenharmony_ci  return prefix + (num || '') + 'F'
291cb0ef41Sopenharmony_ci}
301cb0ef41Sopenharmony_ci
311cb0ef41Sopenharmony_ciexports.horizontalAbsolute = function horizontalAbsolute (num) {
321cb0ef41Sopenharmony_ci  if (num == null) throw new Error('horizontalAboslute requires a column to position to')
331cb0ef41Sopenharmony_ci  return prefix + num + 'G'
341cb0ef41Sopenharmony_ci}
351cb0ef41Sopenharmony_ci
361cb0ef41Sopenharmony_ciexports.eraseData = function eraseData () {
371cb0ef41Sopenharmony_ci  return prefix + 'J'
381cb0ef41Sopenharmony_ci}
391cb0ef41Sopenharmony_ci
401cb0ef41Sopenharmony_ciexports.eraseLine = function eraseLine () {
411cb0ef41Sopenharmony_ci  return prefix + 'K'
421cb0ef41Sopenharmony_ci}
431cb0ef41Sopenharmony_ci
441cb0ef41Sopenharmony_ciexports.goto = function (x, y) {
451cb0ef41Sopenharmony_ci  return prefix + y + ';' + x + 'H'
461cb0ef41Sopenharmony_ci}
471cb0ef41Sopenharmony_ci
481cb0ef41Sopenharmony_ciexports.gotoSOL = function () {
491cb0ef41Sopenharmony_ci  return '\r'
501cb0ef41Sopenharmony_ci}
511cb0ef41Sopenharmony_ci
521cb0ef41Sopenharmony_ciexports.beep = function () {
531cb0ef41Sopenharmony_ci  return '\x07'
541cb0ef41Sopenharmony_ci}
551cb0ef41Sopenharmony_ci
561cb0ef41Sopenharmony_ciexports.hideCursor = function hideCursor () {
571cb0ef41Sopenharmony_ci  return prefix + '?25l'
581cb0ef41Sopenharmony_ci}
591cb0ef41Sopenharmony_ci
601cb0ef41Sopenharmony_ciexports.showCursor = function showCursor () {
611cb0ef41Sopenharmony_ci  return prefix + '?25h'
621cb0ef41Sopenharmony_ci}
631cb0ef41Sopenharmony_ci
641cb0ef41Sopenharmony_civar colors = {
651cb0ef41Sopenharmony_ci  reset: 0,
661cb0ef41Sopenharmony_ci// styles
671cb0ef41Sopenharmony_ci  bold: 1,
681cb0ef41Sopenharmony_ci  italic: 3,
691cb0ef41Sopenharmony_ci  underline: 4,
701cb0ef41Sopenharmony_ci  inverse: 7,
711cb0ef41Sopenharmony_ci// resets
721cb0ef41Sopenharmony_ci  stopBold: 22,
731cb0ef41Sopenharmony_ci  stopItalic: 23,
741cb0ef41Sopenharmony_ci  stopUnderline: 24,
751cb0ef41Sopenharmony_ci  stopInverse: 27,
761cb0ef41Sopenharmony_ci// colors
771cb0ef41Sopenharmony_ci  white: 37,
781cb0ef41Sopenharmony_ci  black: 30,
791cb0ef41Sopenharmony_ci  blue: 34,
801cb0ef41Sopenharmony_ci  cyan: 36,
811cb0ef41Sopenharmony_ci  green: 32,
821cb0ef41Sopenharmony_ci  magenta: 35,
831cb0ef41Sopenharmony_ci  red: 31,
841cb0ef41Sopenharmony_ci  yellow: 33,
851cb0ef41Sopenharmony_ci  bgWhite: 47,
861cb0ef41Sopenharmony_ci  bgBlack: 40,
871cb0ef41Sopenharmony_ci  bgBlue: 44,
881cb0ef41Sopenharmony_ci  bgCyan: 46,
891cb0ef41Sopenharmony_ci  bgGreen: 42,
901cb0ef41Sopenharmony_ci  bgMagenta: 45,
911cb0ef41Sopenharmony_ci  bgRed: 41,
921cb0ef41Sopenharmony_ci  bgYellow: 43,
931cb0ef41Sopenharmony_ci
941cb0ef41Sopenharmony_ci  grey: 90,
951cb0ef41Sopenharmony_ci  brightBlack: 90,
961cb0ef41Sopenharmony_ci  brightRed: 91,
971cb0ef41Sopenharmony_ci  brightGreen: 92,
981cb0ef41Sopenharmony_ci  brightYellow: 93,
991cb0ef41Sopenharmony_ci  brightBlue: 94,
1001cb0ef41Sopenharmony_ci  brightMagenta: 95,
1011cb0ef41Sopenharmony_ci  brightCyan: 96,
1021cb0ef41Sopenharmony_ci  brightWhite: 97,
1031cb0ef41Sopenharmony_ci
1041cb0ef41Sopenharmony_ci  bgGrey: 100,
1051cb0ef41Sopenharmony_ci  bgBrightBlack: 100,
1061cb0ef41Sopenharmony_ci  bgBrightRed: 101,
1071cb0ef41Sopenharmony_ci  bgBrightGreen: 102,
1081cb0ef41Sopenharmony_ci  bgBrightYellow: 103,
1091cb0ef41Sopenharmony_ci  bgBrightBlue: 104,
1101cb0ef41Sopenharmony_ci  bgBrightMagenta: 105,
1111cb0ef41Sopenharmony_ci  bgBrightCyan: 106,
1121cb0ef41Sopenharmony_ci  bgBrightWhite: 107
1131cb0ef41Sopenharmony_ci}
1141cb0ef41Sopenharmony_ci
1151cb0ef41Sopenharmony_ciexports.color = function color (colorWith) {
1161cb0ef41Sopenharmony_ci  if (arguments.length !== 1 || !Array.isArray(colorWith)) {
1171cb0ef41Sopenharmony_ci    colorWith = Array.prototype.slice.call(arguments)
1181cb0ef41Sopenharmony_ci  }
1191cb0ef41Sopenharmony_ci  return prefix + colorWith.map(colorNameToCode).join(';') + 'm'
1201cb0ef41Sopenharmony_ci}
1211cb0ef41Sopenharmony_ci
1221cb0ef41Sopenharmony_cifunction colorNameToCode (color) {
1231cb0ef41Sopenharmony_ci  if (colors[color] != null) return colors[color]
1241cb0ef41Sopenharmony_ci  throw new Error('Unknown color or style name: ' + color)
1251cb0ef41Sopenharmony_ci}
126