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

Add support for custom icons in Questions #1102

Open
RobertoPrevato opened this issue Apr 15, 2023 · 5 comments
Open

Add support for custom icons in Questions #1102

RobertoPrevato opened this issue Apr 15, 2023 · 5 comments

Comments

@RobertoPrevato
Copy link

RobertoPrevato commented Apr 15, 2023

Hi,
Foreword: I started studying Copier and I love it!
This is just about cosmetics.

I would like being able to configure custom icons for questions. I looked at the source code, and saw that the microphone emoji 🎤 and the detective emoji 🕵🏼 are hard-coded.

Would you consider adding the option to customize icons? I wrote an example in the diff block below, to support custom icons for questions in a backward-compatible way. I tried locally I get something like:

image

The only problem I see is that, for some reasons, some emojis seem to include right padding (like a single space), some others require a space added, like the red heart UTF-8 character , which I get when I paste the ❤️ emoji in Visual Studio Code.

value:
    type: str
    help: Some value with default icon

love_copier:
    type: bool # This makes Copier ask for y/n
    help: Do you love Copier (with chosen icon)?
    default: yes # Without a default, you force the user to answer
    qmark: "❤️ "

secret:
    type: str
    help: Some secret with default icon
    secret: true

db_password:
    type: str
    help: Some secret with chosen icon
    qmark: "📦"
    secret: true
diff --git a/copier/user_data.py b/copier/user_data.py
index 1fe07ac..e49082a 100644
--- a/copier/user_data.py
+++ b/copier/user_data.py
@@ -197,6 +197,10 @@ class Question:
             If it is a boolean, it is used directly. If it is a str, it is
             converted to boolean using a parser similar to YAML, but only for
             boolean values.
+
+        qmark:
+            If provided, sets the emoji icon displayed when rendering this question.
+            Defaults to 🎤 for regular values and 🕵️ for secrets.
     """
 
     var_name: str
@@ -211,6 +215,7 @@ class Question:
     type: str = ""
     validator: str = ""
     when: Union[str, bool] = True
+    qmark: Optional[str] = None
 
     @pydantic_validator("var_name")
     def _check_var_name(cls, v):
@@ -327,7 +332,7 @@ class Question:
             "message": self.get_message(),
             "mouse_support": True,
             "name": self.var_name,
-            "qmark": "🕵️" if self.secret else "🎤",
+            "qmark": self.qmark or ("🕵️" if self.secret else "🎤"),
             "when": self.get_when,
         }
         default = self.get_default_rendered()

If you agree and welcome a PR, I can submit one.

@RobertoPrevato
Copy link
Author

RobertoPrevato commented Apr 15, 2023

Additional considerations:

  • I'm not sure if you would like to enforce having 1 character long qmark, or if it could be composed of more characters
  • Maybe it would be worth supporting emojis with names, like :detective:, :eggplant:, etc.

Multiple characters in my opinion would make sense, if the user can configure them, like in this example:

image

@RobertoPrevato RobertoPrevato changed the title Proposal: support custom icons in Questions Add support for custom icons in Questions Apr 15, 2023
@yajo
Copy link
Member

yajo commented Apr 19, 2023

love_copier:
    type: bool # This makes Copier ask for y/n
    help: Do you love Copier (with chosen icon)?
    default: yes # Without a default, you force the user to answer
    qmark: "❤️ "

I don't think this is a good example. Obviously everybody loves copier! 😂😂

Ahem... let's get serious.

AFAICS all you want is an option to hide those icons, because then the help can contain anything you want, including one or more icons.

However I don't really like this proposal TBH... By having a static set of icons, users know that a spy means the answer won't be recorded, or that a mic means waiting for answer. I'm afraid if this could make more harm than good. 🤔

@RobertoPrevato
Copy link
Author

Thanks for your reply. 😄
I don't think the change could harm anybody: if you look at the diff section, the current behavior wouldn't change for those who don't care about customizing icons. The only difference is that the user of Copier would have the option, if they desire, to specify a different icon for a question.

Whether that is important or not it's of course a matter of personal preference, it's just cosmetics after all. But I don't see how that could harm: the author of the template needs to explicitly opt-in for that. If it's about not confusing the user of the templates, I could argue that also the 🕵🏼 icon is not an universally recognized symbol that something is a secret.

@yajo
Copy link
Member

yajo commented Apr 19, 2023

Well, it was more practical some time ago, when we didn't have a nice TUI. Now secrets are written as ***** which is also specific enough.

OK, I'll merge the PR if you want to do it. 😊 Remember to add proper docs and tests. Thanks!

@yajo yajo added this to the Community contribution milestone Apr 19, 2023
@RobertoPrevato
Copy link
Author

Thank You! 😄 I will!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants