tabby/tabby-telnet/src/profiles.ts

67 lines
2.0 KiB
TypeScript
Raw Normal View History

2021-07-04 22:48:48 +08:00
import { Injectable } from '@angular/core'
import { ProfileProvider, Profile, NewTabParameters } from 'tabby-core'
import { TelnetProfileSettingsComponent } from './components/telnetProfileSettings.component'
import { TelnetTabComponent } from './components/telnetTab.component'
import { TelnetProfile } from './session'
@Injectable({ providedIn: 'root' })
export class TelnetProfilesService extends ProfileProvider {
id = 'telnet'
name = 'Telnet'
2021-07-06 04:52:32 +08:00
supportsQuickConnect = false
2021-07-04 22:48:48 +08:00
settingsComponent = TelnetProfileSettingsComponent
async getBuiltinProfiles (): Promise<TelnetProfile[]> {
return [{
id: `telnet:template`,
type: 'telnet',
name: 'Telnet/socket connection',
icon: 'fas fa-network-wired',
options: {
host: '',
port: 23,
inputMode: 'readline',
2021-07-04 22:48:48 +08:00
outputMode: null,
inputNewlines: null,
outputNewlines: 'crlf',
},
isBuiltin: true,
isTemplate: true,
}]
}
async getNewTabParameters (profile: Profile): Promise<NewTabParameters<TelnetTabComponent>> {
return {
type: TelnetTabComponent,
inputs: { profile },
}
}
getDescription (profile: TelnetProfile): string {
return profile.options.host ? `${profile.options.host}:${profile.options.port}` : ''
}
2021-07-06 04:52:32 +08:00
quickConnect (query: string): TelnetProfile {
2021-07-04 22:48:48 +08:00
let host = query
let port = 23
if (host.includes('[')) {
port = parseInt(host.split(']')[1].substring(1))
host = host.split(']')[0].substring(1)
} else if (host.includes(':')) {
port = parseInt(host.split(/:/g)[1])
host = host.split(':')[0]
}
return {
name: query,
type: 'telnet',
options: {
host,
port,
inputMode: 'readline',
2021-07-04 22:48:48 +08:00
outputNewlines: 'crlf',
},
}
}
}