summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpgen <p.gen.progs@gmail.com>2019-01-07 21:29:29 +0100
committerpgen <p.gen.progs@gmail.com>2019-01-20 10:49:47 +0100
commit9df4a51a034b7ffa01f0a5dc0b859ed886cd6d54 (patch)
tree4966bb77e69bdecd64fbf8f0255242a39ec17c31
parent2e47a6cec4c9c950a3fcf4e7f5c7a6a17af168b4 (diff)
Make the argument of -n optional, 0 by default
-rw-r--r--smenu.115
-rw-r--r--smenu.c19
-rw-r--r--tests/window_height/data122
-rw-r--r--tests/window_height/t0001.good43
l---------tests/window_height/t0001.in1
-rw-r--r--tests/window_height/t0001.tst4
-rw-r--r--tests/window_height/t0002.good23
l---------tests/window_height/t0002.in1
-rw-r--r--tests/window_height/t0002.tst4
-rw-r--r--tests/window_height/t0003.good19
l---------tests/window_height/t0003.in1
-rw-r--r--tests/window_height/t0003.tst4
12 files changed, 142 insertions, 14 deletions
diff --git a/smenu.1 b/smenu.1
index db3dfda..03b4ddf 100644
--- a/smenu.1
+++ b/smenu.1
@@ -5,7 +5,7 @@ and outputs the selection to stdout.
.SH SYNOPSIS
.nf
\f(CRsmenu [\fB-h\fP|\fB-?\fP] [\fB-f\fP \fIconfiguration_file\fP] \\
- [\fB-n\fP \fIlines\fP] [\fB-t\fP [\fIcols\fP]] [\fB-k\fP] \\
+ [\fB-n\fP [\fIlines\fP]] [\fB-t\fP [\fIcols\fP]] [\fB-k\fP] \\
[\fB-s\fP \fIpattern\fP] [\fB-m\fP \fImessage\fP] [\fB-w\fP] \\
[\fB-d\fP] [\fB-M\fP] [\fB-c\fP] [\fB-l\fP] [\fB-r\fP] [\fB-b\fP] \\
[\fB-a\fP (i|e|c|b|s|t|ct|sf|st|mf|mt|sfe|ste|mfe|mte|da):\fIATTR\fP]... \\
@@ -469,14 +469,17 @@ default values will be used.
The \fB.smenu\fP files in the user's home directory and in the current
directory, if present, will be ignored when this option is used.
-.IP "\fB-n\fP \fIlines\fB"
+.IP "\fB-n\fP \fI[lines\fB]"
Gives the maximum number of lines in the scrolling selection window.
-By default five lines at most are displayed and the other ones, if
-any, need you to scroll the window.
-The special value \fI0\fP sets this number to match the number of lines
-in the terminal (minus the lines taken by the message if any).
+If \fB-n\fP is not present the number of lines will be set to \fI5\fP.
+
+If \fB-n\fP is present without argument, then the height of the terminal will
+be used to determine the number of lines.
This remains true even if the terminal is resized.
+
+If \fB-n\fP is present with a numerical argument, this value will be used
+to determine the number of lines.
.IP "\fB-t\fP [\fIcolumns\fP]"
This option sets the tabulation mode and, if a number is specified,
attents to set the number of displayed columns to that number.
diff --git a/smenu.c b/smenu.c
index f9ada7b..5672b3d 100644
--- a/smenu.c
+++ b/smenu.c
@@ -142,8 +142,8 @@ int quiet_timeout = 0; /* 1 when we want no message to be displayed. */
void
short_usage(void)
{
- fprintf(stderr, "Usage: smenu [-h|-?] [-f config_file] [-n lines] ");
- fprintf(stderr, "[-t [cols]] [-k] [-v] \\\n");
+ fprintf(stderr, "Usage: smenu [-h|-?] [-f config_file] [-n [lines]] ");
+ fprintf(stderr, "[-t [cols]] [-k] [-v] \\\n");
fprintf(stderr, " [-s pattern] [-m message] [-w] [-d] [-M] [-c] [-l] ");
fprintf(stderr, "[-r] [-b] \\\n");
fprintf(stderr, " [-a prefix:attr [prefix:attr]...] ");
@@ -5131,7 +5131,7 @@ main(int argc, char * argv[])
/* """"""""""""""""""""""""""""" */
while ((opt = egetopt(argc, argv,
"Vf:h?X:x:qdMba:i:e:S:I:E:A:Z:1:2:3:4:5:C:R:"
- "kvclwrg%n:t%m:s:W:L:T%P%pN%U%FD:/:"))
+ "kvclwrg%n%t%m:s:W:L:T%P%pN%U%FD:/:"))
!= -1)
{
switch (opt)
@@ -5151,13 +5151,16 @@ main(int argc, char * argv[])
break;
case 'n':
- if (eoptarg && *eoptarg != '-')
- win.asked_max_lines = abs(atoi(eoptarg));
- else
+ if (eoptarg != NULL)
{
- TELL("Option requires an argument -- ");
- short_usage();
+ if (sscanf(eoptarg, "%ld", &(win.asked_max_lines)) != 1)
+ {
+ TELL("Argument must be numeric -- ");
+ short_usage();
+ }
}
+ else
+ win.asked_max_lines = 0;
break;
case 'd':
diff --git a/tests/window_height/data1 b/tests/window_height/data1
new file mode 100644
index 0000000..64cdb22
--- /dev/null
+++ b/tests/window_height/data1
@@ -0,0 +1,22 @@
+1
+2
+3
+4
+5
+6
+7
+8
+9
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+20
+21
+22
diff --git a/tests/window_height/t0001.good b/tests/window_height/t0001.good
new file mode 100644
index 0000000..fffc9d2
--- /dev/null
+++ b/tests/window_height/t0001.good
@@ -0,0 +1,43 @@
+5
+
+6
+
+7
+
+8
+
+9
+
+10
+
+11
+
+12
+
+13
+
+14
+
+15
+
+16
+
+17
+
+18
+
+19
+
+20
+
+21
+
+22
+
+$
+
+$ echo ":$OUT:"
+
+:1:
+
+$ exit 0
diff --git a/tests/window_height/t0001.in b/tests/window_height/t0001.in
new file mode 120000
index 0000000..0abc8f1
--- /dev/null
+++ b/tests/window_height/t0001.in
@@ -0,0 +1 @@
+data1 \ No newline at end of file
diff --git a/tests/window_height/t0001.tst b/tests/window_height/t0001.tst
new file mode 100644
index 0000000..7a667b1
--- /dev/null
+++ b/tests/window_height/t0001.tst
@@ -0,0 +1,4 @@
+\S[150]\s[10]OUT=$(smenu -n -c t0001.in)
+\S[150]\s[150]\r
+\S[150]\s[10]echo ":$\s[10]OUT:"
+exit 0
diff --git a/tests/window_height/t0002.good b/tests/window_height/t0002.good
new file mode 100644
index 0000000..13d70b2
--- /dev/null
+++ b/tests/window_height/t0002.good
@@ -0,0 +1,23 @@
+$ OUT=$(smenu -n 7 -c t0002.in)
+
+1 ┐
+0:07 1:07 4:20
+2 ║
+4:20
+3 │
+4:20
+4 │
+4:20
+5 │
+4:20
+6 │
+4:20
+7 ▼
+4:20
+$
+
+$ echo ":$OUT:"
+
+:1:
+
+$ exit 0
diff --git a/tests/window_height/t0002.in b/tests/window_height/t0002.in
new file mode 120000
index 0000000..0abc8f1
--- /dev/null
+++ b/tests/window_height/t0002.in
@@ -0,0 +1 @@
+data1 \ No newline at end of file
diff --git a/tests/window_height/t0002.tst b/tests/window_height/t0002.tst
new file mode 100644
index 0000000..a0d692c
--- /dev/null
+++ b/tests/window_height/t0002.tst
@@ -0,0 +1,4 @@
+\S[150]\s[10]OUT=$(smenu -n 7 -c t0002.in)
+\S[150]\s[150]\r
+\S[150]\s[10]echo ":$\s[10]OUT:"
+exit 0
diff --git a/tests/window_height/t0003.good b/tests/window_height/t0003.good
new file mode 100644
index 0000000..cad9e5c
--- /dev/null
+++ b/tests/window_height/t0003.good
@@ -0,0 +1,19 @@
+$ OUT=$(smenu -c t0003.in)
+
+1 ┐
+0:07 1:07 4:20
+2 ║
+4:20
+3 │
+4:20
+4 │
+4:20
+5 ▼
+4:20
+$
+
+$ echo ":$OUT:"
+
+:1:
+
+$ exit 0
diff --git a/tests/window_height/t0003.in b/tests/window_height/t0003.in
new file mode 120000
index 0000000..0abc8f1
--- /dev/null
+++ b/tests/window_height/t0003.in
@@ -0,0 +1 @@
+data1 \ No newline at end of file
diff --git a/tests/window_height/t0003.tst b/tests/window_height/t0003.tst
new file mode 100644
index 0000000..a339a67
--- /dev/null
+++ b/tests/window_height/t0003.tst
@@ -0,0 +1,4 @@
+\S[150]\s[10]OUT=$(smenu -c t0003.in)
+\S[150]\s[150]\r
+\S[150]\s[10]echo ":$\s[10]OUT:"
+exit 0