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
|
program driver
use appgraphics
use appgraphics_filo
use filo
implicit none
type(apEditorConfig)::E
integer::mywindow
integer::key, delta, rowoff
logical::cursor_moved
mywindow = initwindow(640, 480, dbflag=.true., closeflag=.true.)
call settextstyle(MONOSPACE_FONT, HORIZ_DIR, 20)
call setfillstyle(SOLID_FILL, WHITE)
E = initApEditor(mywindow)
if(.not. editorOpen(E, "kilo.c")) then
Print *, "Error opening file..."
stop
end if
call drawApEditor(E)
call swapbuffers()
do while(.true.)
call startidle(50)
do while(kbhit())
cursor_moved = .false.
rowoff = E%rowoff
key = getch()
! Special character
if(key == 0) then
key = getch()
delta = 0
select case(key)
case(KEY_UP)
E%cy = max(E%cy - 1, 1)
cursor_moved = .true.
case(KEY_DOWN)
E%cy = min(E%cy + 1, E%screenrows)
cursor_moved = .true.
case(KEY_LEFT)
E%cx = E%cx - 1
if(E%cx < 0) then
E%cx = 0
E%coloff = min(E%coloff + 1, 0)
end if
cursor_moved = .true.
case(KEY_RIGHT)
E%cx = E%cx + 1
Print *, E%cx, E%cy, E%rowoff, E%coloff
if(E%cx > E%screencols) then
E%coloff = E%coloff - 1
E%cx = E%cx - 1
end if
cursor_moved = .true.
case(KEY_PGUP)
delta = -1*E%screenrows
case(KEY_PGDN)
delta = E%screenrows
end select
rowoff = rowoff + delta
rowoff = max(rowoff, 0)
rowoff = min(rowoff, E%numrows - E%screenrows)
else
select case(key)
case(8) ! Backspace
call editorDelChar(E)
case default
call editorInsertChar(E, char(key))
end select
cursor_moved = .TRUE.
end if
if(rowoff /= E%rowoff .or. cursor_moved) then
e%rowoff = rowoff
call drawApEditor(E)
call swapbuffers()
end if
end do
end do
end program driver
|