import { Requester } from "./requester" ; import { ArgParser } from "./info" ; import { LayoutParser } from "./layout" ; import { Buffers } from "./buffers" ; import { Completer } from "./complete" ; import { Direction } from "./direction" ; export class Ctrlb { constructor ( protected readonly requester , protected readonly argParser , protected readonly layoutParser , protected readonly buffers , protected readonly completer ) { } public async requestAsync ( arg ) { const actionInfo = this . argParser . parse ( arg ) ; this . requester . executeAsync ( actionInfo ) ; return ; } public async open ( bufferType ) { if ( ! this . argParser . isBufferType ( bufferType ) ) { throw new Error ( "Inavalid bufferType: " + bufferType ) ; } const buffer = this . buffers . get ( bufferType ) ; await buffer . open ( Direction . TAB ) ; } public async openLayout ( jsonFilePath ) { const layoutInfo = this . argParser . parseJsonFile ( jsonFilePath ) ; const layoutItem = this . layoutParser . parse ( layoutInfo , null ) ; await layoutItem . openLayout ( ) ; } public async doAction ( bufferType , actionName , firstLine , lastLine ) { if ( ! this . argParser . isBufferType ( bufferType ) ) { throw new Error ( "Inavalid bufferType: " + bufferType ) ; } const buffer = this . buffers . get ( bufferType ) ; await buffer . doAction ( actionName , firstLine , lastLine ) ; } public async clearAll ( ) { await this . buffers . clearAll ( ) ; } public async complete ( currentArg , line , cursorPosition ) { return this . completer . complete ( currentArg , line , cursorPosition ) ; } }