Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7536dc7

Browse files
authored
Merge pull request #42 from Lee-W/feature/configurable-prompt-style
make style configurable for commit command
2 parents 54f17d8 + e2da79d commit 7536dc7

File tree

5 files changed

+68
-2
lines changed

5 files changed

+68
-2
lines changed

‎commitizen/commands/commit.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def __call__(self):
3636
# Prompt user for the commit message
3737
cz = self.cz
3838
questions = cz.questions()
39-
answers = questionary.prompt(questions)
39+
answers = questionary.prompt(questions, style=cz.style)
4040
if not answers:
4141
raise SystemExit(NO_ANSWERS)
4242
m = cz.message(answers)

‎commitizen/config.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ def read_raw_parser_conf(data: str) -> dict:
6161
"commitizen/__version__.py",
6262
"pyproject.toml"
6363
] # this tab at the end is important
64+
style = [
65+
["pointer", "reverse"],
66+
["question", "underline"]
67+
] # this tab at the end is important
6468
```
6569
"""
6670
config = configparser.ConfigParser(allow_no_value=True)
@@ -71,6 +75,10 @@ def read_raw_parser_conf(data: str) -> dict:
7175
files = _data["files"]
7276
_f = json.loads(files)
7377
_data.update({"files": _f})
78+
if "style" in _data:
79+
style = _data["style"]
80+
_s = json.loads(style)
81+
_data.update({"style": _s})
7482

7583
return _data
7684

‎commitizen/cz/base.py‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,29 @@
1-
from typing import Optional
1+
from typing import Optional, List, Tuple
22
from abc import ABCMeta, abstractmethod
33

4+
from prompt_toolkit.styles import merge_styles, Style
5+
46

57
class BaseCommitizen(metaclass=ABCMeta):
68
bump_pattern: Optional[str] = None
79
bump_map: Optional[dict] = None
10+
default_style_config: List[Tuple[str, str]] = [
11+
("qmark", "fg:#ff9d00 bold"),
12+
("question", "bold"),
13+
("answer", "fg:#ff9d00 bold"),
14+
("pointer", "fg:#ff9d00 bold"),
15+
("highlighted", "fg:#ff9d00 bold"),
16+
("selected", "fg:#cc5454"),
17+
("separator", "fg:#cc5454"),
18+
("instruction", ""),
19+
("text", ""),
20+
("disabled", "fg:#858585 italic"),
21+
]
822

923
def __init__(self, config: dict):
1024
self.config = config
25+
if not self.config.get("style"):
26+
self.config["style"] = BaseCommitizen.default_style_config
1127

1228
@abstractmethod
1329
def questions(self) -> list:
@@ -17,6 +33,12 @@ def questions(self) -> list:
1733
def message(self, answers: dict) -> str:
1834
"""Format your git message."""
1935

36+
@property
37+
def style(self):
38+
return merge_styles(
39+
[Style(BaseCommitizen.default_style_config), Style(self.config["style"])]
40+
)
41+
2042
def example(self) -> str:
2143
"""Example of the commit message."""
2244
raise NotImplementedError("Not Implemented yet")

‎docs/config.md‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@ Add an entry to `pyproject.toml`. Recommended for **python** projects.
1313
"src/__version__.py",
1414
"pyproject.toml:version"
1515
]
16+
style = [
17+
["qmark", "fg:#ff9d00 bold"],
18+
["question", "bold"],
19+
["answer", "fg:#ff9d00 bold"],
20+
["pointer", "fg:#ff9d00 bold"],
21+
["highlighted", "fg:#ff9d00 bold"],
22+
["selected", "fg:#cc5454"],
23+
["separator", "fg:#cc5454"],
24+
["instruction", ""],
25+
["text", ""],
26+
["disabled", "fg:#858585 italic"]
27+
]
1628

1729
## INI files
1830

@@ -28,6 +40,18 @@ Recommended for **other languages** projects (js, go, etc).
2840
"src/__version__.py",
2941
"pyproject.toml:version"
3042
]
43+
style = [
44+
["qmark", "fg:#ff9d00 bold"],
45+
["question", "bold"],
46+
["answer", "fg:#ff9d00 bold"],
47+
["pointer", "fg:#ff9d00 bold"],
48+
["highlighted", "fg:#ff9d00 bold"],
49+
["selected", "fg:#cc5454"],
50+
["separator", "fg:#cc5454"],
51+
["instruction", ""],
52+
["text", ""],
53+
["disabled", "fg:#858585 italic"]
54+
]
3155

3256
The extra tab before the square brakets (`]`) at the end is required.
3357

@@ -40,3 +64,4 @@ The extra tab before the square brakets (`]`) at the end is required.
4064
| `files` | `list` | `[ ]` | Files were the version will be updated. A pattern to match a line, can also be specified, separated by `:` [See more](https://woile.github.io/commitizen/bump#files) |
4165
| `tag_format` | `str` | `None` | Format for the git tag, useful for old projects, that use a convention like `"v1.2.1"`. [See more](https://woile.github.io/commitizen/bump#tag_format) |
4266
| `bump_message` | `str` | `None` | Create custom commit message, useful to skip ci. [See more](https://woile.github.io/commitizen/bump#bump_message) |
67+
| `style` | `list` | see above | Style for the prompts (It will merge this value with default style.) [See More (Styling your prompts with your favorite colors)](https://github.com/tmbo/questionary#additional-features) |

‎tests/test_conf.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
"commitizen/__version__.py",
1212
"pyproject.toml"
1313
]
14+
style = [
15+
["pointer", "reverse"],
16+
["question", "underline"]
17+
]
1418
1519
[tool.black]
1620
line-length = 88
@@ -25,6 +29,10 @@
2529
"commitizen/__version__.py",
2630
"pyproject.toml"
2731
]
32+
style = [
33+
["pointer", "reverse"],
34+
["question", "underline"]
35+
]
2836
"""
2937

3038
_config = {
@@ -33,6 +41,7 @@
3341
"tag_format": None,
3442
"bump_message": None,
3543
"files": ["commitizen/__version__.py", "pyproject.toml"],
44+
"style": [["pointer", "reverse"], ["question", "underline"]]
3645
}
3746

3847
_new_config = {
@@ -41,12 +50,14 @@
4150
"tag_format": None,
4251
"bump_message": None,
4352
"files": ["commitizen/__version__.py", "pyproject.toml"],
53+
"style": [["pointer", "reverse"], ["question", "underline"]]
4454
}
4555

4656
_read_conf = {
4757
"name": "cz_jira",
4858
"version": "1.0.0",
4959
"files": ["commitizen/__version__.py", "pyproject.toml"],
60+
"style": [["pointer", "reverse"], ["question", "underline"]]
5061
}
5162

5263

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /