rake-db 2.37.14 → 2.37.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -3636,7 +3636,8 @@ const CSI = `[`;
3636
3636
  const cursorShow = `${CSI}?25h`;
3637
3637
  const cursorHide = `${CSI}?25l`;
3638
3638
  const { stdin, stdout } = process;
3639
- const visibleChars = (s) => s.replace(/[\u001B\u009B][[\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\d/#&.:=?%@~_]+)*|[a-zA-Z\d]+(?:;[-a-zA-Z\d/#&.:=?%@~_]*)*)?\u0007)|(?:(?:\d{1,4}(?:;\d{0,4})*)?[\dA-PRZcf-ntqry=><~]))/g, "").length;
3639
+ const stripAnsi = (s) => s.replace(/[\u001B\u009B][[\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\d/#&.:=?%@~_]+)*|[a-zA-Z\d]+(?:;[-a-zA-Z\d/#&.:=?%@~_]*)*)?\u0007)|(?:(?:\d{1,4}(?:;\d{0,4})*)?[\dA-PRZcf-ntqry=><~]))/g, "");
3640
+ const visibleChars = (s) => stripAnsi(s).length;
3640
3641
  const clear = (text) => {
3641
3642
  const rows = text.split(/\r?\n/).reduce((rows, line) => rows + 1 + Math.floor(Math.max(visibleChars(line) - 1, 0) / stdout.columns), 0);
3642
3643
  let clear = "";
@@ -3646,9 +3647,10 @@ const clear = (text) => {
3646
3647
  }
3647
3648
  return clear;
3648
3649
  };
3649
- const prompt = async ({ render, onKeyPress, validate, value, cursor: showCursor }) => {
3650
+ const prompt = async ({ message, render, onKeyPress, validate, value, cursor: showCursor }) => {
3651
+ if (!stdin.isTTY) throw new RakeDbError(`Cannot prompt "${stripAnsi(message)}": stdin is not a TTY, run the command in an interactive terminal`);
3650
3652
  stdin.resume();
3651
- if (stdin.isTTY) stdin.setRawMode(true);
3653
+ stdin.setRawMode(true);
3652
3654
  stdin.setEncoding("utf-8");
3653
3655
  if (!showCursor) stdout.write(cursorHide);
3654
3656
  return new Promise((res) => {
@@ -3673,7 +3675,7 @@ const prompt = async ({ render, onKeyPress, validate, value, cursor: showCursor
3673
3675
  };
3674
3676
  const close = () => {
3675
3677
  if (!showCursor) stdout.write(cursorShow);
3676
- if (stdin.isTTY) stdin.setRawMode(false);
3678
+ stdin.setRawMode(false);
3677
3679
  stdin.off("data", keypress);
3678
3680
  stdin.pause();
3679
3681
  };
@@ -3692,6 +3694,7 @@ const prompt = async ({ render, onKeyPress, validate, value, cursor: showCursor
3692
3694
  const defaultActive = (s) => `${pqb_internal.colors.blueBold("❯")} ${s}`;
3693
3695
  const defaultInactive = (s) => ` ${s}`;
3694
3696
  const promptSelect = ({ message, options, active = defaultActive, inactive = defaultInactive }) => prompt({
3697
+ message,
3695
3698
  value: 0,
3696
3699
  render(ctx) {
3697
3700
  let text = `${message} ${pqb_internal.colors.pale("Use arrows or jk. Press enter to submit.")}\n`;
@@ -3704,6 +3707,7 @@ const promptSelect = ({ message, options, active = defaultActive, inactive = def
3704
3707
  }
3705
3708
  });
3706
3709
  const promptConfirm = ({ message }) => prompt({
3710
+ message,
3707
3711
  value: true,
3708
3712
  render(ctx) {
3709
3713
  return `${pqb_internal.colors.bright(message)}\n${ctx.submitted ? `> ${ctx.value ? pqb_internal.colors.greenBold("Yes") : pqb_internal.colors.yellowBold("No")}` : pqb_internal.colors.pale(`> (Y/n)`)}\n`;
@@ -3720,6 +3724,7 @@ const promptText = ({ message, default: def = "", password, min }) => {
3720
3724
  let x = 0;
3721
3725
  const renderValue = (ctx) => password ? "*".repeat(ctx.value.length) : ctx.value;
3722
3726
  return prompt({
3727
+ message,
3723
3728
  value: def,
3724
3729
  cursor: true,
3725
3730
  validate: (ctx) => !min || ctx.value.length >= min,