aboutsummaryrefslogtreecommitdiff
path: root/pkg/utilities/nttools/tedit/display/screen/pssetcur.x
blob: a6954da38a42b1d314128c43a4656b48397cc4d3 (plain) (blame)
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
define	ABSOLUTE	YES	# disable relative cursor motion if YES

# PS_SETCUR -- Set the cursor position
#
# B.Simon	19-Jan-89	Original
# B.Simon	19-Dec-90	Rewritten to speed cursor motion
# B.Simon	10-Apr-91	Add switch to disable relative motion

procedure ps_setcur (row, col)

int	row		# i: Cursor row
int	col		# i: Cursor column
#--
include "screen.com"

bool	moved
int	newrow, newcol, dr, dc

bool	ttygetb()

begin
	newrow = min (lines, max (1, row))
	newcol = min (cols, max (1, col))

	moved = true
	dr = newrow - currow
	dc = newcol - curcol

	if (ABSOLUTE == YES) {
	    if (dr != 0 || dc != 0)
		moved = false

	} else if (dr == 0) {
	    if (dc == 0) { # no move
		return

	    } else if (dc == 1) { # move right by one
		if (ttygetb (term, "nd"))
		    call ps_sendcap ("nd", 1)
		else
		    moved = false

	    } else if (dc == -1) { # move left by one
		if (ttygetb (term, "le"))
		    call ps_sendcap ("le", 1)
		else
		    moved = false

	    } else {
		moved = false
	    }

	} else if (dr == 1) {
	    if (dc == 0) { # move down by one
		if (ttygetb (term, "do"))
		    call ps_sendcap ("do", 1)
		else
		    moved = false

	    } else {
		moved = false
	    }

	} else if (dr == -1) {
	    if (dc == 0) { # move up by one
		if (ttygetb (term, "up"))
		    call ps_sendcap ("up", 1)
		else
		    moved = false
	    } else {
		moved = false
	    }

	} else {
	    moved = false
	}

	if (! moved) # must use absolute move
	    call ttygoto (ttyout, term, newcol, newrow)

	# Update current cursor position

	currow = newrow
	curcol = newcol
end

# PS_UPDCUR -- Update the cursor position

procedure ps_updcur (row, col)

int	row		# i: New cursor row
int	col		# i: New cursor column
#--
include "screen.com"

bool	ttygetb()

begin
	if (row >= lines) {
	    currow = lines 
	} else {
	    currow = row
	}

	if (col >= cols) {
	    if (ttygetb (term, "am")) {
		currow = min (row + 1, lines)
		curcol = 1
	    } else {
		curcol = cols
	    }

	} else {
	   curcol = col
	}

end