File: less-pipe

package info (click to toggle)
epic5 2.0.1-1
  • links: PTS
  • area: main
  • in suites: buster, sid, stretch
  • size: 4,696 kB
  • ctags: 6,357
  • sloc: ansic: 69,814; makefile: 715; ruby: 227; sh: 178; perl: 13
file content (70 lines) | stat: -rw-r--r-- 1,129 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
if (word(2 $loadinfo()) != [pf]) { load -pf $word(1 $loadinfo()); return; };

#
# Open up a pipe and then page the output.
# I wrote this in a race with Archon (hop, 1997)
#

#
# Usage: 
#  $0  - name of the pipe
#  $1- - stuff to run
#
alias less_pipe
{
	@ line = 0;

	if ([$1])
	{
		^on ^exec "$0 *" {
			@ lessline[$line] = [$1-];
			@ line++;
		};
		^on ^exec_error "$0 *" {
			echo *** Error on exec: $*;
		};
		^on ^exec_exit "$0 *" {
			on exec -"$0 *";
			on exec_error -"$0 *";
			on exec_exit -"$0 *";
			less_array lessline 0 $line;
		};
		exec -name $*;
	};
};

: {/*
 * $0 is the array name to use
 * $1 is the starting line
 * $2 is the final line
 */}
alias less_array
{
	local line $1;
	local cr 0;
	local rows $winsize();

	while ((line < [$2]) && (cr < rows))
	{
		echo $($0[$line]);
		assign -$0[$line];
		@ line++, cr++;
	};

	if (cr >= rows)
	{
		@ aaa.array_name = [$0];
		@ aaa.next_line = line;
		@ aaa.final_line = [$2];

		input_char "Enter q to quit, or anything else to continue "
		{
			if ([$0] != [q])
			{
				^less_array $aaa.array_name $aaa.next_line $aaa.final_line;
			};
		};
	};
};

#hop'97