Skip to content

Commit 4162c4a

Browse files
doc readme
1 parent e3bd44c commit 4162c4a

9 files changed

Lines changed: 81 additions & 35 deletions

File tree

src/api_docs/README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# OllieOS API Documentation
2+
3+
Welcome to the OllieOS Program API documentation.
4+
5+
This document provides an overview of the APIs available to your program and their usage.
6+
7+
## Categories
8+
9+
### [Userspace API](./modules/Userspace.html)
10+
11+
All programs have access to the Userspace API, providing limited access to the kernel but allowing interaction with the system.
12+
13+
### [Kernel (Privileged) API](./modules/Kernel_(Privileged).html)
14+
15+
Programs that start privileged, or successfully [request elevation](./interfaces/Userspace.UserspaceKernel.html#request_privilege-1), have access to the Kernel API, which provides full access to the system.
16+
17+
This is a responsibility, and programs should only request elevation when absolutely necessary.
18+
19+
### [Program Types](./modules/Program_Types.html)
20+
21+
Additional information on the type assertions applied to define a program in OllieOS.
22+
23+
## Example Program
24+
25+
Here is a minimal example of how programs are structured in OllieOS, according to the [Program interface](./interfaces/Program_Types.Program.html):
26+
27+
```ts
28+
import type { Program } from "ollieos/types";
29+
30+
export default {
31+
name: "hwpkg",
32+
description: "Says hello to the world!",
33+
usage_suffix: "",
34+
arg_descriptions: {},
35+
compat: "2.0.0",
36+
main: async (data) => {
37+
const { term } = data;
38+
39+
term.writeln("hello package!");
40+
41+
return 0;
42+
}
43+
} as Program;
44+
```

src/api_docs/privileged.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55

66
export type { Kernel } from "../kernel";
77
export type { AbstractFileSystem } from "../kernel/filesystem";
8-
export type { ProcessManager, IPCManager, ProcessContext } from "../kernel/processes";
8+
export type { ProcessManager, ProcessContext, IPCManager } from "../kernel/processes";
99
export type { ProgramRegistry } from "../kernel/prog_registry";
1010
export type { AbstractWindow, AbstractWindowManager } from "../kernel/windowing";

src/api_docs/types.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/**
2-
* @module Types
2+
* @module Program Types
3+
* @description Type interfaces for the definition of program files.
34
*/
45

56
export type {
@@ -9,7 +10,7 @@ export type {
910
ArgDescriptions,
1011
CompletionGenerator,
1112
CompletionData,
12-
ProgramRegistrant,
13-
KeyEvent,
14-
KeyEventHandler
13+
PrivilegedProgram,
14+
PrivilegedProgramMain,
15+
PrivilegedProgramMainData
1516
} from "../types";

src/api_docs/userspace.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,19 @@
66
export type {UserspaceKernel, SpawnResult, ParsedCommandLine} from "../kernel";
77
export type {UserspaceFileSystem, FSEventType, FSEventHandler} from "../kernel/filesystem";
88
export type {
9-
IPCMessage,
10-
IPCChannelListener,
11-
IPCServiceOnConnectionCallback,
129
UserspaceProcessManager,
13-
UserspaceIPCManager,
1410
UserspaceProcessContext,
1511
UserspaceOtherProcessContext,
12+
ProcessAttachment,
13+
UserspaceIPCManager,
14+
IPCMessage,
15+
IPCChannelListener,
16+
IPCServiceOnConnectionCallback,
1617
} from "../kernel/processes";
1718
export type {UserspaceWindowManager, UserspaceWindow, UserspaceOtherWindow, WindowEvent} from "../kernel/windowing";
18-
export type {UserspaceProgramRegistry} from "../kernel/prog_registry";
19+
export type {UserspaceProgramRegistry, ProgramRegistrant} from "../kernel/prog_registry";
1920
export type {SoundRegistry} from "../kernel/sfx_registry";
2021

21-
export type {WrappedTerminal, ReadLineBuffer, ReadLineKeyHandler} from "../kernel/term_ctl";
22+
export type {WrappedTerminal, KeyEvent, KeyEventHandler, RegisteredKeyEventIdentifier, ReadLineBuffer, ReadLineKeyHandler} from "../kernel/term_ctl";
2223

2324
export type {AbstractShell, AbstractShellMemory} from "../abstract_shell";

src/kernel/processes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ export class IPCManager {
283283

284284
// TODO: could migrate the stuff where programs grab "scary" stuff like WindowManager and ProcessManager to be services
285285

286-
enum ProcessAttachment {
286+
export enum ProcessAttachment {
287287
FOREGROUND,
288288
BACKGROUND,
289289
DETACHED,

src/kernel/prog_registry.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1-
import type { Program, ProgramRegistrant } from "../types";
2-
import type { AbstractFileSystem } from "./filesystem";
3-
import { ANSI, WrappedTerminal } from "./term_ctl";
1+
import type {Program} from "../types";
2+
import type {AbstractFileSystem} from "./filesystem";
3+
import {ANSI, WrappedTerminal} from "./term_ctl";
44

55
const encode_js_to_url = (js_code: string): string => {
66
const encoded = encodeURIComponent(js_code);
77
return `data:text/javascript;charset=utf-8,${encoded}`;
88
}
99

10+
export interface ProgramRegistrant {
11+
program: Program<unknown>,
12+
built_in: boolean,
13+
}
14+
1015
export const build_registrant_from_js = async (js_code: string, built_in = false): Promise<ProgramRegistrant> => {
1116
// inspect the js code to see if it starts with "import". if so, this is outdated, put a deprecation warning
1217
let warn_deprecation = false;

src/kernel/term_ctl.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {IDisposable, ITerminalOptions, Terminal} from "@xterm/xterm";
2-
import type {KeyEvent, KeyEventHandler, RegisteredKeyEventIdentifier} from "../types";
32

43
export const NEWLINE = "\r\n";
54
/* eslint-disable-next-line no-control-regex, no-misleading-character-class */
@@ -82,6 +81,18 @@ export const ANSI = {
8281

8382
// TODO: docstrings everywhere
8483

84+
export interface KeyEvent {
85+
key: string;
86+
domEvent: KeyboardEvent;
87+
}
88+
89+
export type KeyEventHandler = (event: KeyEvent, term: WrappedTerminal) => void | Promise<void>;
90+
91+
export interface RegisteredKeyEventIdentifier {
92+
key?: string;
93+
domEventCode?: string;
94+
}
95+
8596
export interface ReadLineBuffer {
8697
current_line: string;
8798
current_index: number;

src/types.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,6 @@ export interface Program<K = UserspaceKernel> {
6969

7070
export type PrivilegedProgram = Program<Kernel>;
7171

72-
// TODO: move some of these to their correct modules
73-
7472
export interface CompletionData {
7573
term: WrappedTerminal,
7674
kernel: UserspaceKernel,
@@ -85,19 +83,3 @@ export interface CompletionData {
8583

8684
// return null to fall back to default completion behavior (file paths)
8785
export type CompletionGenerator = (data: CompletionData) => Promise<string[] | null> | AsyncGenerator<string>;
88-
89-
export interface ProgramRegistrant {
90-
program: Program<unknown>,
91-
built_in: boolean,
92-
}
93-
94-
export interface KeyEvent {
95-
key: string;
96-
domEvent: KeyboardEvent;
97-
}
98-
99-
export type KeyEventHandler = (event: KeyEvent, term: WrappedTerminal) => void | Promise<void>;
100-
export interface RegisteredKeyEventIdentifier {
101-
key?: string;
102-
domEventCode?: string;
103-
}

typedoc.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
{
22
"$schema": "https://typedoc.org/schema.json",
3-
"entryPoints": ["src/api_docs/index.ts"]
3+
"entryPoints": ["src/api_docs/index.ts"],
4+
"sort": ["required-first"],
5+
"readme": "src/api_docs/README.md",
46
}

0 commit comments

Comments
 (0)