From patchwork Sat Dec 8 20:26:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi salminen X-Patchwork-Id: 10719739 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5719B15A6 for ; Sat, 8 Dec 2018 20:26:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 42FF629E99 for ; Sat, 8 Dec 2018 20:26:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 35BD329FFF; Sat, 8 Dec 2018 20:26:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B253C29E99 for ; Sat, 8 Dec 2018 20:26:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726194AbeLHU0s (ORCPT ); Sat, 8 Dec 2018 15:26:48 -0500 Received: from mail-lf1-f66.google.com ([209.85.167.66]:45640 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726192AbeLHU0r (ORCPT ); Sat, 8 Dec 2018 15:26:47 -0500 Received: by mail-lf1-f66.google.com with SMTP id b20so5341840lfa.12 for ; Sat, 08 Dec 2018 12:26:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:subject:message-id:mime-version:content-disposition :user-agent; bh=DT6MQsSmixr+QulvihBe258I0h91Y8+NWNpeEPrY0tk=; b=aIA6kQa6l45luSWxGtS0sBZyazsEtyeNOrL0iGzgB9moF3mGLdZmVdCVxmmp2DkKNh +CpdsYBpLeIDzHT5UnnbOiUuNICsjIbeX3nMjeodd4wRtti6Q/xg0Q5QWpNHffezAdWe xghcg2T/PE6mbnyOF8MtmlvLSEmertyez4tMsEX18RO4JnQ+lORwzTo6yJrZnljm3CkI JsLOuOeTG4E8Y8W8HrYR+yWv5nqZ6sRzlc22Epo1maj3CEQ/8u/dKzK5owu1QuOQTFUi 1fcXHF+xhs8hsp8E+VpQ8Q40GFLtLoOjqNsxCoEADZdnEQZHvRCb0ZyfayGuMBOfNtDx Ns5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:mime-version :content-disposition:user-agent; bh=DT6MQsSmixr+QulvihBe258I0h91Y8+NWNpeEPrY0tk=; b=iNA5N645qWEJkaW0Sr3imWNfAek2F3GBGnW4jIgLRv6kFrmT5uvC4zW+vSs54Ytc64 VfteQYwZlxiEIkogdXYJGDWG56rToWto7gBSuZM2x08zJvo4SbROrjwgiUTfdsBGdxXe JbU0uynsF1ZCyuEdgDQNZKsKQ8n/vNzZdtSOpM49kZhDJBIpO2diOhL50UxCuV7m1GzD hAa+S0tAq3GpnJJsCnHuPLYi/ZtIjVWgvEJBrrpGus65tgjbcpGECUad/RnDGIMN3Rcp cgOugdF4FhtyF5xQzMSTQKFQdF29zGjxjk8zijFuS7ogPMe86tFTaKkTXHtQIt76iUIx rXVA== X-Gm-Message-State: AA+aEWZ0pJz1sI2lyNex2SV4FDnD/tn/syBLCiz+TKkAqx6iCYChYTN0 heh+lqLMKEvi4wNidIK80lTBJTQUi4U= X-Google-Smtp-Source: AFSGD/WsLIlGfklxczDOHVvMTBVVFrJHPqHv1hQaLZzr+aD0Zd/C+XfeSturf51ruLoFpQjgk6/IWw== X-Received: by 2002:a19:d90c:: with SMTP id q12mr3702412lfg.24.1544300803758; Sat, 08 Dec 2018 12:26:43 -0800 (PST) Received: from turska (dtb2smtyyyyyyyyyyyyyt-3.rev.dnainternet.fi. [2001:14ba:806c:f540::1]) by smtp.gmail.com with ESMTPSA id g17sm1349472lfj.36.2018.12.08.12.26.42 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 08 Dec 2018 12:26:42 -0800 (PST) Date: Sat, 8 Dec 2018 22:26:40 +0200 From: Tomi Salminen To: linux-kbuild@vger.kernel.org Subject: [PATCH 001/123] kconfig/conf.c: Added optional colorization of output. Message-ID: <20181208202640.GA28712@turska> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.11.0 (2018-11-25) Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Tomi Salminen Added option COLORIZE=1 for oldconfig, coloring the tristate options to yes=green, no=red, module=blue and boolean variables to true=green, false=red. Signed-off-by: Tomi Salminen --- scripts/kconfig/Makefile | 9 +++++++- scripts/kconfig/conf.c | 45 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/scripts/kconfig/Makefile b/scripts/kconfig/Makefile index 63b609243d03..22cc1257f8a4 100644 --- a/scripts/kconfig/Makefile +++ b/scripts/kconfig/Makefile @@ -56,6 +56,11 @@ localyesconfig localmodconfig: $(obj)/conf fi $(Q)rm -f .tmp.config + +MAYBECOLORIZE= +ifeq ($(COLORIZE),1) + MAYBECOLORIZE="-c" +endif # These targets map 1:1 to the commandline options of 'conf' # # Note: @@ -66,7 +71,7 @@ simple-targets := oldconfig allnoconfig allyesconfig allmodconfig \ PHONY += $(simple-targets) $(simple-targets): $(obj)/conf - $< $(silent) --$@ $(Kconfig) + $< $(silent) $(MAYBECOLORIZE) --$@ $(Kconfig) PHONY += savedefconfig defconfig @@ -140,6 +145,8 @@ help: @echo ' xenconfig - Enable additional options for xen dom0 and guest kernel support' @echo ' tinyconfig - Configure the tiniest possible kernel' @echo ' testconfig - Run Kconfig unit tests (requires python3 and pytest)' + @echo 'Options for targets:' + @echo ' COLORIZE=1 - Colorize option output (no=red, green=yes, blue=mod)' # =========================================================================== # Shared Makefile for the various kconfig executables: diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c index 98e0c7a34699..6253a473292b 100644 --- a/scripts/kconfig/conf.c +++ b/scripts/kconfig/conf.c @@ -42,6 +42,7 @@ static int sync_kconfig; static int conf_cnt; static char line[PATH_MAX]; static struct menu *rootEntry; +static int colorize; // Colorizes output lines according to option default. static void print_help(struct menu *menu) { @@ -53,6 +54,40 @@ static void print_help(struct menu *menu) str_free(&help); } +static void colorize_reset(void) +{ + if (colorize) { + const char *reset = "\x1B[37m"; + + printf("%s", reset); + } +} + +static void colorize_line(struct symbol *sym) +{ + if (colorize) { + enum symbol_type type = sym_get_type(sym); + const char *red = "\x1B[31m", *green = "\x1B[32m", *blue = + "\x1B[34m"; + + if (type == S_BOOLEAN || type == S_TRISTATE) { + switch (sym_get_tristate_value(sym)) { + { + case no: + printf("%s", red); + break; + case yes: + printf("%s", green); + break; + case mod: + printf("%s", blue); + break; + } + } + } + } +} + static void strip(char *str) { char *p = str; @@ -166,6 +201,7 @@ static int conf_sym(struct menu *menu) while (1) { printf("%*s%s ", indent - 1, "", menu->prompt->text); + colorize_line(sym); if (sym->name) printf("(%s) ", sym->name); putchar('['); @@ -188,6 +224,7 @@ static int conf_sym(struct menu *menu) if (oldval != yes && sym_tristate_within_range(sym, yes)) printf("/y"); printf("/?] "); + colorize_reset(); if (!conf_askvalue(sym, sym_get_string_value(sym))) return 0; strip(line); @@ -466,7 +503,7 @@ static struct option long_opts[] = { static void conf_usage(const char *progname) { - printf("Usage: %s [-s] [option] \n", progname); + printf("Usage: %s [-s] [-c] [option] \n", progname); printf("[option] is _one_ of the following:\n"); printf(" --listnewconfig List new options\n"); printf(" --oldaskconfig Start a new configuration using a line-oriented program\n"); @@ -481,6 +518,8 @@ static void conf_usage(const char *progname) printf(" --allmodconfig New config where all options are answered with mod\n"); printf(" --alldefconfig New config with all symbols set to default\n"); printf(" --randconfig New config with random answer to all options\n"); + printf("Modifiers:\n"); + printf(" -c Output colorized lines for default option.\n"); } int main(int ac, char **av) @@ -493,10 +532,12 @@ int main(int ac, char **av) tty_stdio = isatty(0) && isatty(1); - while ((opt = getopt_long(ac, av, "s", long_opts, NULL)) != -1) { + while ((opt = getopt_long(ac, av, "sc", long_opts, NULL)) != -1) { if (opt == 's') { conf_set_message_callback(NULL); continue; + } else if (opt == 'c') { + colorize = 1; } input_mode = (enum input_mode)opt; switch (opt) {