summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2018-02-23 19:37:06 +0900
committerTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2018-02-23 22:14:53 +0900
commit7b5858c1783730ea1e31adafb982e7b0edcefcf9 (patch)
tree4e82f5f77160f169a28a5c003430956585a640b3
parenta2ab07e95d805ffaf1b8f91095afac0a05a83b8f (diff)
downloadbuildstream-7b5858c1783730ea1e31adafb982e7b0edcefcf9.tar.gz
_frontend: Added App.shell() to call instead of directly invoking the Element._shell()
And use this place to format a custom prompt for PS1, here we have click and we use the ANSI colors in PS1 only if colors are enabled.
-rw-r--r--buildstream/_frontend/cli.py3
-rw-r--r--buildstream/_frontend/main.py19
2 files changed, 20 insertions, 2 deletions
diff --git a/buildstream/_frontend/cli.py b/buildstream/_frontend/cli.py
index c5fc87bab..29bae1da4 100644
--- a/buildstream/_frontend/cli.py
+++ b/buildstream/_frontend/cli.py
@@ -510,7 +510,8 @@ def shell(app, element, sysroot, isolate, build, command):
sys.exit(-1)
try:
- exitcode = app.pipeline.targets[0]._shell(scope, sysroot, isolate=isolate, command=command)
+ element = app.pipeline.targets[0]
+ exitcode = app.shell(element, scope, sysroot, isolate=isolate, command=command)
sys.exit(exitcode)
except BstError as e:
click.echo("", err=True)
diff --git a/buildstream/_frontend/main.py b/buildstream/_frontend/main.py
index dc251748d..9d30dd7fa 100644
--- a/buildstream/_frontend/main.py
+++ b/buildstream/_frontend/main.py
@@ -342,7 +342,7 @@ class App():
if choice == 'shell':
click.echo("\nDropping into an interactive shell in the failed build sandbox\n", err=True)
try:
- element._shell(Scope.BUILD, failure.sandbox, isolate=True)
+ self.shell(element, Scope.BUILD, failure.sandbox, isolate=True)
except BstError as e:
click.echo("Error while attempting to create interactive shell: {}".format(e), err=True)
elif choice == 'log':
@@ -364,6 +364,23 @@ class App():
queue.failed_elements.remove(element)
queue.enqueue([element])
+ def shell(self, element, scope, directory, isolate=False, command=None):
+ _, key, dim = element._get_full_display_key()
+ element_name = element._get_full_name()
+
+ if self.colors:
+ p = Profile()
+ prompt = self.format_profile.fmt('[') + \
+ self.content_profile.fmt(key, dim=dim) + \
+ self.format_profile.fmt('@') + \
+ p.fmt(element_name, fg='blue', bold=True) + \
+ self.format_profile.fmt(']') + ':' + \
+ p.fmt('$PWD', fg='blue', bold=True) + '$ '
+ else:
+ prompt = '[{}@{}]:${{PWD}}$ '.format(key, element_name)
+
+ return element._shell(scope, directory, isolate=isolate, prompt=prompt, command=command)
+
def tick(self, elapsed):
self.maybe_render_status()