public inbox for util-linux@vger.kernel.org
 help / color / mirror / Atom feed
From: Sami Kerola <kerolasa@iki.fi>
To: util-linux@vger.kernel.org
Cc: kerolasa@iki.fi
Subject: [PATCH 13/17] setterm: tell user when options does not effect
Date: Sun, 18 May 2014 15:05:37 +0100	[thread overview]
Message-ID: <1400421941-14244-14-git-send-email-kerolasa@iki.fi> (raw)
In-Reply-To: <1400421941-14244-1-git-send-email-kerolasa@iki.fi>

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 term-utils/setterm.c | 83 ++++++++++++++++++++++++++++------------------------
 1 file changed, 45 insertions(+), 38 deletions(-)

diff --git a/term-utils/setterm.c b/term-utils/setterm.c
index f1ed862..2a0162e 100644
--- a/term-utils/setterm.c
+++ b/term-utils/setterm.c
@@ -792,6 +792,17 @@ static void screendump(struct setterm_control *ctl)
 	return;
 }
 
+/* Some options are applicable when terminal is virtual console. */
+static int vc_only(struct setterm_control *ctl, const char *err)
+{
+	if (!ctl->vcterm) {
+		if (err)
+			warnx(_("terminal %s does not support %s"),
+			      ctl->opt_te_terminal_name, err);
+	}
+	return ctl->vcterm;
+}
+
 static void perform_sequence(struct setterm_control *ctl)
 {
 	int result;
@@ -812,49 +823,45 @@ static void perform_sequence(struct setterm_control *ctl)
 			putp(ti_entry("civis"));
 	}
 
-	/* -linewrap [on|off]. Vc only (vt102) */
-	if (ctl->opt_linewrap && ctl->vcterm)
+	/* -linewrap [on|off]. */
+	if (ctl->opt_linewrap && vc_only(ctl, "-linewrap"))
 		fputs(ctl->opt_li_on ? "\033[?7h" : "\033[?7l", stdout);
 
-	/* -repeat [on|off]. Vc only (vt102) */
-	if (ctl->opt_repeat && ctl->vcterm)
+	/* -repeat [on|off]. */
+	if (ctl->opt_repeat && vc_only(ctl, "-repeat"))
 		fputs(ctl->opt_rep_on ? "\033[?8h" : "\033[?8l", stdout);
 
-	/* -appcursorkeys [on|off]. Vc only (vt102) */
-	if (ctl->opt_appcursorkeys && ctl->vcterm)
+	/* -appcursorkeys [on|off]. */
+	if (ctl->opt_appcursorkeys && vc_only(ctl, "-appcursorkeys"))
 		fputs(ctl->opt_appck_on ? "\033[?1h" : "\033[?1l", stdout);
 
 	/* -default.  Vc sets default rendition, otherwise clears all
 	 * attributes. */
 	if (ctl->opt_default) {
-		if (ctl->vcterm)
+		if (vc_only(ctl, NULL))
 			printf("\033[0m");
 		else
 			putp(ti_entry("sgr0"));
 	}
 
-	/* -foreground black|red|green|yellow|blue|magenta|cyan|white|default.
-	 * Vc only (ANSI). */
-	if (ctl->opt_foreground && ctl->vcterm)
+	/* -foreground black|red|green|yellow|blue|magenta|cyan|white|default. */
+	if (ctl->opt_foreground && vc_only(ctl, "-foreground"))
 		printf("\033[3%c%s", '0' + ctl->opt_fo_color, "m");
 
-	/* -background black|red|green|yellow|blue|magenta|cyan|white|default.
-	 * Vc only (ANSI). */
-	if (ctl->opt_background && ctl->vcterm)
+	/* -background black|red|green|yellow|blue|magenta|cyan|white|default. */
+	if (ctl->opt_background && vc_only(ctl, "-background"))
 		printf("\033[4%c%s", '0' + ctl->opt_ba_color, "m");
 
-	/* -ulcolor black|red|green|yellow|blue|magenta|cyan|white|default.
-	 * Vc only. */
-	if (ctl->opt_ulcolor && ctl->vcterm)
+	/* -ulcolor black|red|green|yellow|blue|magenta|cyan|white|default. */
+	if (ctl->opt_ulcolor && vc_only(ctl, "-ulcolor"))
 		printf("\033[1;%d]", ctl->opt_ul_color);
 
-	/* -hbcolor black|red|green|yellow|blue|magenta|cyan|white|default.
-	 * Vc only. */
-	if (ctl->opt_hbcolor && ctl->vcterm)
+	/* -hbcolor black|red|green|yellow|blue|magenta|cyan|white|default. */
+	if (ctl->opt_hbcolor && vc_only(ctl, "-hbcolor"))
 		printf("\033[2;%d]", ctl->opt_hb_color);
 
-	/* -inversescreen [on|off].  Vc only (vt102). */
-	if (ctl->opt_inversescreen && ctl->vcterm)
+	/* -inversescreen [on|off]. */
+	if (ctl->opt_inversescreen && vc_only(ctl, "-inversescreen"))
 		fputs(ctl->opt_invsc_on ? "\033[?5h" : "\033[?5l", stdout);
 
 	/* -bold [on|off].  Vc behaves as expected, otherwise off turns off
@@ -863,7 +870,7 @@ static void perform_sequence(struct setterm_control *ctl)
 		if (ctl->opt_bo_on)
 			putp(ti_entry("bold"));
 		else {
-			if (ctl->vcterm)
+			if (vc_only(ctl, NULL))
 				fputs("\033[22m", stdout);
 			else
 				putp(ti_entry("sgr0"));
@@ -876,7 +883,7 @@ static void perform_sequence(struct setterm_control *ctl)
 		if (ctl->opt_hb_on)
 			putp(ti_entry("dim"));
 		else {
-			if (ctl->vcterm)
+			if (vc_only(ctl, NULL))
 				fputs("\033[22m", stdout);
 			else
 				putp(ti_entry("sgr0"));
@@ -889,7 +896,7 @@ static void perform_sequence(struct setterm_control *ctl)
 		if (ctl->opt_bl_on)
 			putp(ti_entry("blink"));
 		else {
-			if (ctl->vcterm)
+			if (vc_only(ctl, NULL))
 				fputs("\033[25m", stdout);
 			else
 				putp(ti_entry("sgr0"));
@@ -902,7 +909,7 @@ static void perform_sequence(struct setterm_control *ctl)
 		if (ctl->opt_re_on)
 			putp(ti_entry("rev"));
 		else {
-			if (ctl->vcterm)
+			if (vc_only(ctl, NULL))
 				fputs("\033[27m", stdout);
 			else
 				putp(ti_entry("sgr0"));
@@ -913,16 +920,16 @@ static void perform_sequence(struct setterm_control *ctl)
 	if (ctl->opt_underline)
 		putp(ti_entry(ctl->opt_un_on ? "smul" : "rmul"));
 
-	/* -store.  Vc only. */
-	if (ctl->opt_store && ctl->vcterm)
+	/* -store. */
+	if (ctl->opt_store && vc_only(ctl, "-store"))
 		fputs("\033[8]", stdout);
 
 	/* -clear [all|rest]. */
 	if (ctl->opt_clear)
 		putp(ti_entry(ctl->opt_cl_all ? "clear" : "ed"));
 
-	/* -tabs Vc only. */
-	if (ctl->opt_tabs && ctl->vcterm) {
+	/* -tabs. */
+	if (ctl->opt_tabs && vc_only(ctl, "-tabs")) {
 		int i;
 
 		if (ctl->opt_tb_array[0] == -1)
@@ -934,8 +941,8 @@ static void perform_sequence(struct setterm_control *ctl)
 		}
 	}
 
-	/* -clrtabs Vc only. */
-	if (ctl->opt_clrtabs && ctl->vcterm) {
+	/* -clrtabs. */
+	if (ctl->opt_clrtabs && vc_only(ctl, "-clrtabs")) {
 		int i;
 
 		if (ctl->opt_tb_array[0] == -1)
@@ -946,8 +953,8 @@ static void perform_sequence(struct setterm_control *ctl)
 		putchar('\r');
 	}
 
-	/* -regtabs Vc only. */
-	if (ctl->opt_regtabs && ctl->vcterm) {
+	/* -regtabs. */
+	if (ctl->opt_regtabs && vc_only(ctl, "-regtabs")) {
 		int i;
 
 		fputs("\033[3g\r", stdout);
@@ -957,7 +964,7 @@ static void perform_sequence(struct setterm_control *ctl)
 	}
 
 	/* -blank [0-60]. */
-	if (ctl->opt_blank && ctl->vcterm) {
+	if (ctl->opt_blank && vc_only(ctl, "-blank")) {
 		if (ctl->opt_bl_min >= 0)
 			printf("\033[9;%d]", ctl->opt_bl_min);
 		else if (ctl->opt_bl_min == BLANKSCREEN) {
@@ -997,7 +1004,7 @@ static void perform_sequence(struct setterm_control *ctl)
 		screendump(ctl);
 
 	/* -msg [on|off].  Controls printk's to console. */
-	if (ctl->opt_msg && ctl->vcterm) {
+	if (ctl->opt_msg && vc_only(ctl, "-msg")) {
 		if (ctl->opt_msg_on)
 			result = klogctl(SYSLOG_ACTION_CONSOLE_ON, NULL, 0);
 		else
@@ -1008,7 +1015,7 @@ static void perform_sequence(struct setterm_control *ctl)
 	}
 
 	/* -msglevel [0-8].  Console printk message level. */
-	if (ctl->opt_msglevel_num && ctl->vcterm) {
+	if (ctl->opt_msglevel_num && vc_only(ctl, "-msglevel")) {
 		result =
 		    klogctl(SYSLOG_ACTION_CONSOLE_LEVEL, NULL,
 			    ctl->opt_msglevel_num);
@@ -1017,12 +1024,12 @@ static void perform_sequence(struct setterm_control *ctl)
 	}
 
 	/* -blength [0-2000] */
-	if (ctl->opt_blength && ctl->vcterm) {
+	if (ctl->opt_blength && vc_only(ctl, "-blength")) {
 		printf("\033[11;%d]", ctl->opt_blength_l);
 	}
 
 	/* -bfreq freqnumber */
-	if (ctl->opt_bfreq && ctl->vcterm) {
+	if (ctl->opt_bfreq && vc_only(ctl, "-bfreq")) {
 		printf("\033[10;%d]", ctl->opt_bfreq_f);
 	}
 }
-- 
1.9.2


  parent reply	other threads:[~2014-05-18 14:06 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-18 14:05 [PATCH 00/17] pull: almost complete setterm refactoring Sami Kerola
2014-05-18 14:05 ` [PATCH 01/17] setterm: clean up includes Sami Kerola
2014-05-18 14:05 ` [PATCH 02/17] setterm: use getopt_long_only() for option parsing Sami Kerola
2014-05-19  9:29   ` Karel Zak
2014-05-18 14:05 ` [PATCH 03/17] setterm: use string utils to numeric parsing Sami Kerola
2014-05-19  9:24   ` Karel Zak
2014-05-18 14:05 ` [PATCH 04/17] setterm: move show_tabs() and screendump() functions Sami Kerola
2014-05-18 14:05 ` [PATCH 05/17] setterm: remove usage comment segment Sami Kerola
2014-05-18 14:05 ` [PATCH 06/17] setterm: add option control structure Sami Kerola
2014-05-19  9:38   ` Karel Zak
2014-05-19  9:48   ` Karel Zak
2014-05-18 14:05 ` [PATCH 07/17] setterm: add init_terminal() to make main() shorter Sami Kerola
2014-05-18 14:05 ` [PATCH 08/17] setterm: clean up screendump() Sami Kerola
2014-05-18 14:05 ` [PATCH 09/17] setterm: remove devfs and /dev/vcsa0 support Sami Kerola
2014-05-19  9:52   ` Karel Zak
2014-05-18 14:05 ` [PATCH 10/17] setterm: make -msglevel 0 to work as is did earlier Sami Kerola
2014-05-18 14:05 ` [PATCH 11/17] setterm: correct usage() bright color argument Sami Kerola
2014-05-19  9:57   ` Karel Zak
2014-05-18 14:05 ` [PATCH 12/17] setterm: improve perform_sequence() coding style Sami Kerola
2014-05-18 14:05 ` Sami Kerola [this message]
2014-05-19 10:02   ` [PATCH 13/17] setterm: tell user when options does not effect Karel Zak
2014-05-18 14:05 ` [PATCH 14/17] setterm: improve error messages Sami Kerola
2014-05-18 14:05 ` [PATCH 15/17] setterm: various visual terminal effects are not console specific Sami Kerola
2014-05-18 14:05 ` [PATCH 16/17] setterm: mark some options to be exclusive with each other Sami Kerola
2014-05-18 14:05 ` [PATCH 17/17] setterm: add set_blanking() action Sami Kerola
2014-05-19 21:51 ` [PATCH 00/17] pull: almost complete setterm refactoring Sami Kerola
2014-05-20  8:11   ` Benno Schulenberg
2014-05-20 10:02     ` Karel Zak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1400421941-14244-14-git-send-email-kerolasa@iki.fi \
    --to=kerolasa@iki.fi \
    --cc=util-linux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox