Commit 7a372c75 by Sébastien Eustace

Make terminal colors more consistent

parent 7a34f6ea
...@@ -21,7 +21,7 @@ class BuildCommand(EnvCommand): ...@@ -21,7 +21,7 @@ class BuildCommand(EnvCommand):
package = self.poetry.package package = self.poetry.package
self.line( self.line(
"Building <info>{}</> (<comment>{}</>)".format( "Building <c1>{}</c1> (<b>{}</b>)".format(
package.pretty_name, package.version package.pretty_name, package.version
) )
) )
......
...@@ -116,11 +116,7 @@ class DebugResolveCommand(InitCommand): ...@@ -116,11 +116,7 @@ class DebugResolveCommand(InitCommand):
current_python_version current_python_version
) or not env.is_valid_for_marker(pkg.marker): ) or not env.is_valid_for_marker(pkg.marker):
continue continue
row = [ row = ["<c1>{}</c1>".format(pkg.name), "<b>{}</b>".format(pkg.version), ""]
"<info>{}</info>".format(pkg.name),
"<b>{}</b>".format(pkg.version),
"",
]
if not pkg.marker.is_any(): if not pkg.marker.is_any():
row[2] = str(pkg.marker) row[2] = str(pkg.marker)
......
...@@ -52,7 +52,7 @@ class InitCommand(Command): ...@@ -52,7 +52,7 @@ class InitCommand(Command):
] ]
help = """\ help = """\
The <info>init</info> command creates a basic <comment>pyproject.toml</> file in the current directory. The <c1>init</c1> command creates a basic <comment>pyproject.toml</> file in the current directory.
""" """
def __init__(self): def __init__(self):
...@@ -249,7 +249,7 @@ The <info>init</info> command creates a basic <comment>pyproject.toml</> file in ...@@ -249,7 +249,7 @@ The <info>init</info> command creates a basic <comment>pyproject.toml</> file in
choices.append(found_package.pretty_name) choices.append(found_package.pretty_name)
self.line( self.line(
"Found <info>{}</info> packages matching <info>{}</info>".format( "Found <info>{}</info> packages matching <c1>{}</c1>".format(
len(matches), package len(matches), package
) )
) )
...@@ -277,7 +277,7 @@ The <info>init</info> command creates a basic <comment>pyproject.toml</> file in ...@@ -277,7 +277,7 @@ The <info>init</info> command creates a basic <comment>pyproject.toml</> file in
) )
self.line( self.line(
"Using version <info>{}</info> for <info>{}</info>".format( "Using version <b>{}</b> for <c1>{}</c1>".format(
package_constraint, package package_constraint, package
) )
) )
......
...@@ -77,7 +77,7 @@ exist it will look for <comment>pyproject.toml</> and do the same. ...@@ -77,7 +77,7 @@ exist it will look for <comment>pyproject.toml</> and do the same.
return 0 return 0
self.line( self.line(
" - Installing <info>{}</info> (<comment>{}</comment>)".format( " - Installing <c1>{}</c1> (<b>{}</b>)".format(
self.poetry.package.pretty_name, self.poetry.package.pretty_version self.poetry.package.pretty_name, self.poetry.package.pretty_version
) )
) )
......
...@@ -80,8 +80,8 @@ lists all packages available.""" ...@@ -80,8 +80,8 @@ lists all packages available."""
return 0 return 0
rows = [ rows = [
["<info>name</>", " : <info>{}</>".format(pkg.pretty_name)], ["<info>name</>", " : <c1>{}</>".format(pkg.pretty_name)],
["<info>version</>", " : <comment>{}</>".format(pkg.pretty_version)], ["<info>version</>", " : <b>{}</b>".format(pkg.pretty_version)],
["<info>description</>", " : {}".format(pkg.description)], ["<info>description</>", " : {}".format(pkg.description)],
] ]
...@@ -93,7 +93,7 @@ lists all packages available.""" ...@@ -93,7 +93,7 @@ lists all packages available."""
self.line("<info>dependencies</info>") self.line("<info>dependencies</info>")
for dependency in pkg.requires: for dependency in pkg.requires:
self.line( self.line(
" - {} <comment>{}</>".format( " - <c1>{}</c1> <b>{}</b>".format(
dependency.pretty_name, dependency.pretty_constraint dependency.pretty_name, dependency.pretty_constraint
) )
) )
...@@ -211,7 +211,7 @@ lists all packages available.""" ...@@ -211,7 +211,7 @@ lists all packages available."""
self.line(line) self.line(line)
def display_package_tree(self, io, package, installed_repo): def display_package_tree(self, io, package, installed_repo):
io.write("<info>{}</info>".format(package.pretty_name)) io.write("<c1>{}</c1>".format(package.pretty_name))
description = "" description = ""
if package.description: if package.description:
description = " " + package.description description = " " + package.description
......
...@@ -47,7 +47,7 @@ patch, minor, major, prepatch, preminor, premajor, prerelease. ...@@ -47,7 +47,7 @@ patch, minor, major, prepatch, preminor, premajor, prerelease.
) )
self.line( self.line(
"Bumping version from <comment>{}</> to <info>{}</>".format( "Bumping version from <b>{}</> to <fg=green>{}</>".format(
self.poetry.package.pretty_version, version self.poetry.package.pretty_version, version
) )
) )
......
...@@ -16,7 +16,7 @@ class ApplicationConfig(BaseApplicationConfig): ...@@ -16,7 +16,7 @@ class ApplicationConfig(BaseApplicationConfig):
super(ApplicationConfig, self).configure() super(ApplicationConfig, self).configure()
self.add_style(Style("c1").fg("cyan")) self.add_style(Style("c1").fg("cyan"))
self.add_style(Style("info").fg("cyan")) self.add_style(Style("info").fg("blue"))
self.add_style(Style("comment").fg("green")) self.add_style(Style("comment").fg("green"))
self.add_style(Style("error").fg("red").bold()) self.add_style(Style("error").fg("red").bold())
self.add_style(Style("warning").fg("yellow")) self.add_style(Style("warning").fg("yellow"))
......
...@@ -305,7 +305,7 @@ class Installer: ...@@ -305,7 +305,7 @@ class Installer:
if operation.skipped: if operation.skipped:
if self.is_verbose() and (self._execute_operations or self.is_dry_run()): if self.is_verbose() and (self._execute_operations or self.is_dry_run()):
self._io.write_line( self._io.write_line(
" - Skipping <info>{}</> (<comment>{}</>) {}".format( " - Skipping <c1>{}</c1> (<b>{}</b>) {}".format(
operation.package.pretty_name, operation.package.pretty_name,
operation.package.full_pretty_version, operation.package.full_pretty_version,
operation.skip_reason, operation.skip_reason,
...@@ -316,7 +316,7 @@ class Installer: ...@@ -316,7 +316,7 @@ class Installer:
if self._execute_operations or self.is_dry_run(): if self._execute_operations or self.is_dry_run():
self._io.write_line( self._io.write_line(
" - Installing <info>{}</> (<comment>{}</>)".format( " - Installing <c1>{}</c1> (<b>{}</b>)".format(
operation.package.pretty_name, operation.package.full_pretty_version operation.package.pretty_name, operation.package.full_pretty_version
) )
) )
...@@ -333,7 +333,7 @@ class Installer: ...@@ -333,7 +333,7 @@ class Installer:
if operation.skipped: if operation.skipped:
if self.is_verbose() and (self._execute_operations or self.is_dry_run()): if self.is_verbose() and (self._execute_operations or self.is_dry_run()):
self._io.write_line( self._io.write_line(
" - Skipping <info>{}</> (<comment>{}</>) {}".format( " - Skipping <c1>{}</c1> (<comment>{}</>) {}".format(
target.pretty_name, target.pretty_name,
target.full_pretty_version, target.full_pretty_version,
operation.skip_reason, operation.skip_reason,
...@@ -360,7 +360,7 @@ class Installer: ...@@ -360,7 +360,7 @@ class Installer:
if operation.skipped: if operation.skipped:
if self.is_verbose() and (self._execute_operations or self.is_dry_run()): if self.is_verbose() and (self._execute_operations or self.is_dry_run()):
self._io.write_line( self._io.write_line(
" - Not removing <info>{}</> (<comment>{}</>) {}".format( " - Not removing <c1>{}</c1> (<b>{}</b>) {}".format(
operation.package.pretty_name, operation.package.pretty_name,
operation.package.full_pretty_version, operation.package.full_pretty_version,
operation.skip_reason, operation.skip_reason,
...@@ -371,7 +371,7 @@ class Installer: ...@@ -371,7 +371,7 @@ class Installer:
if self._execute_operations or self.is_dry_run(): if self._execute_operations or self.is_dry_run():
self._io.write_line( self._io.write_line(
" - Removing <info>{}</> (<comment>{}</>)".format( " - Removing <c1>{}</c1> (<b>{}</b>)".format(
operation.package.pretty_name, operation.package.full_pretty_version operation.package.pretty_name, operation.package.full_pretty_version
) )
) )
......
...@@ -26,8 +26,8 @@ class Publisher: ...@@ -26,8 +26,8 @@ class Publisher:
def publish(self, repository_name, username, password, cert=None, client_cert=None): def publish(self, repository_name, username, password, cert=None, client_cert=None):
if repository_name: if repository_name:
self._io.write_line( self._io.write_line(
"Publishing <info>{}</info> (<comment>{}</comment>) " "Publishing <c1>{}</c1> (<b>{}</b>) "
"to <fg=cyan>{}</>".format( "to <info>{}</info>".format(
self._package.pretty_name, self._package.pretty_name,
self._package.pretty_version, self._package.pretty_version,
repository_name, repository_name,
...@@ -35,8 +35,8 @@ class Publisher: ...@@ -35,8 +35,8 @@ class Publisher:
) )
else: else:
self._io.write_line( self._io.write_line(
"Publishing <info>{}</info> (<comment>{}</comment>) " "Publishing <c1>{}</c1> (<b>{}</b>) "
"to <fg=cyan>PyPI</>".format( "to <info>PyPI</info>".format(
self._package.pretty_name, self._package.pretty_version self._package.pretty_name, self._package.pretty_version
) )
) )
......
...@@ -229,7 +229,7 @@ class Uploader: ...@@ -229,7 +229,7 @@ class Uploader:
encoder = MultipartEncoder(data_to_send) encoder = MultipartEncoder(data_to_send)
bar = self._io.progress_bar(encoder.len) bar = self._io.progress_bar(encoder.len)
bar.set_format( bar.set_format(
" - Uploading <info>{0}</> <comment>%percent%%</>".format(file.name) " - Uploading <c1>{0}</c1> <b>%percent%%</b>".format(file.name)
) )
monitor = MultipartEncoderMonitor( monitor = MultipartEncoderMonitor(
encoder, lambda monitor: bar.set_progress(monitor.bytes_read) encoder, lambda monitor: bar.set_progress(monitor.bytes_read)
...@@ -245,13 +245,18 @@ class Uploader: ...@@ -245,13 +245,18 @@ class Uploader:
) )
if resp.ok: if resp.ok:
bar.set_format(
" - Uploading <c1>{0}</c1> <fg=green>%percent%%</>".format(
file.name
)
)
bar.finish() bar.finish()
self._io.write_line("") self._io.write_line("")
else: else:
if self._io.output.supports_ansi(): if self._io.output.supports_ansi():
self._io.overwrite( self._io.overwrite(
" - Uploading <info>{0}</> <error>{1}%</>".format( " - Uploading <c1>{0}</c1> <error>{1}%</>".format(
file.name, int(math.floor(bar._percent * 100)) file.name, int(math.floor(bar._percent * 100))
) )
) )
......
...@@ -708,44 +708,42 @@ class Provider: ...@@ -708,44 +708,42 @@ class Provider:
m2 = re.match(r"(.+?) \((.+?)\)", m.group(1)) m2 = re.match(r"(.+?) \((.+?)\)", m.group(1))
if m2: if m2:
name = m2.group(1) name = m2.group(1)
version = " (<comment>{}</comment>)".format(m2.group(2)) version = " (<b>{}</b>)".format(m2.group(2))
else: else:
name = m.group(1) name = m.group(1)
version = "" version = ""
message = ( message = (
"<fg=blue>fact</>: <info>{}</info>{} " "<fg=blue>fact</>: <c1>{}</c1>{} "
"depends on <info>{}</info> (<comment>{}</comment>)".format( "depends on <c1>{}</c1> (<b>{}</b>)".format(
name, version, m.group(2), m.group(3) name, version, m.group(2), m.group(3)
) )
) )
elif " is " in message: elif " is " in message:
message = re.sub( message = re.sub(
"fact: (.+) is (.+)", "fact: (.+) is (.+)",
"<fg=blue>fact</>: <info>\\1</info> is <comment>\\2</comment>", "<fg=blue>fact</>: <c1>\\1</c1> is <b>\\2</b>",
message, message,
) )
else: else:
message = re.sub( message = re.sub(
r"(?<=: )(.+?) \((.+?)\)", r"(?<=: )(.+?) \((.+?)\)", "<c1>\\1</c1> (<b>\\2</b>)", message
"<info>\\1</info> (<comment>\\2</comment>)",
message,
) )
message = "<fg=blue>fact</>: {}".format(message.split("fact: ")[1]) message = "<fg=blue>fact</>: {}".format(message.split("fact: ")[1])
elif message.startswith("selecting "): elif message.startswith("selecting "):
message = re.sub( message = re.sub(
r"selecting (.+?) \((.+?)\)", r"selecting (.+?) \((.+?)\)",
"<fg=blue>selecting</> <info>\\1</info> (<comment>\\2</comment>)", "<fg=blue>selecting</> <c1>\\1</c1> (<b>\\2</b>)",
message, message,
) )
elif message.startswith("derived:"): elif message.startswith("derived:"):
m = re.match(r"derived: (.+?) \((.+?)\)$", message) m = re.match(r"derived: (.+?) \((.+?)\)$", message)
if m: if m:
message = "<fg=blue>derived</>: <info>{}</info> (<comment>{}</comment>)".format( message = "<fg=blue>derived</>: <c1>{}</c1> (<b>{}</b>)".format(
m.group(1), m.group(2) m.group(1), m.group(2)
) )
else: else:
message = "<fg=blue>derived</>: <info>{}</info>".format( message = "<fg=blue>derived</>: <c1>{}</c1>".format(
message.split("derived: ")[1] message.split("derived: ")[1]
) )
elif message.startswith("conflict:"): elif message.startswith("conflict:"):
...@@ -754,14 +752,14 @@ class Provider: ...@@ -754,14 +752,14 @@ class Provider:
m2 = re.match(r"(.+?) \((.+?)\)", m.group(1)) m2 = re.match(r"(.+?) \((.+?)\)", m.group(1))
if m2: if m2:
name = m2.group(1) name = m2.group(1)
version = " (<comment>{}</comment>)".format(m2.group(2)) version = " (<b>{}</b>)".format(m2.group(2))
else: else:
name = m.group(1) name = m.group(1)
version = "" version = ""
message = ( message = (
"<fg=red;options=bold>conflict</>: <info>{}</info>{} " "<fg=red;options=bold>conflict</>: <c1>{}</c1>{} "
"depends on <info>{}</info> (<comment>{}</comment>)".format( "depends on <c1>{}</c1> (<b>{}</b>)".format(
name, version, m.group(2), m.group(3) name, version, m.group(2), m.group(3)
) )
) )
......
...@@ -545,9 +545,7 @@ class EnvManager(object): ...@@ -545,9 +545,7 @@ class EnvManager(object):
continue continue
if supported_python.allows(Version.parse(python_patch)): if supported_python.allows(Version.parse(python_patch)):
io.write_line( io.write_line("Using <c1>{}</c1> ({})".format(python, python_patch))
"Using <info>{}</info> ({})".format(python, python_patch)
)
executable = python executable = python
python_minor = ".".join(python_patch.split(".")[:2]) python_minor = ".".join(python_patch.split(".")[:2])
break break
...@@ -576,19 +574,19 @@ class EnvManager(object): ...@@ -576,19 +574,19 @@ class EnvManager(object):
return SystemEnv(Path(sys.prefix)) return SystemEnv(Path(sys.prefix))
io.write_line( io.write_line(
"Creating virtualenv <info>{}</> in {}".format(name, str(venv_path)) "Creating virtualenv <c1>{}</> in {}".format(name, str(venv_path))
) )
self.build_venv(str(venv), executable=executable) self.build_venv(str(venv), executable=executable)
else: else:
if force: if force:
io.write_line( io.write_line(
"Recreating virtualenv <info>{}</> in {}".format(name, str(venv)) "Recreating virtualenv <c1>{}</> in {}".format(name, str(venv))
) )
self.remove_venv(str(venv)) self.remove_venv(str(venv))
self.build_venv(str(venv), executable=executable) self.build_venv(str(venv), executable=executable)
elif io.is_very_verbose(): elif io.is_very_verbose():
io.write_line("Virtualenv <info>{}</> already exists.".format(name)) io.write_line("Virtualenv <c1>{}</> already exists.".format(name))
# venv detection: # venv detection:
# stdlib venv may symlink sys.executable, so we can't use realpath. # stdlib venv may symlink sys.executable, so we can't use realpath.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment