@suds-cli/filetree 0.1.0-alpha.0

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.
@@ -0,0 +1,196 @@
1
+ import { Cmd, Msg } from '@suds-cli/tea';
2
+ import { FileSystemAdapter, PathAdapter } from '@suds-cli/machine';
3
+ import { Binding } from '@suds-cli/key';
4
+ import { Style } from '@suds-cli/chapstick';
5
+
6
+ /**
7
+ * Represents a file or directory item in the file tree.
8
+ * @public
9
+ */
10
+ interface DirectoryItem {
11
+ /** Name of the file or directory */
12
+ name: string;
13
+ /** Formatted details string (e.g., "2024-01-15 10:30:00 -rw-r--r-- 1.2K") */
14
+ details: string;
15
+ /** Full path to the item */
16
+ path: string;
17
+ /** File extension (empty for directories) */
18
+ extension: string;
19
+ /** Whether this item is a directory */
20
+ isDirectory: boolean;
21
+ /** Parent directory path */
22
+ currentDirectory: string;
23
+ /** File mode bits (from fs.Stats.mode) for determining file type and permissions */
24
+ mode: number;
25
+ }
26
+
27
+ /**
28
+ * Keyboard bindings for the filetree component.
29
+ * @public
30
+ */
31
+ interface FiletreeKeyMap {
32
+ down: Binding;
33
+ up: Binding;
34
+ }
35
+ /**
36
+ * Default key bindings for the filetree.
37
+ * @public
38
+ */
39
+ declare const defaultKeyMap: FiletreeKeyMap;
40
+
41
+ /**
42
+ * Style configuration for the filetree component.
43
+ * @public
44
+ */
45
+ interface FiletreeStyles {
46
+ /** Style for selected/highlighted item */
47
+ selectedItem: Style;
48
+ /** Style for normal items */
49
+ normalItem: Style;
50
+ }
51
+ /**
52
+ * Default styles for the filetree component.
53
+ * @public
54
+ */
55
+ declare function defaultStyles(): FiletreeStyles;
56
+ /**
57
+ * Merge user provided style overrides with defaults.
58
+ * @public
59
+ */
60
+ declare function mergeStyles(overrides?: Partial<FiletreeStyles>): FiletreeStyles;
61
+
62
+ /**
63
+ * Options for creating a new FiletreeModel.
64
+ * @public
65
+ */
66
+ interface FiletreeOptions {
67
+ /** Filesystem adapter for file operations */
68
+ filesystem: FileSystemAdapter;
69
+ /** Path adapter for path operations */
70
+ path: PathAdapter;
71
+ /** Initial directory to display */
72
+ currentDir?: string;
73
+ /** Whether to show hidden files */
74
+ showHidden?: boolean;
75
+ /** Custom key bindings */
76
+ keyMap?: FiletreeKeyMap;
77
+ /** Custom styles */
78
+ styles?: Partial<FiletreeStyles>;
79
+ /** Initial width */
80
+ width?: number;
81
+ /** Initial height */
82
+ height?: number;
83
+ }
84
+ /**
85
+ * Model for the filetree component.
86
+ * @public
87
+ */
88
+ declare class FiletreeModel {
89
+ /** Current cursor position */
90
+ readonly cursor: number;
91
+ /** Array of directory items */
92
+ readonly files: DirectoryItem[];
93
+ /** Whether component is active and receives input */
94
+ readonly active: boolean;
95
+ /** Key bindings */
96
+ readonly keyMap: FiletreeKeyMap;
97
+ /** Minimum viewport scroll position */
98
+ readonly min: number;
99
+ /** Maximum viewport scroll position */
100
+ readonly max: number;
101
+ /** Component height */
102
+ readonly height: number;
103
+ /** Component width */
104
+ readonly width: number;
105
+ /** Styles */
106
+ readonly styles: FiletreeStyles;
107
+ /** Current directory */
108
+ readonly currentDir: string;
109
+ /** Whether to show hidden files */
110
+ readonly showHidden: boolean;
111
+ /** Last error, if any */
112
+ readonly error: Error | null;
113
+ /** Filesystem adapter */
114
+ readonly filesystem: FileSystemAdapter;
115
+ /** Path adapter */
116
+ readonly path: PathAdapter;
117
+ private constructor();
118
+ /**
119
+ * Creates a new filetree model.
120
+ * @param options - Configuration options
121
+ * @returns A new FiletreeModel instance
122
+ * @public
123
+ */
124
+ static new(options: FiletreeOptions): FiletreeModel;
125
+ /**
126
+ * Initializes the model and returns a command to load the directory.
127
+ * @returns Command to load directory listing
128
+ * @public
129
+ */
130
+ init(): Cmd<Msg>;
131
+ /**
132
+ * Sets whether the component is active and receives input.
133
+ * @param active - Whether component should be active
134
+ * @returns Updated model
135
+ * @public
136
+ */
137
+ setIsActive(active: boolean): FiletreeModel;
138
+ /**
139
+ * Updates the model in response to a message.
140
+ * @param msg - The message to handle
141
+ * @returns Tuple of updated model and command
142
+ * @public
143
+ */
144
+ update(msg: Msg): [FiletreeModel, Cmd<Msg> | null];
145
+ /**
146
+ * Renders the file tree view.
147
+ * @returns Rendered string
148
+ * @public
149
+ */
150
+ view(): string;
151
+ /**
152
+ * Gets the currently selected file, if any.
153
+ * @returns The selected DirectoryItem or null
154
+ * @public
155
+ */
156
+ get selectedFile(): DirectoryItem | null;
157
+ }
158
+
159
+ /**
160
+ * Message containing directory listing results.
161
+ * @public
162
+ */
163
+ declare class GetDirectoryListingMsg {
164
+ readonly items: DirectoryItem[];
165
+ readonly _tag = "filetree-get-directory-listing";
166
+ constructor(items: DirectoryItem[]);
167
+ }
168
+ /**
169
+ * Message containing an error.
170
+ * @public
171
+ */
172
+ declare class ErrorMsg {
173
+ readonly error: Error;
174
+ readonly _tag = "filetree-error";
175
+ constructor(error: Error);
176
+ }
177
+
178
+ /**
179
+ * Converts bytes to a human-readable size string.
180
+ * @param size - Size in bytes
181
+ * @returns Formatted string (e.g., "1.2K", "5.4M", "2.3G")
182
+ * @public
183
+ */
184
+ declare function convertBytesToSizeString(size: number): string;
185
+ /**
186
+ * Creates a command to asynchronously fetch directory contents.
187
+ * @param filesystem - Filesystem adapter for file operations
188
+ * @param path - Path adapter for path operations
189
+ * @param dir - Directory path to list
190
+ * @param showHidden - Whether to show hidden files
191
+ * @returns Command that will emit GetDirectoryListingMsg or ErrorMsg
192
+ * @public
193
+ */
194
+ declare function getDirectoryListingCmd(filesystem: FileSystemAdapter, path: PathAdapter, dir: string, showHidden: boolean): Cmd<GetDirectoryListingMsg | ErrorMsg>;
195
+
196
+ export { type DirectoryItem, ErrorMsg, type FiletreeKeyMap, FiletreeModel, type FiletreeOptions, type FiletreeStyles, GetDirectoryListingMsg, convertBytesToSizeString, defaultKeyMap, defaultStyles, getDirectoryListingCmd, mergeStyles };
@@ -0,0 +1,196 @@
1
+ import { Cmd, Msg } from '@suds-cli/tea';
2
+ import { FileSystemAdapter, PathAdapter } from '@suds-cli/machine';
3
+ import { Binding } from '@suds-cli/key';
4
+ import { Style } from '@suds-cli/chapstick';
5
+
6
+ /**
7
+ * Represents a file or directory item in the file tree.
8
+ * @public
9
+ */
10
+ interface DirectoryItem {
11
+ /** Name of the file or directory */
12
+ name: string;
13
+ /** Formatted details string (e.g., "2024-01-15 10:30:00 -rw-r--r-- 1.2K") */
14
+ details: string;
15
+ /** Full path to the item */
16
+ path: string;
17
+ /** File extension (empty for directories) */
18
+ extension: string;
19
+ /** Whether this item is a directory */
20
+ isDirectory: boolean;
21
+ /** Parent directory path */
22
+ currentDirectory: string;
23
+ /** File mode bits (from fs.Stats.mode) for determining file type and permissions */
24
+ mode: number;
25
+ }
26
+
27
+ /**
28
+ * Keyboard bindings for the filetree component.
29
+ * @public
30
+ */
31
+ interface FiletreeKeyMap {
32
+ down: Binding;
33
+ up: Binding;
34
+ }
35
+ /**
36
+ * Default key bindings for the filetree.
37
+ * @public
38
+ */
39
+ declare const defaultKeyMap: FiletreeKeyMap;
40
+
41
+ /**
42
+ * Style configuration for the filetree component.
43
+ * @public
44
+ */
45
+ interface FiletreeStyles {
46
+ /** Style for selected/highlighted item */
47
+ selectedItem: Style;
48
+ /** Style for normal items */
49
+ normalItem: Style;
50
+ }
51
+ /**
52
+ * Default styles for the filetree component.
53
+ * @public
54
+ */
55
+ declare function defaultStyles(): FiletreeStyles;
56
+ /**
57
+ * Merge user provided style overrides with defaults.
58
+ * @public
59
+ */
60
+ declare function mergeStyles(overrides?: Partial<FiletreeStyles>): FiletreeStyles;
61
+
62
+ /**
63
+ * Options for creating a new FiletreeModel.
64
+ * @public
65
+ */
66
+ interface FiletreeOptions {
67
+ /** Filesystem adapter for file operations */
68
+ filesystem: FileSystemAdapter;
69
+ /** Path adapter for path operations */
70
+ path: PathAdapter;
71
+ /** Initial directory to display */
72
+ currentDir?: string;
73
+ /** Whether to show hidden files */
74
+ showHidden?: boolean;
75
+ /** Custom key bindings */
76
+ keyMap?: FiletreeKeyMap;
77
+ /** Custom styles */
78
+ styles?: Partial<FiletreeStyles>;
79
+ /** Initial width */
80
+ width?: number;
81
+ /** Initial height */
82
+ height?: number;
83
+ }
84
+ /**
85
+ * Model for the filetree component.
86
+ * @public
87
+ */
88
+ declare class FiletreeModel {
89
+ /** Current cursor position */
90
+ readonly cursor: number;
91
+ /** Array of directory items */
92
+ readonly files: DirectoryItem[];
93
+ /** Whether component is active and receives input */
94
+ readonly active: boolean;
95
+ /** Key bindings */
96
+ readonly keyMap: FiletreeKeyMap;
97
+ /** Minimum viewport scroll position */
98
+ readonly min: number;
99
+ /** Maximum viewport scroll position */
100
+ readonly max: number;
101
+ /** Component height */
102
+ readonly height: number;
103
+ /** Component width */
104
+ readonly width: number;
105
+ /** Styles */
106
+ readonly styles: FiletreeStyles;
107
+ /** Current directory */
108
+ readonly currentDir: string;
109
+ /** Whether to show hidden files */
110
+ readonly showHidden: boolean;
111
+ /** Last error, if any */
112
+ readonly error: Error | null;
113
+ /** Filesystem adapter */
114
+ readonly filesystem: FileSystemAdapter;
115
+ /** Path adapter */
116
+ readonly path: PathAdapter;
117
+ private constructor();
118
+ /**
119
+ * Creates a new filetree model.
120
+ * @param options - Configuration options
121
+ * @returns A new FiletreeModel instance
122
+ * @public
123
+ */
124
+ static new(options: FiletreeOptions): FiletreeModel;
125
+ /**
126
+ * Initializes the model and returns a command to load the directory.
127
+ * @returns Command to load directory listing
128
+ * @public
129
+ */
130
+ init(): Cmd<Msg>;
131
+ /**
132
+ * Sets whether the component is active and receives input.
133
+ * @param active - Whether component should be active
134
+ * @returns Updated model
135
+ * @public
136
+ */
137
+ setIsActive(active: boolean): FiletreeModel;
138
+ /**
139
+ * Updates the model in response to a message.
140
+ * @param msg - The message to handle
141
+ * @returns Tuple of updated model and command
142
+ * @public
143
+ */
144
+ update(msg: Msg): [FiletreeModel, Cmd<Msg> | null];
145
+ /**
146
+ * Renders the file tree view.
147
+ * @returns Rendered string
148
+ * @public
149
+ */
150
+ view(): string;
151
+ /**
152
+ * Gets the currently selected file, if any.
153
+ * @returns The selected DirectoryItem or null
154
+ * @public
155
+ */
156
+ get selectedFile(): DirectoryItem | null;
157
+ }
158
+
159
+ /**
160
+ * Message containing directory listing results.
161
+ * @public
162
+ */
163
+ declare class GetDirectoryListingMsg {
164
+ readonly items: DirectoryItem[];
165
+ readonly _tag = "filetree-get-directory-listing";
166
+ constructor(items: DirectoryItem[]);
167
+ }
168
+ /**
169
+ * Message containing an error.
170
+ * @public
171
+ */
172
+ declare class ErrorMsg {
173
+ readonly error: Error;
174
+ readonly _tag = "filetree-error";
175
+ constructor(error: Error);
176
+ }
177
+
178
+ /**
179
+ * Converts bytes to a human-readable size string.
180
+ * @param size - Size in bytes
181
+ * @returns Formatted string (e.g., "1.2K", "5.4M", "2.3G")
182
+ * @public
183
+ */
184
+ declare function convertBytesToSizeString(size: number): string;
185
+ /**
186
+ * Creates a command to asynchronously fetch directory contents.
187
+ * @param filesystem - Filesystem adapter for file operations
188
+ * @param path - Path adapter for path operations
189
+ * @param dir - Directory path to list
190
+ * @param showHidden - Whether to show hidden files
191
+ * @returns Command that will emit GetDirectoryListingMsg or ErrorMsg
192
+ * @public
193
+ */
194
+ declare function getDirectoryListingCmd(filesystem: FileSystemAdapter, path: PathAdapter, dir: string, showHidden: boolean): Cmd<GetDirectoryListingMsg | ErrorMsg>;
195
+
196
+ export { type DirectoryItem, ErrorMsg, type FiletreeKeyMap, FiletreeModel, type FiletreeOptions, type FiletreeStyles, GetDirectoryListingMsg, convertBytesToSizeString, defaultKeyMap, defaultStyles, getDirectoryListingCmd, mergeStyles };