Skip to content

Commit f09dd1d

Browse files
committed
Improve darkmode and add plugin documentation
1 parent 29114c5 commit f09dd1d

File tree

8 files changed

+157
-6
lines changed

8 files changed

+157
-6
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ Feather will automatically capture and log errors in real-time. You can also man
151151
debugger:error("Something went wrong")
152152
```
153153

154+
### Plugins
155+
156+
Feather comes with a plugin system that allows you to extend its functionality with custom data inspectors. Check out the [Feather Plugins](docs/plugins.md) repository for more information.
157+
154158
## 📜 License
155159

156160
Feel free to use and remix this project for personal, educational, or non-commercial fun.

ROADMAP.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@
1010
- [x] default settings
1111
- [x] download feather rock file for the version you are using
1212
- [x] Add basic plugin support
13-
- [ ] Add optional plugins:
13+
- [x] Add optional plugins:
1414
- [x] SIGNAL
15-
- [ ] LUA STATE
16-
- [ ] CARGO
17-
- [ ] Mini overlay mode
18-
- [ ] Add plugin documentation
15+
- [x] LUA STATE
16+
- [ ] ~~CARGO~~
17+
- [x] Add plugin documentation
18+
- [ ] ~~Mini overlay mode~~
19+
20+
Use OverlayStats instead (see [this](https://github.com/Oval-Tutu/bootstrap-love2d-project/blob/main/game/lib/overlayStats.lua)).
1921

2022
---
2123

docs/images/logs.png

-1.52 MB
Loading

docs/images/observable.png

-478 KB
Loading

docs/images/performance.png

-786 KB
Loading

docs/plugins.md

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
# Feather Plugins
2+
3+
Feather plugins are any Lua modules that extend the functionality of the debugger.
4+
5+
## Creating a plugin
6+
7+
To create a plugin, you need to create a Lua module that exports a table with the following functions:
8+
9+
- `init(config)`: This function is called when the plugin is initialized.
10+
- `update(dt, feather)`: This function is called every frame.
11+
- `onerror(msg, feather)`: This function is called when an error occurs. Errors in this function will close the game abruptly.
12+
- `handleRequest(request, feather)`: This function is called when a request is received.
13+
- `finish(feather)`: This function is called when the server is closed.
14+
- `getConfig()`: This function returns the configuration for the plugin. Sent to the client app.
15+
16+
To help with the implementation, Feather provides the `FeatherPlugin` class, which you can extend to create your plugin.
17+
18+
```lua
19+
local FeatherPlugin = require("feather.plugins.base")
20+
21+
local MyPlugin = Class({
22+
__includes = FeatherPlugin,
23+
})
24+
25+
function MyPlugin:init(config)
26+
-- Do something with the config
27+
end
28+
29+
function MyPlugin:update(dt, feather)
30+
-- Do something with the dt and feather
31+
end
32+
33+
function MyPlugin:onerror(msg, feather)
34+
-- Do something with the msg and feather
35+
end
36+
37+
function MyPlugin:handleRequest(request, feather)
38+
-- Do something with the request and feather
39+
end
40+
41+
function MyPlugin:finish(feather)
42+
-- Do something with the feather
43+
end
44+
45+
function MyPlugin:getConfig()
46+
-- Return the configuration for the plugin
47+
return {
48+
type = "my-plugin",
49+
color = "#ff0000",
50+
icon = "my-plugin-icon",
51+
}
52+
end
53+
54+
return MyPlugin
55+
```
56+
57+
## Registering a plugin
58+
59+
To register a plugin, you need to create an instance of it and pass it to the FeatherPluginManager. The FeatherPluginManager will handle the lifecycle of the plugin and call the appropriate functions.
60+
61+
```lua
62+
local MyPlugin = require("my-plugin")
63+
64+
local plugin = FeatherPluginManager.createPlugin(MyPlugin, "my-plugin", {
65+
-- Plugin options
66+
})
67+
```
68+
69+
## Plugin lifecycle
70+
71+
The FeatherPluginManager will handle the lifecycle of the plugin and call the appropriate functions. Here's a breakdown of the plugin lifecycle:
72+
73+
1. **Initialization**: The plugin is initialized with the provided options.
74+
2. **Request Handling**: The plugin handles requests from the client.
75+
3. **Update**: The plugin is updated every frame.
76+
4. **Error Handling**: The plugin handles errors that occur in the game.
77+
5. **Finish**: The plugin is finished and the game is closed.
78+
79+
## Plugin options
80+
81+
The plugin options are passed to the plugin's constructor. Here's an example of a plugin with options:
82+
83+
```lua
84+
local MyPlugin = require("my-plugin")
85+
86+
local plugin = FeatherPluginManager.createPlugin(MyPlugin, "my-plugin", {
87+
option1 = "value1",
88+
option2 = "value2",
89+
})
90+
```
91+
92+
### Feather Options
93+
94+
By default, every plugin has the following properties available:
95+
96+
- `self.logger`: A logger that logs messages to the Feather logger.
97+
- `self.observer`: A logger that logs messages to the Feather observer.
98+
99+
## Plugin configuration
100+
101+
Feather plugins can return configuration that is sent to the client. This configuration is used to display the plugin in the plugins tab.
102+
103+
Here's an example of a plugin with configuration:
104+
105+
```lua
106+
local MyPlugin = require("my-plugin")
107+
108+
function MyPlugin:getConfig()
109+
return {
110+
type = "my-plugin",
111+
color = "#ff0000",
112+
icon = "my-plugin-icon",
113+
}
114+
end
115+
```
116+
117+
## Plugin examples
118+
119+
Here are some examples of Feather plugins:
120+
121+
- [Hump's Signal Plugin](../src-lua/plugins/hump/signal/README.md)
122+
- [Lua State Machine Plugin](../src-lua/plugins/lua-state-machine/README.md)
123+
124+
## Plugin documentation
125+
126+
Each plugin should have a README file that explains how to use it and provides examples.

src/components/code.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
import SyntaxHighlighter from 'react-syntax-highlighter';
22
import { ScrollArea } from '@/components/ui/scroll-area';
33
import oneLight from '@/assets/theme/light';
4+
import onDark from '@/assets/theme/dark';
5+
46
import { cn } from '@/lib/utils';
7+
import { useTheme } from '@/hooks/use-theme';
58

69
export function LuaBlock({ code, className }: { code: string; className?: string }) {
10+
const theme = useTheme();
11+
const style = theme === 'dark' ? onDark : oneLight;
12+
713
return (
814
<ScrollArea className="mt-2 w-full rounded border bg-muted p-2 font-mono text-xs">
915
<div className={cn('max-h-64', className)}>
@@ -12,7 +18,7 @@ export function LuaBlock({ code, className }: { code: string; className?: string
1218
language="lua"
1319
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
1420
// @ts-expect-error
15-
style={oneLight}
21+
style={style}
1622
showLineNumbers
1723
>
1824
{code}

src/hooks/use-theme.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { useSettingsStore } from '@/store/settings';
2+
3+
export const useTheme = () => {
4+
const isDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
5+
6+
const theme = useSettingsStore((state) => state.theme);
7+
8+
if (theme === 'system') {
9+
return isDark ? 'dark' : 'light';
10+
}
11+
12+
return theme;
13+
};

0 commit comments

Comments
 (0)