It is used by BFS to tell TUI how to display content, and TUI to tell BFS what instructions to execute.
dataHeader-dataBody-dataEnd
dataHeader
header informationdataBody
data bodydataEnd
data end information\r\n\r\n
to separatedataHeader
Description:COMMANDER BTP/1.0.0
is used to define that the current message is a commander
command; the message adopts the BTP/1.0.0
standard;application/json
| text/plain
| text/html
[application/json supported in the initial stage]utf8
commander
| post
commander
command callpost
to pass datadataBody
description:{
// Types of
type: "input" | "res",
// associated commandID
mateCommandID:number
// tui current status description
// WATI_RES waiting for the command message to return
// INTPUT_SINGLE_LINE enter the normal input mode
// INPUT_MULTI_LINE enters multi-line input mode
// INPUT_EDIT_FILE enter the edit file mode
tuiState: "WATI_RES" | "INTPUT_SINGLE_LINE" | "INPUT_MULTI_LINE" | "INPUT_EDIT_FILE",
// Menu list
// tuiState === INPUT_MULTI_LINE requires menu attribute
menu?: string[],
// The content of the text that needs to be edited
// tuiState === INPUT_EDIT_file requires body attribute;
body: string;
// message body
body: {
// Level-reference value of left margin
level: number;
// Whether it is bold
isBlod: boolean;
// Whether it is a space placeholder, such as true ===, the content of content will be ignored;
isSpace: boolean;
// Whether the block-level element true === occupies a line by itself false === will occupy the same line as the flying block-level elements before and after;
isBlock: boolean;
// text color
color:'red' |'blue' |'grey' |'yellow' |'white';
// text content
content: string | Array<Array<string>>,
// Define the type of data passed
type:'string' |'arrayT';
}
}
dataEnd
The end information of the data:--------end
| --------inc
--------end
=== The current dataBody
is a complete data;--------inc
=== The current dataBody
is a partial data;Original format: COMMANDER\0BTP/1.0.0\r\ncontent-type:application/json\r\ncharset:utf8\r\n\r\n{\r\n"type": "res",\ r\n"body":{\r\n"level":0,"isBlod":true\r\n}\r\n}\r\n\r\r\n--------end
format:
COMMANDER BTP/1.0.0
content-type:application/json
charset:utf8
method:commander
{
"type": "res",
"body": {
"level":0,
"isBlod:true
}
}
--------end
Description:
// dataHeader
// Message protocol
COMMANDER BTP/1.0.0
// dataBody format
content-type:application/json
// Character set used by dataBody
charset:utf8
// dataBody
{
"type": "res",
"body": {
"level":0,
"isBlod:true
}
}
// dataEnd
--------end
BFS-TUI communication protocol generation and analysis tool [bfsprocess.import('bfs').BTPTools]
BTPTools.parseHead(commandMessage: string): {[key: string]: string}
Parameter Description:
Protocol sent by commandMessage Tui
Description: Parse the header information of the command message
const commandMessage = `COMMANDER BTP/1.0.0
content-type:applicationjson
charset:utf-8
method:commander
{"type":"string","commandID":161173507822,"body":"core help"}
--------end`
const head = BTPTools.parseHead(commandMessage)
operation result:
{
protocol: "COMMANDERBTP/1.0.0 ",
content-type: "application/json",
charset: "utf8",
method: "commander"
}
BTPTools.parseBodyByBTPString(commandMessage: string): {[key: string]: string}
Parameter Description:
Protocol sent by commandMessage Tui
Description: Analyze the body information of the command message
const commandMessage = `COMMANDER BTP/1.0.0
content-type:applicationjson
charset:utf-8
method:commander
{"type":"string","commandID":161173507822,"body":"core help"}
--------end`
const body = BTPTools.parseBodyByBTPString(commandMessage)
operation result:
{
body: "core help"
commandID: 1611735078633
type: "string"
}
BTPTools.parseCommandIDByCommandMessage(commandMessage: string): number
Protocol sent by commandMessage Tui
Description: Parse the commandID from the command message
const commandMessage = `COMMANDER BTP/1.0.0
content-type:applicationjson
charset:utf-8
method:commander
{"type":"string","commandID":161173507822,"body":"core help"}
--------end`
const commandID = BTPTools.parseCommandIDByCommandMessage(commandMessage)
operation result:
161173507822
BTPTools.createResMessageNormal(content: string, commandID: number, level: number): string
Parameter Description:
content The content that needs to be sent to TUI to display
commandID matching command ID
level The level of the content, the left blank is determined according to the level
Description: The protocol for generating normal return messages
BTPTools.createResMessageNormal("Test Text", 1111111, 0)
operation result:
`COMMANDER BTP/1.0.0
content-type:applicationjson
charset:utf-8
method:commander
{"type":"string","mateCommandID":1111111,"body":{"level":0,"isBlod":false,"isSpace":false,"isBlock":true,"color":"white ","conent":"test text","type":"string"}}
--------end`
BTPTools.createResMessageNormalErr(content: string, commandID: number): string
Parameter Description:
content The content that needs to be sent to TUI to display
commandID matching command ID
Description: Generate a return message protocol for common error types
BTPTools.createResMessageNormalErr("error message", 1111111)
operation result:
`COMMANDER BTP/1.0.0
content-type:applicationjson
charset:utf-8
method:commander
{"type":"string","mateCommandID":1111111,"body":{"level":0,"isBlod":false,"isSpace":false,"isBlock":true,"color":"red ","conent":"error message","type":"string"}}
--------end`
BTPTools.createResMessageLoading(commandID: number): string
Parameter Description:
commandID matching command ID
Description: Generate a return message protocol for loading status
BTPTools.createResMessageLoading(1111111)
operation result:
`COMMANDER BTP/1.0.0
content-type:applicationjson
charset:utf-8
method:commander
{"type":"string","mateCommandID":1111111,"body":{"level":0,"isBlod":false,"isSpace":false,"isBlock":false,"color":"white ","conent":"-","type":"string"}}
--------end`
BTPTools.createResMessageTable(conent: string[][], commandID: number): string
Parameter Description:
content The content that needs to be sent to TUI to display
commandID matching command ID
Description: Generate the return information protocol of the form type
BTPTools.createResMessageTable([["name","age"],["bill",10]],1111111)
operation result:
`COMMANDER BTP/1.0.0
content-type:applicationjson
charset:utf-8
method:commander
{"type":"string","mateCommandID":1111111,"body":{"level":0,"isBlod":false,"isSpace":false,"isBlock":true,"color":"white ","conent":[["name","age"],["bill",10]],"type":"arrayT"}}
--------end`
BTPTools.createEntryInputStateNormalProtocol(commandID: number): string
Parameter Description:
commandID matching command ID
Description: Generate a protocol to make TUI enter the normal input mode
BTPTools.createEntryInputStateNormalProtocol(1111111)
operation result:
`COMMANDER BTP/1.0.0
content-type:applicationjson
charset:utf-8
method:commander
{"type":"input","mateCommandID":1111111,"tuiState":"INTPUT_SINGLE_LINE"}}
--------end`
instruction manual: