open SFTP panel in the CWD

This commit is contained in:
Eugene Pankov
2021-07-24 09:44:47 +02:00
parent 7fa29b4b37
commit a2e0db2a16
14 changed files with 94 additions and 47 deletions

View File

@@ -268,16 +268,17 @@ export class BaseTerminalTabComponent extends BaseTabComponent implements OnInit
break
}
})
this.bellPlayer = document.createElement('audio')
this.bellPlayer.src = require('../bell.ogg').default
this.contextMenuProviders.sort((a, b) => a.weight - b.weight)
this.pinToolbar = this.enableToolbar && (window.localStorage.pinTerminalToolbar ?? 'true') === 'true'
}
/** @hidden */
ngOnInit (): void {
this.pinToolbar = this.enableToolbar && (window.localStorage.pinTerminalToolbar ?? 'true') === 'true'
this.focused$.subscribe(() => {
this.configure()
this.frontend?.focus()

View File

@@ -0,0 +1,37 @@
import * as os from 'os'
import { Subject, Observable } from 'rxjs'
const OSC1337Prefix = Buffer.from('\x1b]1337;')
const OSC1337Suffix = Buffer.from('\x07')
export class OSC1337Processor {
get cwdReported$ (): Observable<string> { return this.cwdReported }
private cwdReported = new Subject<string>()
process (data: Buffer): Buffer {
if (data.includes(OSC1337Prefix)) {
const preData = data.subarray(0, data.indexOf(OSC1337Prefix))
const params = data.subarray(data.indexOf(OSC1337Prefix) + OSC1337Prefix.length)
const postData = params.subarray(params.indexOf(OSC1337Suffix) + OSC1337Suffix.length)
const paramString = params.subarray(0, params.indexOf(OSC1337Suffix)).toString()
if (paramString.startsWith('CurrentDir=')) {
let reportedCWD = paramString.split('=')[1]
if (reportedCWD.startsWith('~')) {
reportedCWD = os.homedir() + reportedCWD.substring(1)
}
this.cwdReported.next(reportedCWD)
} else {
console.debug('Unsupported OSC 1337 parameter:', paramString)
}
data = Buffer.concat([preData, postData])
}
return data
}
close (): void {
this.cwdReported.complete()
}
}

View File

@@ -3,6 +3,9 @@ import { ConfigProvider, Platform } from 'tabby-core'
/** @hidden */
export class TerminalConfigProvider extends ConfigProvider {
defaults = {
hotkeys: {
'copy-current-path': [],
},
terminal: {
frontend: 'xterm',
fontSize: 14,

View File

@@ -27,7 +27,7 @@ import { PathDropDecorator } from './features/pathDrop'
import { ZModemDecorator } from './features/zmodem'
import { TerminalConfigProvider } from './config'
import { TerminalHotkeyProvider } from './hotkeys'
import { CopyPasteContextMenu, LegacyContextMenu } from './tabContextMenu'
import { CopyPasteContextMenu, MiscContextMenu, LegacyContextMenu } from './tabContextMenu'
import { hterm } from './frontends/hterm'
import { Frontend } from './frontends/frontend'
@@ -56,6 +56,7 @@ import { TerminalCLIHandler } from './cli'
{ provide: TerminalDecorator, useClass: DebugDecorator, multi: true },
{ provide: TabContextMenuItemProvider, useClass: CopyPasteContextMenu, multi: true },
{ provide: TabContextMenuItemProvider, useClass: MiscContextMenu, multi: true },
{ provide: TabContextMenuItemProvider, useClass: LegacyContextMenu, multi: true },
{ provide: CLIHandler, useClass: TerminalCLIHandler, multi: true },
@@ -119,5 +120,6 @@ export { BaseTerminalTabComponent } from './api/baseTerminalTab.component'
export * from './api/interfaces'
export * from './api/streamProcessing'
export * from './api/loginScriptProcessing'
export * from './api/osc1337Processing'
export * from './session'
export { LoginScriptsSettingsComponent, StreamProcessingSettingsComponent }

View File

@@ -1,6 +1,7 @@
import { Observable, Subject } from 'rxjs'
import { Logger } from 'tabby-core'
import { LoginScriptProcessor, LoginScriptsOptions } from './api/loginScriptProcessing'
import { OSC1337Processor } from './api/osc1337Processing'
/**
* A session object for a [[BaseTerminalTabComponent]]
@@ -14,6 +15,8 @@ export abstract class BaseSession {
protected closed = new Subject<void>()
protected destroyed = new Subject<void>()
protected loginScriptProcessor: LoginScriptProcessor | null = null
protected reportedCWD?: string
protected osc1337Processor = new OSC1337Processor()
private initialDataBuffer = Buffer.from('')
private initialDataBufferReleased = false
@@ -22,9 +25,14 @@ export abstract class BaseSession {
get closed$ (): Observable<void> { return this.closed }
get destroyed$ (): Observable<void> { return this.destroyed }
constructor (protected logger: Logger) { }
constructor (protected logger: Logger) {
this.osc1337Processor.cwdReported$.subscribe(cwd => {
this.reportedCWD = cwd
})
}
emitOutput (data: Buffer): void {
data = this.osc1337Processor.process(data)
if (!this.initialDataBufferReleased) {
this.initialDataBuffer = Buffer.concat([this.initialDataBuffer, data])
} else {
@@ -56,6 +64,7 @@ export abstract class BaseSession {
this.destroyed.next()
await this.gracefullyKillProcess()
}
this.osc1337Processor.close()
this.closed.complete()
this.destroyed.complete()
this.output.complete()

View File

@@ -39,6 +39,22 @@ export class CopyPasteContextMenu extends TabContextMenuItemProvider {
}
}
/** @hidden */
@Injectable()
export class MiscContextMenu extends TabContextMenuItemProvider {
weight = 1
async getItems (tab: BaseTabComponent): Promise<MenuItemOptions[]> {
if (tab instanceof BaseTerminalTabComponent && tab.session?.supportsWorkingDirectory()) {
return [{
label: 'Copy current path',
click: () => tab.copyCurrentPath(),
}]
}
return []
}
}
/** @hidden */
@Injectable()
export class LegacyContextMenu extends TabContextMenuItemProvider {