forked from akrasuski1/akrOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib_os_data.ks
More file actions
170 lines (146 loc) · 3.31 KB
/
lib_os_data.ks
File metadata and controls
170 lines (146 loc) · 3.31 KB
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
@lazyglobal off.
// os_data is a list of:
// [0] - window tree, represented as documented in main file
// [1] - list of all windows (simple list, not tree or what not)
// [2] - list of all processes
// [3] - currently focused window's index
// [4] - if true, enable focus mechanics
// [5] - list of installed programs, where each program is a list:
// [0] - name of program
// [1] - run program function
// [2] - boolean stating whether it is system program
// (runs always in window 0)
// [6] - status bar height (internal)
// [7] - window focus tip width (external)
// [8] - current highest process id
// GET:
function get_window_tree{
parameter os_data.
return os_data[0].
}
function get_window_list{
parameter os_data.
return os_data[1].
}
function get_process_list{
parameter os_data.
return os_data[2].
}
function get_focused_window{
parameter os_data.
return os_data[3].
}
function get_showing_focused_window{
parameter os_data.
return os_data[4].
}
function get_status_height{
parameter os_data.
return os_data[6].
}
function get_status_window{
parameter os_data.
return make_rect(
0,terminal:height()-os_data[6]-3,
terminal:width()-get_focus_tip_width(os_data)+1,os_data[6]+2
).
}
function get_new_pid{
parameter os_data.
set os_data[8] to os_data[8]+1.
return os_data[8].
}
function get_focus_tip_width{
parameter os_data.
return os_data[7].
}
function get_focus_tip_window{
parameter os_data.
local w is get_focus_tip_width(os_data).
return make_rect(
terminal:width()-w,terminal:height()-os_data[6]-3,
w,os_data[6]+2
).
}
function draw_status_bar{
parameter os_data.
draw_empty_window(get_status_window(os_data)).
local tip is get_focus_tip_window(os_data).
draw_empty_window(tip).
local x is tip[0].
local y is tip[1].
print "Use 1/2" at(x+1,y+1).
print "to move" at(x+1,y+2).
print "focus. " at(x+1,y+3).
}
function new_os_data{
return list(
list(), // empty window tree
list(), // empty window list
list(), // empty processs list
0, // currently focused window
true, // show focus
list(), // empty installed programs list
3, // status bar height - hardcoded to make unified experience
9, // ag1/ag2 tip width - hardcoded too
-1 // no processes exist yet
).
}
function get_program_list{ // just names
parameter os_data.
local ret is list().
for prog in os_data[5]{
ret:add(prog[0]).
}
return ret.
}
function is_system_program{
parameter
os_data,
program_name.
for prog in os_data[5]{
if prog[0]=program_name{
return prog[2].
}
}
print "No such program: "+program_name.
local x is 1/0.
}
function make_process_from_name{
parameter
os_data,
program_name,
window_index.
for prog in os_data[5]{
if prog[0]=program_name{
global __os_data is os_data.
global __window_index is window_index.
return evaluate(prog[1]+"(__os_data,__window_index)").
}
}
print "No such program: "+program_name.
local x is 1/0.
}
// SET:
function register_program{
parameter
os_data,
program_name,
program_run_function,
is_system_program_bool.
os_data[5]:add(list(
program_name,program_run_function,is_system_program_bool
)).
}
function set_focused_window{
parameter
os_data,
foc.
set os_data[3] to foc.
}
function set_showing_focused_window{
parameter
os_data,
showing.
set os_data[4] to showing.
}