Skip to content

Commit b7fa5b4

Browse files
committed
feat: draw table for kvctl
1 parent a509cd1 commit b7fa5b4

File tree

7 files changed

+125
-11
lines changed

7 files changed

+125
-11
lines changed

.vscode/launch.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,26 @@
2525
}
2626
],
2727
},
28+
{
29+
"name": "kvctl",
30+
"type": "cppdbg",
31+
"request": "launch",
32+
"program": "${workspaceFolder}/build/kvctl",
33+
"args": ["--flagfile", "${workspaceFolder}/kvctl/config.flags"],
34+
"stopAtEntry": false,
35+
"cwd": "${workspaceFolder}",
36+
"environment": [],
37+
"externalConsole": false,
38+
"internalConsoleOptions": "neverOpen",
39+
"MIMode": "gdb",
40+
"miDebuggerPath": "/usr/bin/gdb",
41+
"setupCommands": [
42+
{
43+
"description": "Enable pretty-printing for gdb",
44+
"text": "-enable-pretty-printing",
45+
"ignoreFailures": false
46+
}
47+
],
48+
},
2849
]
2950
}

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"utility": "cpp",
4949
"string": "cpp",
5050
"shared_mutex": "cpp",
51-
"bitset": "cpp"
51+
"bitset": "cpp",
52+
"iomanip": "cpp"
5253
}
5354
}

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ then you can get `kvserver` and `kvclient`.
4242
./kvserver
4343
```
4444

45+
# Persistent data frame format
46+
![avatar](/images/dataframe.svg)
47+
4548
# About
4649
- This project is based on the gRPC framework to implement the memory-based KV cache middleware, which realizes the client and server respectively. Support list, string type KV cache, data snapshot and progressive Rehash.
4750

images/dataframe.svg

Lines changed: 4 additions & 0 deletions
Loading

kvctl/config.flags

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
--ip=43.143.229.22
2+
--key=qjx
3+
--operate=get

kvctl/draw_table.h

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#ifndef DRAW_TABLE_H
2+
#define DRAWTABLE_H
3+
#include <vector>
4+
#include <iostream>
5+
#include <iomanip>
6+
void drawLine(std::vector<int>& max,int columns) { //画行线
7+
for (int i = 0; i < columns; i++) {
8+
std::cout << "+-";
9+
for (int j = 0; j <= max[i]; j++) {
10+
std::cout << '-';
11+
}
12+
}
13+
std::cout << '+' << std::endl;
14+
}
15+
16+
void drawDatas(std::vector<int>& max, std::vector<std::vector<std::string>>& Str,
17+
std::vector<std::string>& D,int columns,int row) { //显示构造过程,状态转换矩阵
18+
drawLine(max,columns);
19+
for (int i = 0; i < D.size(); i++) {
20+
std::cout << "| " << std::setw(max[i]) << std::setiosflags(std::ios::left) << std::setfill(' ') << D[i] << ' ';
21+
}
22+
std::cout << '|' << std::endl;
23+
drawLine(max, columns);
24+
for (int i = 0; i < row; i++) {
25+
for (int j = 0; j < columns; j++) {
26+
std::cout << "| " << std::setw(max[j]) << std::setiosflags(std::ios::left) << std::setfill(' ');
27+
std::cout << Str[i][j] << ' ';
28+
}
29+
std::cout << '|'<< std::endl;
30+
}
31+
drawLine(max, columns);
32+
}
33+
34+
void maxLenForEveryCol(std::vector<std::vector<std::string>>& datas, std::vector<int>& maxLen) {
35+
if (datas.empty()) return;
36+
maxLen.resize(datas[0].size());
37+
for (int i = 0; i < datas[0].size(); ++i) {
38+
for (int j = 0; j < datas.size(); ++j) {
39+
if (datas[j][i].size() > maxLen[i]) {
40+
maxLen[i] = datas[j][i].size();
41+
}
42+
}
43+
44+
}
45+
return;
46+
}
47+
48+
#endif

0 commit comments

Comments
 (0)