From 51dbcbb2a0793ff72b3557b1b300270a03b69f80 Mon Sep 17 00:00:00 2001 From: Thomas Adam Date: Thu, 14 Jun 2018 09:53:07 +0100 Subject: [PATCH] prompt: display context if one is present The documentation for tasksh currently says that the tasksh prompt will display the context if there is one. This adds the context to the prompt. Fixes GH issue #37 --- src/prompt.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/prompt.cpp b/src/prompt.cpp index c368ebe..e16c488 100644 --- a/src/prompt.cpp +++ b/src/prompt.cpp @@ -28,6 +28,8 @@ #include #include #include +#include +#include static std::vector contextColors = { "bold white on red", @@ -93,11 +95,22 @@ std::string promptCompose () // TODO - The accumulated context, as colored tokens. // TODO - sync status // TODO - time + std::string prompt = "tasksh"; auto decoration = composeContexts (true); if (decoration.length ()) return "task " + decoration + "> "; - return "tasksh> "; + // For now, display the context (if any). + std::string dummy;; + std::string output; + execute ("task", {"_get", "rc.context"}, dummy, output); + output = Lexer::trimRight (output, "\n"); + + if (output != "") + prompt += " (" + output + ")"; + prompt += "> "; + + return prompt; } ////////////////////////////////////////////////////////////////////////////////