setterm: tell user when options does not effect

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
Sami Kerola 2014-05-18 13:40:11 +01:00
parent 16279cc2b4
commit da27df2553
1 changed files with 45 additions and 38 deletions

View File

@ -779,6 +779,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;
@ -799,49 +810,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
@ -850,7 +857,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"));
@ -863,7 +870,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"));
@ -876,7 +883,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"));
@ -889,7 +896,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"));
@ -900,16 +907,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)
@ -921,8 +928,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)
@ -933,8 +940,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);
@ -944,7 +951,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) {
@ -984,7 +991,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
@ -995,7 +1002,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);
@ -1004,12 +1011,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);
}
}