mirror of
https://github.com/Eugeny/tabby.git
synced 2024-09-21 01:47:28 +03:00
ignore stray tmux responses (fixes #178)
This commit is contained in:
parent
3ced784568
commit
ede59ed4d4
@ -5,6 +5,8 @@ import { ConnectableObservable, AsyncSubject, Subject } from 'rxjs'
|
|||||||
import * as childProcess from 'child_process'
|
import * as childProcess from 'child_process'
|
||||||
import { SessionOptions, SessionPersistenceProvider } from '../api'
|
import { SessionOptions, SessionPersistenceProvider } from '../api'
|
||||||
|
|
||||||
|
declare function delay (ms: number): Promise<void>
|
||||||
|
|
||||||
const TMUX_CONFIG = `
|
const TMUX_CONFIG = `
|
||||||
set -g status off
|
set -g status off
|
||||||
set -g focus-events on
|
set -g focus-events on
|
||||||
@ -97,7 +99,7 @@ export class TMuxCommandProcess {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
this.response$ = this.block$.skip(1).publish()
|
this.response$ = this.block$.publish()
|
||||||
this.response$.connect()
|
this.response$.connect()
|
||||||
|
|
||||||
this.block$.subscribe(block => {
|
this.block$.subscribe(block => {
|
||||||
@ -134,15 +136,23 @@ export class TMuxCommandProcess {
|
|||||||
|
|
||||||
export class TMux {
|
export class TMux {
|
||||||
private process: TMuxCommandProcess
|
private process: TMuxCommandProcess
|
||||||
|
private ready: Promise<void>
|
||||||
|
|
||||||
constructor () {
|
constructor () {
|
||||||
this.process = new TMuxCommandProcess()
|
this.process = new TMuxCommandProcess()
|
||||||
TMUX_CONFIG.split('\n').filter(x => x).forEach(async (line) => {
|
this.ready = (async () => {
|
||||||
|
for (let line of TMUX_CONFIG.split('\n')) {
|
||||||
|
if (line) {
|
||||||
await this.process.command(line)
|
await this.process.command(line)
|
||||||
})
|
}
|
||||||
|
}
|
||||||
|
// Tmux sometimes sends a stray response block at start
|
||||||
|
await delay(500)
|
||||||
|
})()
|
||||||
}
|
}
|
||||||
|
|
||||||
async create (id: string, options: SessionOptions): Promise<void> {
|
async create (id: string, options: SessionOptions): Promise<void> {
|
||||||
|
await this.ready
|
||||||
let args = [options.command].concat(options.args)
|
let args = [options.command].concat(options.args)
|
||||||
let cmd = args.map(x => `"${x.replace('"', '\\"')}"`)
|
let cmd = args.map(x => `"${x.replace('"', '\\"')}"`)
|
||||||
await this.process.command(
|
await this.process.command(
|
||||||
@ -153,11 +163,13 @@ export class TMux {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async list (): Promise<string[]> {
|
async list (): Promise<string[]> {
|
||||||
|
await this.ready
|
||||||
let block = await this.process.command('list-sessions -F "#{session_name}"')
|
let block = await this.process.command('list-sessions -F "#{session_name}"')
|
||||||
return block.lines
|
return block.lines
|
||||||
}
|
}
|
||||||
|
|
||||||
async getPID (id: string): Promise<number|null> {
|
async getPID (id: string): Promise<number|null> {
|
||||||
|
await this.ready
|
||||||
let response = await this.process.command(`list-panes -t ${id} -F "#{pane_pid}"`)
|
let response = await this.process.command(`list-panes -t ${id} -F "#{pane_pid}"`)
|
||||||
if (response.lines.length === 0) {
|
if (response.lines.length === 0) {
|
||||||
return null
|
return null
|
||||||
@ -167,6 +179,7 @@ export class TMux {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async terminate (id: string): Promise<void> {
|
async terminate (id: string): Promise<void> {
|
||||||
|
await this.ready
|
||||||
this.process.command(`kill-session -t ${id}`).catch(() => {
|
this.process.command(`kill-session -t ${id}`).catch(() => {
|
||||||
console.debug('Session already killed')
|
console.debug('Session already killed')
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user