How to use cli-truncate - 8 common examples

To help you get started, we’ve selected a few cli-truncate 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 neo-one-suite / neo-one / packages / neo-one-cli / src / interactive / createCRUD.js View on Github external
} else if (data == null) {
        data = task.message;
      }

      if (data != null) {
        data = stripAnsi(
          data
            .trim()
            .split('\n')
            .filter(Boolean)
            .pop(),
        );
        const out = indentString(`${figures.arrowRight} ${data}`, level, '  ');
        output.push(
          // $FlowFixMe
          `   ${chalk.gray(cliTruncate(out, process.stdout.columns - 3))}`,
        );
      }
    }

    if (
      (task.pending || task.error != null || !task.collapse) &&
      task.subtasks != null &&
      task.subtasks.length > 0
    ) {
      output = output.concat(renderTasks(task.subtasks, spinners, level + 1));
    }
  }

  return output.join('\n');
};
github dawg / vusic / src / context.ts View on Github external
defaultActions.separator(),
      defaultActions.copyLink(),
      defaultActions.separator(),
      options.showInspectElement && defaultActions.inspect(),
      defaultActions.separator(),
    ];

    // Filter out leading/trailing separators
    // FIXME: https://github.com/electron/electron/issues/5869
    menuTemplate = removeUnusedMenuItems(menuTemplate);

    for (const menuItem of menuTemplate) {
      // Replace placeholders in menu item labels
      if (typeof menuItem.label === 'string' && menuItem.label.includes('{selection}')) {
        const selectionString = typeof props.selectionText === 'string' ? props.selectionText.trim() : '';
        menuItem.label = menuItem.label.replace('{selection}', cliTruncate(selectionString, 25));
      }
    }

    if (menuTemplate.length > 0) {
      const menu = (electron.remote ? electron.remote.Menu : electron.Menu).buildFromTemplate(menuTemplate);

      /*
			When `electron.remote`` is not available this runs in the browser process.
			We can safely use `win`` in this case as it refers to the window the
			context-menu should open in.
			When this is being called from a webView, we can't use win as this
			would refere to the webView which is not allowed to render a popup menu.
			*/
      menu.popup(electron.remote ? electron.remote.getCurrentWindow() : win);
    }
  });
github neo-one-suite / neo-one / packages / neo-one-server-plugin / src / handleCLITaskList.ts View on Github external
data = task.skipped;
        }
      } else if (data === undefined) {
        data = task.message;
      }

      if (data !== undefined) {
        data = stripAnsi(
          data
            .trim()
            .split('\n')
            .filter(utils.notNull)[0],
        );

        const out = indentString(`${figures.arrowRight} ${data}`, level, { indent: '  ' });
        mutableOutput.push(`   ${chalk.gray(cliTruncate(out, (process.stdout.columns as number) - 3))}`);
      }
    }

    if (
      (task.pending || task.error !== undefined || !task.collapse) &&
      task.subtasks !== undefined &&
      task.subtasks.length > 0
    ) {
      mutableOutput = mutableOutput.concat(renderTasks(task.subtasks, spinners, level + 1));
    }
  });
github vadimdemedes / ink / src / wrap-text.js View on Github external
if (String(textWrap).startsWith('truncate')) {
		let position;

		if (textWrap === 'truncate' || textWrap === 'truncate-end') {
			position = 'end';
		}

		if (textWrap === 'truncate-middle') {
			position = 'middle';
		}

		if (textWrap === 'truncate-start') {
			position = 'start';
		}

		return cliTruncate(text, maxWidth, {position});
	}

	return text;
};
github milesj / boost / packages / core / src / Reporter.ts View on Github external
truncate(
    message: string,
    columns?: number,
    options?: { position?: 'start' | 'middle' | 'end' },
  ): string {
    return cliTruncate(message, columns || this.size().columns, options);
  }
github jeffbski / pkglink / src / util / format.js View on Github external
export function trunc(size, str) {
  return truncate(str, size, { position: 'middle' });
}
github prisma / lift / src / utils / drawBox.ts View on Github external
.map(l => {
      const lineWidth = Math.min(stringWidth(l), width)
      const paddingRight = Math.max(width - lineWidth - 2, 0)
      return `${chalk.grey(chars.vertical)}${chalk.reset(cliTruncate(l, width - 2))}${' '.repeat(
        paddingRight,
      )}${chalk.grey(chars.vertical)}`
    })
    .join('\n')
github prisma / prisma2 / cli / ink-components / src / components / drawBox.tsx View on Github external
.map(l => {
      const lineWidth = Math.min(stringWidth(l || ''), width)
      const paddingRight = Math.max(width - lineWidth - 2, 0)
      return `${chalk.grey(chars.vertical)}${chalk.reset(cliTruncate(l, width - 2))}${' '.repeat(
        paddingRight,
      )}${chalk.grey(chars.vertical)}`
    })
    .join('\n')

cli-truncate

Truncate a string to a specific width in the terminal

MIT
Latest version published 1 year ago

Package Health Score

70 / 100
Full package analysis

Popular cli-truncate functions