Giter Site home page Giter Site logo

Use of moved value `confirm` about dialoguer HOT 5 CLOSED

ShayBox avatar ShayBox commented on August 16, 2024
Use of moved value `confirm`

from dialoguer.

Comments (5)

pksunkara avatar pksunkara commented on August 16, 2024

Yes, it will be a breaking change to support the builder pattern.

preventing re-use and requiring constant re-initialization.

You wouldn't need it. Can you describe more on the differences? How did it used to be and how did you need to change it?

from dialoguer.

ShayBox avatar ShayBox commented on August 16, 2024

I used it like this: let mut confirm = Confirm::new(); which let you initialize Confirm, Input, etc once and set the theme once instead of doing it 50 times. The builder pattern is nice but the prompt_with method shouldn't be part of the builder, but on the variable the builder returns so it can be re-used as many times as needed.

from dialoguer.

pksunkara avatar pksunkara commented on August 16, 2024

Just to make sure I don't misunderstand, I would prefer a more concrete example with code. Please understand that I don't have the full context here compared to you.

from dialoguer.

ShayBox avatar ShayBox commented on August 16, 2024
let theme = ColorfulTheme::default();

// Stable
let mut confirm = Confirm::with_theme(&theme);
if confirm.with_prompt("Question 1").interact().unwrap() {}
if confirm.with_prompt("Question 2").interact().unwrap() {}
if confirm.with_prompt("Question 3").interact().unwrap() {}

// Git
if Confirm::with_theme(&theme)
    .with_prompt("Question 1")
    .interact()
    .unwrap()
{}
if Confirm::with_theme(&theme)
    .with_prompt("Question 2")
    .interact()
    .unwrap()
{}
if Confirm::with_theme(&theme)
    .with_prompt("Question 3")
    .interact()
    .unwrap()
{}

With stable if the prompt becomes too long and rustfmt wraps the lines you can create a prompt variable for the input prompt which only takes 2 lines, with the git code it always takes 4 lines even with the prompt variable to separate the input prompt. It also requires initializing a new Confirm and borrowing the Theme every time, this ends up with the git code taking 6 lines of code (because open and close braces are on new lines) rather than 2-3 for the stable code, and this stacks the more questions you ask.

from dialoguer.

pksunkara avatar pksunkara commented on August 16, 2024

All the prompts are now cloneable so that you can reduce the code's duplicity.

from dialoguer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.