Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interactive dialog #2

Open
ThatOneCalculator opened this issue Jan 2, 2024 · 0 comments
Open

Interactive dialog #2

ThatOneCalculator opened this issue Jan 2, 2024 · 0 comments

Comments

@ThatOneCalculator
Copy link

Right now I'm doing this, which prints out the dialog, but doesn't make it interactive. Is there any built-in way to do interactive dialogs?

import blipgloss from "blipgloss";

// Adapted from https://github.com/wobsoriano/blipgloss/blob/main/examples/layout.ts
const docStyle = blipgloss.NewStyle().Padding(1, 2, 1, 2);
const doc: string[] = [];
const width = 72;

const dialogBoxStyle = blipgloss
  .NewStyle()
  .Border(blipgloss.Border.Rounded)
  .BorderForeground("#56949f")
  .Padding(1, 0)
  .BorderTop(true)
  .BorderLeft(true)
  .BorderRight(true)
  .BorderBottom(true);

const buttonStyle = blipgloss
  .NewStyle()
  .Foreground("#faf4ed")
  .Background("#575279")
  .Padding(0, 3)
  .MarginTop(1);

const activeButtonStyle = buttonStyle
  .Copy()
  .Foreground("#faf4ed")
  .Background("#b4637a")
  .MarginRight(2)
  .Underline(true);

const okButton = activeButtonStyle.Render("Yes");
const cancelButton = buttonStyle.Render("No");

const question = blipgloss
  .NewStyle()
  .Width(50)
  .Align(blipgloss.Position.Center)
  .Render(`Update ${outdated.map((model) => model.name).join(", ")}?`);
const buttons = blipgloss.JoinHorizontal(
  blipgloss.Position.Top,
  okButton,
  cancelButton
);
const ui = blipgloss.JoinVertical(
  blipgloss.Position.Center,
  question,
  buttons
);

const dialog = blipgloss.Place(
  width,
  9,
  blipgloss.Position.Center,
  blipgloss.Position.Center,
  dialogBoxStyle.Render(ui),
  blipgloss.WithWhitespaceChars("🦙"),
);

doc.push(dialog);

console.log(docStyle.Render(doc.join("\n\n")));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant