-
Notifications
You must be signed in to change notification settings - Fork 1
/
interfaces.ts
172 lines (144 loc) · 3.21 KB
/
interfaces.ts
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
171
172
import { defaultCommands } from './commands';
import { defaultKeybindings } from './keybindings';
/**
* Defaults that a new Unixorn component will
* be initialized with if its props are not set.
*/
export const defaultConfiguration: UnixornConfiguration = {
autoFocus: false,
commands: defaultCommands,
keybindings: defaultKeybindings,
prompt: '> ',
startupMessage: 'Welcome to Unixorn. Enter `help` for basic information.',
};
/**
* The props of a Unixorn component.
*/
export interface UnixornConfiguration {
/**
* Whether the component should take focus when the page loads.
*/
autoFocus?: boolean;
/**
* List of commands to use instead of the default commands.
*/
commands?: UnixornCommand[];
/**
* List of keybindings to use instead of the default keybindings.
*/
keybindings?: UnixornKeybinding[];
/**
* The string to use instead of the default prompt.
*/
prompt?: string;
/**
* The message to show when Unixorn starts.
*/
startupMessage?: string;
}
/**
* A command that can be run on the command line.
*/
export interface UnixornCommand {
/**
* The name of the command.
*/
name: string;
/**
* A string that demonstrates how the command is used.
*/
usage: string;
/**
* A brief description of the purpose of the command.
*/
summary: string;
/**
* The actual code of the command.
*/
action: (kernel: UnixornKernel, tokens: string[]) => void;
}
/**
* A keybinding that can be triggered on the command line.
*/
export interface UnixornKeybinding {
/**
* Whether the control key should be held.
*/
ctrl: boolean;
/**
* Whether the meta key should be held.
* On a standard keyboard, the meta key is marked "alt".
*/
meta: boolean;
/**
* The non-modifier key of the keybinding.
*/
key: string;
/**
* A brief description of the purpose of the keybinding.
*/
summary: string;
/**
* The actual code of the keybinding.
*/
action: (kernel: UnixornKernel) => void;
}
/**
* The set of Unixorn system calls.
*/
export interface UnixornKernel {
/**
* Clear input and output that has been rendered to screen.
*/
clearScreen: () => void;
/**
* Get the list of available commands.
*/
commands: () => UnixornCommand[];
/**
* Delete all characters after cursor.
*/
deleteToEnd: () => void;
/**
* Delete all characters before cursor.
*/
deleteToStart: () => void;
/**
* Execute a statement.
*/
execute: (stmt: string[]) => void;
/**
* Get the list of available keybindings.
*/
keybindings: () => UnixornKeybinding[];
/**
* Move the cursor to the end of the line.
*/
moveCursorToEnd: () => void;
/**
* Move the cursor to the start of the line.
*/
moveCursorToStart: () => void;
/**
* Split a list of tokens into a
* list of statements.
*/
parse: (tokens: string[]) => string[][];
/**
* Print text to stderr.
*/
printErr: (text: string) => void;
/**
* Print text to stdout.
*/
printOut: (text: string) => void;
/**
* Split the text of a program into a
* list of tokens.
*/
tokenize: (programText: string) => string[];
/**
* Visit a URL.
*/
visit: (url: string) => void;
}