Skip to content

Commit

Permalink
feat: 🎸 shell option
Browse files Browse the repository at this point in the history
  • Loading branch information
ZingerLittleBee committed Oct 6, 2023
1 parent f32f39f commit 4ca4e14
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
1 change: 1 addition & 0 deletions view/src/routes/settings/terminal/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export const cursorStyleOptions = ['block', 'underline', 'bar']
export const terminalFormSchema = z.object({
copyOnSelect: z.boolean(),
cursorBlink: z.boolean(),
shell: z.string().optional(),
cursorStyle: z.enum(cursorStyleOptions as [string, ...string[]]).optional(),
fontSize: z.number().min(4).max(40),
fontFamily: z.string().optional(),
Expand Down
21 changes: 20 additions & 1 deletion view/src/routes/settings/terminal/terminal-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export function TerminalForm({
if (form.formState.isDirty) return
form.setValue('copyOnSelect', terminalSettings?.copyOnSelect ?? true)
form.setValue('cursorBlink', terminalSettings?.cursorBlink ?? true)
form.setValue('shell', terminalSettings?.shell)
form.setValue('cursorStyle', terminalSettings?.cursorStyle)
form.setValue('fontSize', terminalSettings?.fontSize ?? 14)
form.setValue('fontFamily', terminalSettings?.fontFamily)
Expand Down Expand Up @@ -255,6 +256,25 @@ export function TerminalForm({
</FormItem>
)}
/>
<FormField
control={form.control}
name="shell"
render={({ field }) => (
<FormItem>
<FormLabel>Shell</FormLabel>
<FormControl>
<Input
placeholder="default system shell"
{...field}
/>
</FormControl>
<FormDescription>
shell name or path
</FormDescription>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="fontFamily"
Expand All @@ -271,7 +291,6 @@ export function TerminalForm({
</FormItem>
)}
/>

<FormField
control={form.control}
name="background"
Expand Down
7 changes: 5 additions & 2 deletions view/src/routes/terminal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ export default function TerminalPage() {

useEffect(() => {
if (!terminalDivRef.current) return
const webSocket = new WebSocket(`${wsBaseUrl()}/pty?shell=zsh`)
const url = terminalSettings.shell
? `${wsBaseUrl()}/pty?shell=${terminalSettings.shell}`
: `${wsBaseUrl()}/pty`
const webSocket = new WebSocket(url)
webSocket.binaryType = 'arraybuffer'
const terminal = new Terminal({
cursorBlink: terminalSettings?.cursorBlink,
Expand Down Expand Up @@ -87,7 +90,7 @@ export default function TerminalPage() {

webSocket.onclose = (reason) => {
terminalRef.current?.write(
'\r\nConnection closed. Please press Enter try reconnect \r\n'
'\r\nConnection closed. Please \x1b[33mPress Enter\x1b[0m or \x1b[33mRefresh the Page\x1b[0m to attempt reconnection. \r\n'
)
console.log('WebSocket closed', reason)
}
Expand Down
1 change: 1 addition & 0 deletions view/src/types/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export type ServerConfigVo = Omit<ServerConfig, 'disable_ssl'> & {
}

export type TerminalSettings = {
shell?: string
copyOnSelect?: boolean
fontSize?: number
fontFamily?: string
Expand Down

0 comments on commit 4ca4e14

Please sign in to comment.