telnet使用的文件格式是什么?

时间:2018-04-04 12:15:52

标签: sockets formatting telnet

我一直在构建一个telnet客户端,它可以成功地从服务器发送和接收消息。

但是,在接收数据时,由于文本格式化,输出无法正确显示。

Example output:

[2J[2;1H[2;1H[1;30;47mMain menu
[3;1H[0;37;40m1[3;3HStock[3;9HBooking
[4;1H[1;30;47m2 Despatch
[5;1H[0;37;40m3[5;3HProduction[5;14HIssues
[6;1H4[6;3HProduction[6;14HReturns
[7;1H5[7;3HVoid[7;8Hbatch
[8;1H6[8;3HArea[8;8HTransfer
[9;1H7[9;3HUnit[9;8HIssue
[10;1H8[10;3HOrder[10;9HLabel[10;15HPrint
[11;1H9[11;3HDry[11;7HGoods

[13;1H[1;30;47mPrt: <not set>[1;1H

I want it to look like this:
Main menu
1StockBooking
2Despatch
3ProductionIssues
4ProductionReturns
5Voidbatch
6AreaTransfer
7UnitIssue
8Order

LabelPrint9DryGoodsPrt: <not set>

关于这种格式使用的任何想法,所以我可以让一个库变成纯文本吗?

1 个答案:

答案 0 :(得分:0)

还有一些额外的格式,您无法直观地看到它使用不可打印的字符。你展示的文字实际上就是这样:

^[2J^[2;1H^[2;1H^[1;30;47mMain menu^
[3;1H^[0;37;40m1^[3;3HStock^[3;9HBooking^
[4;1H^[1;30;47m2 Despatch^
[5;1H^[0;37;40m3^[5;3HProduction^[5;14HIssues^
[6;1H4^[6;3HProduction^[6;14HReturns^
[7;1H5^[7;3HVoid^[7;8Hbatch^
[8;1H6^[8;3HArea^[8;8HTransfer^
[9;1H7^[9;3HUnit^[9;8HIssue^
[10;1H8^[10;3HOrder^[10;9HLabel^[10;15HPrint^
[11;1H9^[11;3HDry^[11;7HGoods^

[13;1H^[1;30;47mPrt: <not set>^[1;1H

(我正在使用^直观地向您显示0x1B字节 - ASCII ESC字符 - 存在于您发布的内容中。)

每个格式化命令都以ESC为前缀,后跟'['个字符和参数数据,然后是显示文字。

您发布的文字分解为以下顺序:

^[2J
^[2;1H
^[2;1H
^[1;30;47m
Main menu
^[3;1H
^[0;37;40m
1
^[3;3H
Stock
^[3;9H
Booking
^[4;1H
^[1;30;47m
2 Despatch
^[5;1H
^[0;37;40m
3
^[5;3H
Production
^[5;14H
Issues
^[6;1H
4
^[6;3H
Production
^[6;14H
Returns
^[7;1H
5
^[7;3H
Void
^[7;8H
batch
^[8;1H
6
^[8;3H
Area
^[8;8H
Transfer
^[9;1H
7
^[9;3H
Unit
^[9;8H
Issue
^[10;1H
8
^[10;3H
Order
^[10;9H
Label
^[10;15H
Print
^[11;1H
9
^[11;3H
Dry
^[11;7H
Goods
^[13;1H
^[1;30;47m
Prt: <not set>
^[1;1H

看到ESC参与其中,我找到了以下文章,完全与您发布的内容相符:

ANSI/VT100 Terminal Control Escape Sequences

最终细分如下:

Erase Screen
Cursor Home: Row=2, Column=1
Cursor Home: Row=2, Column=1
Set Attribute Mode: Bright, Foreground=Black, Background=White
Output: "Main menu"
Cursor Home: Row=3, Column=1
Set Attribute Mode: Reset, Foreground=White, Background=Black
Output: "1"
Cursor Home: Row=3, Column=3
Output: "Stock"
Cursor Home: Row=3, Column=9
Output: "Booking"
Cursor Home: Row=4, Column=1
Set Attribute Mode: Bright, Foreground=Black, Background=White
Output: "2 Despatch"
Cursor Home: Row=5, Column=1
Set Attribute Mode: Reset, Foreground=White, Background=Black
Output: "3"
Cursor Home: Row=5, Column=3
Output: "Production"
Cursor Home: Row=5, Column=14
Output: "Issues"
Cursor Home: Row=6, Column=1
Output: "4"
Cursor Home: Row=6, Column=3
Output: "Production"
Cursor Home: Row=6, Column=14
Output: "Returns"
Cursor Home: Row=7, Column=1
Output: "5"
Cursor Home: Row=7, Column=3
Output: "Void"
Cursor Home: Row=7, Column=8
Output: "batch"
Cursor Home: Row=8, Column=1
Output: "6"
Cursor Home: Row=8, Column=3
Output: "Area"
Cursor Home: Row=8, Column=8
Output: "Transfer"
Cursor Home: Row=9, Column=1
Output: "7"
Cursor Home: Row=9, Column=3
Output: "Unit"
Cursor Home: Row=9, Column=8
Output: "Issue"
Cursor Home: Row=10, Column=1
Output: "8"
Cursor Home: Row=10, Column=3
Output: "Order"
Cursor Home: Row=10, Column=9
Output: "Label"
Cursor Home: Row=10, Column=15
Output: "Print"
Cursor Home: Row=11, Column=1
Output: "9"
Cursor Home: Row=11, Column=3
Output: "Dry"
Cursor Home: Row=11, Column=7
Output: "Goods"
Cursor Home: Row=13, Column=1
Set Attribute Mode: Bright, Foreground=Black, Background=White
Output: "Prt: <not set>"
Cursor Home: Row=1, Column=1

在终端屏幕上打印时看起来像这样:

image