opendocker 0.1.5 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,132 +0,0 @@
1
- import { useState, useEffect, useRef, useMemo } from "react";
2
- import { colors, termColors } from "../utils/styling";
3
- import { RGBA, TextAttributes, type ScrollBoxRenderable } from "@opentui/core";
4
- import Pane from "./Pane";
5
- import { useContainerStore } from "../stores/containers";
6
- import { useApplicationStore } from "../stores/application";
7
- import { Shimmer } from "./ui/Shimmer";
8
-
9
- type LogEntry = {
10
- text: string;
11
- type: 'stdout' | 'stderr';
12
- };
13
-
14
- export default function LogsPane() {
15
- const { activePane } = useApplicationStore((state) => state);
16
- const { activeContainer } = useContainerStore((state) => state);
17
- const [logs, setLogs] = useState<LogEntry[]>([]);
18
- const scrollBoxRef = useRef<ScrollBoxRenderable>(null);
19
-
20
- useEffect(() => {
21
- if (!activeContainer || activePane !== "containers") {
22
- cleanup();
23
- return;
24
- };
25
-
26
- const process = Bun.spawn([
27
- "docker",
28
- "logs",
29
- "--follow",
30
- "--tail",
31
- "100",
32
- activeContainer.name,
33
- ], {
34
- stdout: "pipe",
35
- stderr: "pipe",
36
- });
37
-
38
- async function readStream(stream: ReadableStream, type: 'stdout' | 'stderr') {
39
- const decoder = new TextDecoder();
40
- const reader = stream.getReader();
41
-
42
- try {
43
- while (true) {
44
- const { done, value } = await reader.read();
45
- if (done) break;
46
-
47
- const text = decoder.decode(value, { stream: true });
48
- // Split by newlines and filter out empty lines
49
- const lines = text.split('\n').filter(line => line.trim().length > 0);
50
-
51
- if (lines.length > 0) {
52
- setLogs(prev => {
53
- const newEntries = lines.map(line => ({
54
- text: line,
55
- type
56
- }));
57
- return [...prev, ...newEntries];
58
- });
59
- }
60
- }
61
- } catch (error) {}
62
- }
63
-
64
- readStream(process.stdout, 'stdout');
65
- readStream(process.stderr, 'stderr');
66
-
67
- return () => {
68
- process.kill();
69
- cleanup();
70
- }
71
- }, [activePane, activeContainer?.name, activeContainer?.state])
72
-
73
- useEffect(() => {
74
- if (scrollBoxRef.current && logs.length > 0) {
75
- scrollBoxRef.current.scrollTo({ x: 0, y: scrollBoxRef.current.scrollHeight });
76
- }
77
- }, [logs]);
78
-
79
- function cleanup() {
80
- setLogs([]);
81
- }
82
-
83
- const output = useMemo(() => {
84
- if (logs.length === 0 && activeContainer?.state === "created") {
85
- return <Shimmer text="Container starting..." color={RGBA.fromHex(colors.text)} />
86
- }
87
-
88
- if (logs.length === 0) {
89
- return <text fg={colors.textMuted}>No logs available</text>;
90
- }
91
-
92
- return logs.map((log, index) => (
93
- <text
94
- key={index}
95
- >
96
- {log.text}
97
- </text>
98
- ));
99
- }, [logs]);
100
-
101
- return (
102
- <Pane
103
- title="Logs"
104
- flexDirection="column"
105
- width="70%"
106
- >
107
- <box flexDirection="column" gap={1} height="100%">
108
- <box flexDirection="row" gap={2} height="auto">
109
- <box flexDirection="column" gap={1}>
110
- <text fg={termColors.purple11} attributes={TextAttributes.BOLD}>Container</text>
111
- <text>{activeContainer?.name || "None"}</text>
112
- </box>
113
- <box flexDirection="column">
114
- <text fg={termColors.purple11} attributes={TextAttributes.BOLD}>Status</text>
115
- <text>{activeContainer?.status || "None"}</text>
116
- </box>
117
- </box>
118
- <scrollbox
119
- ref={scrollBoxRef}
120
- scrollY={true}
121
- stickyScroll={true}
122
- stickyStart="bottom"
123
- height="100%"
124
- >
125
- <box flexDirection="column" height="auto">
126
- {output}
127
- </box>
128
- </scrollbox>
129
- </box>
130
- </Pane>
131
- )
132
- }
@@ -1,34 +0,0 @@
1
- import { SplitBorder } from "./Border";
2
- import type { BoxProps } from "@opentui/react";
3
- import { padding, colors, termColors } from "../utils/styling";
4
- import { TextAttributes } from "@opentui/core";
5
-
6
- interface PaneProps extends BoxProps {
7
- title?: string;
8
- active?: boolean;
9
- children: React.ReactNode;
10
- }
11
-
12
- export default function Pane({
13
- title,
14
- active = false,
15
- children,
16
- ...props
17
- }: PaneProps) {
18
- return (
19
- <box
20
- {...SplitBorder}
21
- {...props}
22
- borderColor={active ? termColors.purple11 : colors.backgroundPanel}
23
- >
24
- <box
25
- flexGrow={1}
26
- backgroundColor={colors.backgroundPanel}
27
- {...padding}
28
- >
29
- {title && <text marginBottom={1} attributes={TextAttributes.BOLD}>{title}</text>}
30
- {children}
31
- </box>
32
- </box>
33
- )
34
- }
@@ -1,84 +0,0 @@
1
- import { useEffect, useRef } from "react";
2
- import { useKeyboard } from "@opentui/react";
3
- import Pane from "./Pane";
4
- import { colors } from "../utils/styling";
5
- import { useVolumeStore } from "../stores/volumes";
6
- import { useApplicationStore } from "../stores/application";
7
- import type { ScrollBoxRenderable } from "@opentui/core";
8
-
9
- export default function ImagesPane() {
10
- const { activePane, setActivePane } = useApplicationStore((state) => state);
11
- const { volumes, setVolumes } = useVolumeStore();
12
- const scrollBoxRef = useRef<ScrollBoxRenderable>(null);
13
-
14
- useEffect(() => {
15
- const process = Bun.spawn(
16
- ["docker", "volume", "ls", "--format", "{{.Name}}"],
17
- {stdout: "pipe", stderr: "pipe"},
18
- );
19
-
20
- async function read() {
21
- try {
22
- const reader = process.stdout.getReader();
23
-
24
- while (true) {
25
- const { done, value } = await reader.read();
26
- if (done) break;
27
- const decodedValues = new TextDecoder().decode(value);
28
- const lines = decodedValues.split("\n").filter(Boolean);
29
- setVolumes(lines);
30
- }
31
- } catch (error) {
32
- console.error(error);
33
- }
34
- }
35
-
36
- read();
37
-
38
- return () => process.kill();
39
- }, []);
40
-
41
- useKeyboard((key) => {
42
- if (activePane !== "volumes") {
43
- return;
44
- }
45
-
46
- if (key.name === "left") {
47
- setActivePane("images");
48
- }
49
-
50
- if (key.name === "right" || key.name === "tab") {
51
- setActivePane("containers");
52
- }
53
- });
54
-
55
- return (
56
- <Pane
57
- title="Volumes"
58
- active={activePane === "volumes"}
59
- width="100%"
60
- flexDirection="column"
61
- >
62
- <scrollbox
63
- ref={scrollBoxRef}
64
- scrollY={true}
65
- stickyScroll={true}
66
- stickyStart="bottom"
67
- viewportOptions={{
68
- flexGrow: 1
69
- }}
70
- >
71
- {volumes.map((item, index) => {
72
- return <box>
73
- <text
74
- key={index}
75
- content={`[*] ${item}`}
76
- fg={colors.textMuted}
77
- />
78
- </box>
79
- })}
80
- {volumes.length < 1 && <text fg={colors.textMuted}>No Volumes</text>}
81
- </scrollbox>
82
- </Pane>
83
- )
84
- }
@@ -1,64 +0,0 @@
1
- import { RGBA } from "@opentui/core"
2
- import { useTimeline } from "@opentui/react"
3
- import { useState, useEffect } from "react"
4
-
5
- export type ShimmerProps = {
6
- text: string
7
- color: RGBA
8
- }
9
-
10
- const DURATION = 2_500
11
-
12
- export function Shimmer(props: ShimmerProps) {
13
- const timeline = useTimeline({
14
- duration: DURATION,
15
- loop: true,
16
- })
17
- const characters = props.text.split("")
18
- const color = props.color
19
-
20
- const [shimmerValues, setShimmerValues] = useState<number[]>(() =>
21
- characters.map(() => 0.4)
22
- )
23
-
24
- useEffect(() => {
25
- characters.forEach((_, i) => {
26
- const target = {
27
- shimmer: shimmerValues[i],
28
- setShimmer: (value: number) => {
29
- setShimmerValues(prev => {
30
- const newValues = [...prev]
31
- newValues[i] = value
32
- return newValues
33
- })
34
- },
35
- }
36
-
37
- timeline!.add(
38
- target,
39
- {
40
- shimmer: 1,
41
- duration: DURATION / (props.text.length + 1),
42
- ease: "linear",
43
- alternate: true,
44
- loop: 2,
45
- onUpdate: () => {
46
- target.setShimmer(target.shimmer)
47
- },
48
- },
49
- (i * (DURATION / (props.text.length + 1))) / 2,
50
- )
51
- })
52
- }, [timeline, props.text.length])
53
-
54
- return (
55
- <text>
56
- {characters.map((ch, i) => {
57
- const shimmer = shimmerValues[i]
58
- const fg = RGBA.fromInts(color.r * 255, color.g * 255, color.b * 255, shimmer * 255)
59
- return <span key={i} style={{ fg }}>{ch}</span>
60
- })}
61
- </text>
62
- )
63
- }
64
-
@@ -1,60 +0,0 @@
1
-
2
- import { useTerminalDimensions } from "@opentui/react";
3
- import { useState, useEffect } from "react";
4
- import { colors, padding } from "../utils/styling";
5
- import { TextAttributes } from "@opentui/core";
6
- import { useApplicationStore } from "../stores/application";
7
- import { SplitBorder } from "../components/Border";
8
-
9
- export default function BaseLayout({ children }: { children: React.ReactNode }) {
10
- const { activePane, setActivePane } = useApplicationStore((state) => state);
11
- const dimensions = useTerminalDimensions();
12
- const [pwd, setPwd] = useState<string>("");
13
- const version = "v0.1.5";
14
-
15
- useEffect(() => {
16
- Bun.$`pwd`.quiet().then(result => setPwd(result.text()));
17
- setActivePane("containers");
18
- }, [setActivePane]);
19
-
20
- return (
21
- <box
22
- width={dimensions.width}
23
- height={dimensions.height}
24
- backgroundColor={colors.background}
25
- >
26
- <box
27
- flexDirection="row"
28
- gap={1}
29
- width="100%"
30
- {...padding}
31
- >
32
- {children}
33
- </box>
34
- <box
35
- height={1}
36
- backgroundColor={colors.backgroundPanel}
37
- flexDirection="row"
38
- justifyContent="space-between"
39
- flexShrink={0}
40
- >
41
- <box flexDirection="row">
42
- <box flexDirection="row" backgroundColor={colors.backgroundElement} paddingLeft={1} paddingRight={1}>
43
- <text fg={colors.textMuted}>open</text>
44
- <text attributes={TextAttributes.BOLD}>docker </text>
45
- <text fg={colors.textMuted}>{version}</text>
46
- </box>
47
- <box paddingLeft={1} paddingRight={1}>
48
- <text fg={colors.textMuted}>~{pwd}</text>
49
- </box>
50
- </box>
51
- <box flexDirection="row" gap={1}>
52
- {/* <text fg={colors.textMuted}>tab</text> */}
53
- <box backgroundColor={colors.accent} paddingLeft={1} paddingRight={1} {...SplitBorder} borderColor={colors.backgroundPanel}>
54
- <text fg={colors.backgroundPanel} attributes={TextAttributes.BOLD}>{activePane}</text>
55
- </box>
56
- </box>
57
- </box>
58
- </box>
59
- )
60
- }
package/src/lib/docker.ts DELETED
@@ -1,68 +0,0 @@
1
-
2
- export class Docker {
3
- private socket = "/var/run/docker.sock";
4
-
5
- private async request(path: string) {
6
- try {
7
- const process = Bun.spawn([
8
- "curl", "-s", "--unix-socket", this.socket,
9
- `http://localhost${path}`
10
- ], { stdout: "pipe", stderr: "pipe" });
11
-
12
- const output = await new Response(process.stdout).text();
13
- process.kill();
14
-
15
- return JSON.parse(output);
16
- } catch (error) {
17
- console.error('Docker socket request failed:', error);
18
- throw error;
19
- }
20
- }
21
-
22
- async getContainers() {
23
- return this.request("/v1.41/containers/json?all=true");
24
- }
25
-
26
- async watch(callback: (containers: any[]) => void) {
27
- try {
28
- let containers = await this.getContainers();
29
- callback(containers);
30
-
31
- const process = Bun.spawn([
32
- "curl", "-s", "--no-buffer", "--unix-socket", this.socket,
33
- "http://localhost/v1.41/events"
34
- ], { stdout: "pipe", stderr: "pipe" });
35
-
36
- const reader = process.stdout.getReader();
37
- const decoder = new TextDecoder();
38
- let buffer = "";
39
-
40
- while (true) {
41
- const { value, done } = await reader.read();
42
- if (done) break;
43
-
44
- buffer += decoder.decode(value, { stream: true });
45
- const lines = buffer.split('\n');
46
- buffer = lines.pop() || "";
47
-
48
- for (const line of lines) {
49
- if (line.trim()) {
50
- try {
51
- const event = JSON.parse(line);
52
- if (event.Type === "container") {
53
- containers = await this.getContainers();
54
- callback(containers);
55
- }
56
- } catch (parseError) {
57
- console.error('Failed to parse event:', line, parseError);
58
- }
59
- }
60
- }
61
- }
62
-
63
- } catch (error) {
64
- console.error('Docker watch failed', error);
65
- throw error;
66
- }
67
- }
68
- }
package/src/main.tsx DELETED
@@ -1,43 +0,0 @@
1
- #!/usr/bin/env bun
2
-
3
- import { createRoot, useKeyboard, useRenderer } from "@opentui/react";
4
- import { createCliRenderer } from "@opentui/core";
5
- import ContainersPane from "./components/ContainersPane";
6
- import LogsPane from "./components/LogsPane";
7
- import BaseLayout from "./layouts/BaseLayout";
8
-
9
- function App() {
10
- const renderer = useRenderer();
11
-
12
- useKeyboard((key) => {
13
- if (key.name === "q") {
14
- process.exit(0);
15
- }
16
-
17
- if (key.ctrl && key.name === "d") {
18
- renderer?.console.toggle()
19
- renderer?.toggleDebugOverlay()
20
- }
21
- })
22
-
23
- return (
24
- <BaseLayout>
25
- <box
26
- flexDirection="column"
27
- width="30%"
28
- gap={1}
29
- >
30
- <ContainersPane />
31
- </box>
32
- <LogsPane />
33
- </BaseLayout>
34
- )
35
- }
36
-
37
- async function main() {
38
- const renderer = await createCliRenderer();
39
- const root = createRoot(renderer);
40
- root.render(<App />);
41
- }
42
-
43
- main();
@@ -1,11 +0,0 @@
1
- import { create } from "zustand";
2
-
3
- interface ApplicationStore {
4
- activePane: string;
5
- setActivePane: (activePane: string) => void;
6
- }
7
-
8
- export const useApplicationStore = create<ApplicationStore>((set) => ({
9
- activePane: "containers",
10
- setActivePane: (activePane) => set({ activePane }),
11
- }));
@@ -1,22 +0,0 @@
1
- import { create } from "zustand";
2
-
3
- export type Container = {
4
- name: string;
5
- status: string;
6
- health: string;
7
- state: string;
8
- }
9
-
10
- interface ContainerStore {
11
- containers: Container[];
12
- activeContainer: Container;
13
- setContainers: (containers: Container[]) => void;
14
- setActiveContainer: (activeContainer: Container) => void;
15
- }
16
-
17
- export const useContainerStore = create<ContainerStore>((set) => ({
18
- containers: [],
19
- activeContainer: null,
20
- setContainers: (containers: Container[]) => set({ containers }),
21
- setActiveContainer: (activeContainer) => set({ activeContainer }),
22
- }));
@@ -1,11 +0,0 @@
1
- import { create } from "zustand";
2
-
3
- export interface ImageStore {
4
- images: string[];
5
- setImages: (images: string[]) => void;
6
- }
7
-
8
- export const useImageStore = create<ImageStore>((set) => ({
9
- images: [],
10
- setImages: (images: string[]) => set({ images }),
11
- }));
@@ -1,11 +0,0 @@
1
- import { create } from "zustand";
2
-
3
- interface VolumeStore {
4
- volumes: string[];
5
- setVolumes: (volumes: string[]) => void;
6
- }
7
-
8
- export const useVolumeStore = create<VolumeStore>((set) => ({
9
- volumes: [],
10
- setVolumes: (volumes: string[]) => set({ volumes }),
11
- }));