Skip to content

Add support for custom icons in Questions #1102

@RobertoPrevato

Description

@RobertoPrevato

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions