|
| 1 | +import ComposableArchitecture |
| 2 | +import MarkdownUI |
1 | 3 | import Preferences |
2 | 4 | import SwiftUI |
3 | 5 |
|
@@ -29,8 +31,8 @@ struct CustomCommandView: View { |
29 | 31 | } |
30 | 32 |
|
31 | 33 | @State var editingCommand: EditingCommand? |
32 | | - |
33 | 34 | @StateObject var settings = Settings() |
| 35 | + @Environment(\.toast) var toast |
34 | 36 |
|
35 | 37 | var body: some View { |
36 | 38 | HStack(spacing: 0) { |
@@ -122,16 +124,81 @@ struct CustomCommandView: View { |
122 | 124 |
|
123 | 125 | if let editingCommand { |
124 | 126 | EditCustomCommandView( |
125 | | - editingCommand: $editingCommand, |
126 | | - settings: settings |
| 127 | + store: .init( |
| 128 | + initialState: .init(editingCommand), |
| 129 | + reducer: EditCustomCommand( |
| 130 | + settings: settings, |
| 131 | + toast: toast, |
| 132 | + editingCommand: $editingCommand |
| 133 | + ) |
| 134 | + ) |
127 | 135 | ).id(editingCommand.command.id) |
128 | 136 | } else { |
129 | | - Color.clear |
| 137 | + CustomCommandTypeDescription(text: """ |
| 138 | + # Send Message |
| 139 | +
|
| 140 | + This command sends a message to the active chat tab. You can provide additional context through the "Extra System Prompt" as well. |
| 141 | +
|
| 142 | + # Prompt to Code |
| 143 | +
|
| 144 | + This command opens the prompt-to-code panel and executes the provided requirements on the selected code. You can provide additional context through the "Extra Context" as well. |
| 145 | +
|
| 146 | + # Custom Chat |
| 147 | +
|
| 148 | + This command will overwrite the system prompt to let the bot behave differently. |
| 149 | +
|
| 150 | + # One-time Dialog |
| 151 | +
|
| 152 | + This command allows you to send a message to a temporary chat without opening the chat panel. |
| 153 | +
|
| 154 | + It is particularly useful for one-time commands, such as running a terminal command with `/run`. |
| 155 | +
|
| 156 | + For example, you can set the prompt to `/run open $FILE_PATH -a "Finder.app"` to reveal the active document in Finder. |
| 157 | + """) |
130 | 158 | } |
131 | 159 | } |
132 | 160 | } |
133 | 161 | } |
134 | 162 |
|
| 163 | +struct CustomCommandTypeDescription: View { |
| 164 | + let text: String |
| 165 | + var body: some View { |
| 166 | + ScrollView { |
| 167 | + Markdown(text) |
| 168 | + .lineLimit(nil) |
| 169 | + .markdownTheme( |
| 170 | + .gitHub |
| 171 | + .text { |
| 172 | + ForegroundColor(.secondary) |
| 173 | + BackgroundColor(.clear) |
| 174 | + FontSize(14) |
| 175 | + } |
| 176 | + .heading1 { conf in |
| 177 | + VStack(alignment: .leading, spacing: 0) { |
| 178 | + conf.label |
| 179 | + .relativePadding(.bottom, length: .em(0.3)) |
| 180 | + .relativeLineSpacing(.em(0.125)) |
| 181 | + .markdownMargin(top: 24, bottom: 16) |
| 182 | + .markdownTextStyle { |
| 183 | + FontWeight(.semibold) |
| 184 | + FontSize(.em(1.25)) |
| 185 | + } |
| 186 | + Divider() |
| 187 | + } |
| 188 | + } |
| 189 | + ) |
| 190 | + .padding() |
| 191 | + .background(Color.primary.opacity(0.02), in: RoundedRectangle(cornerRadius: 8)) |
| 192 | + .overlay { |
| 193 | + RoundedRectangle(cornerRadius: 8) |
| 194 | + .stroke(style: .init(lineWidth: 1)) |
| 195 | + .foregroundColor(Color(nsColor: .separatorColor)) |
| 196 | + } |
| 197 | + .padding() |
| 198 | + } |
| 199 | + } |
| 200 | +} |
| 201 | + |
135 | 202 | // MARK: - Previews |
136 | 203 |
|
137 | 204 | struct CustomCommandView_Preview: PreviewProvider { |
@@ -171,3 +238,32 @@ struct CustomCommandView_Preview: PreviewProvider { |
171 | 238 | } |
172 | 239 | } |
173 | 240 |
|
| 241 | +struct CustomCommandView_NoEditing_Preview: PreviewProvider { |
| 242 | + static var previews: some View { |
| 243 | + CustomCommandView( |
| 244 | + editingCommand: nil, |
| 245 | + settings: .init(customCommands: .init(wrappedValue: [ |
| 246 | + .init( |
| 247 | + commandId: "1", |
| 248 | + name: "Explain Code", |
| 249 | + feature: .chatWithSelection( |
| 250 | + extraSystemPrompt: nil, |
| 251 | + prompt: "Hello", |
| 252 | + useExtraSystemPrompt: false |
| 253 | + ) |
| 254 | + ), |
| 255 | + .init( |
| 256 | + commandId: "2", |
| 257 | + name: "Refactor Code", |
| 258 | + feature: .promptToCode( |
| 259 | + extraSystemPrompt: nil, |
| 260 | + prompt: "Refactor", |
| 261 | + continuousMode: false, |
| 262 | + generateDescription: true |
| 263 | + ) |
| 264 | + ), |
| 265 | + ], "CustomCommandView_Preview")) |
| 266 | + ) |
| 267 | + } |
| 268 | +} |
| 269 | + |
0 commit comments