Skip to content

Commit a1bc97c

Browse files
committed
monet-explorer cmd
1 parent b0ef3ee commit a1bc97c

File tree

3 files changed

+52
-40
lines changed

3 files changed

+52
-40
lines changed

protocol_doc/monet-explorer/CommandLine.hpp

Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
#include <ctype.h>
1919
#include <errno.h>
2020
#include <stdlib.h>
21+
#include <unistd.h>
2122
#include <string.h>
23+
#include <sys/ioctl.h>
2224
#include <cmath>
2325
#include <iostream>
2426
#include <string>
@@ -903,9 +905,11 @@ namespace CommandLine {
903905
* per columns between calls. Examples: bold, underline.
904906
* @param out The resulting characters will be appended to this
905907
* string stream.
908+
* @param breakAll Break text after every character.
909+
* For languages like Japanese and Chinese.
906910
*/
907-
inline void FormatLine(std::string &text, int &cursor, int limit, char softHypen,
908-
int &textAttribute, std::stringstream &out) {
911+
inline void FormatLine(const std::string &text, int &cursor, int limit, char softHypen,
912+
int &textAttribute, std::stringstream &out, bool breakAll) {
909913

910914
int length = text.length();
911915
int charCount = 0;
@@ -972,6 +976,32 @@ namespace CommandLine {
972976
continue;
973977
}
974978

979+
/*
980+
Check for VT100 escape sequences.
981+
Allow only text attributes: ESC[0m, ESC[1m, etc.
982+
Output them, but don't include them
983+
in the char count.
984+
*/
985+
if (c == '\033') {
986+
if (cursor + 3 < length) {
987+
if (text[cursor + 1] == '[' && text[cursor + 3] == 'm'
988+
&& text[cursor + 2] >= 48 && text[cursor + 2] <= 56
989+
&& text[cursor + 2] != 51 && text[cursor + 2] != 54) {
990+
991+
int value = text[cursor + 2] - 48;
992+
993+
if (!textAttributeWasSetInLastWord) {
994+
textAttribute = value;
995+
textAttributeWasSetInLastWord = true;
996+
}
997+
998+
lastWord << "\033[" << value << 'm';
999+
cursor += 3;
1000+
continue;
1001+
}
1002+
}
1003+
}
1004+
9751005
/*
9761006
Check if we reached the character limit
9771007
for the line if we include the current
@@ -998,7 +1028,7 @@ namespace CommandLine {
9981028
didn't fit into the allowed width, then
9991029
force "break all" behavior.
10001030
*/
1001-
if (lastWordPosition == 0) {
1031+
if (lastWordPosition == 0 || breakAll) {
10021032
out << lastWord.str();
10031033
charCount += lastWordCharCount;
10041034
return;
@@ -1011,7 +1041,7 @@ namespace CommandLine {
10111041
if (!beforeLastWordEndedInHyphen) {
10121042
/*
10131043
Output a dash for the soft hyphen only when
1014-
the word before the last word doesn't start
1044+
the word before the last word doesn't end
10151045
with a hyphen.
10161046
*/
10171047
out << '-';
@@ -1043,32 +1073,6 @@ namespace CommandLine {
10431073
continue;
10441074
}
10451075

1046-
/*
1047-
Check for VT100 escape sequences.
1048-
Allow only text attributes: ESC[0m, ESC[1m, etc.
1049-
Output them, but don't include them
1050-
in the char count.
1051-
*/
1052-
if (c == '\033') {
1053-
if (cursor + 3 < length) {
1054-
if (text[cursor + 1] == '[' && text[cursor + 3] == 'm'
1055-
&& text[cursor + 2] >= 48 && text[cursor + 2] <= 56
1056-
&& text[cursor + 2] != 51 && text[cursor + 2] != 54) {
1057-
1058-
int value = text[cursor + 2] - 48;
1059-
1060-
if (!textAttributeWasSetInLastWord) {
1061-
textAttribute = value;
1062-
textAttributeWasSetInLastWord = true;
1063-
}
1064-
1065-
lastWord << "\033[" << value << 'm';
1066-
cursor += 3;
1067-
continue;
1068-
}
1069-
}
1070-
}
1071-
10721076
/*
10731077
Check for word-breakers (non printable, space, soft hyphen)
10741078
*/
@@ -1148,7 +1152,10 @@ namespace CommandLine {
11481152
* @param argv Second parameter of the main function.
11491153
*/
11501154
Parser(int argc, char *argv[]) : argc(argc), argv(argv), accu(), Argument(accu) {
1151-
this->screenWidth = 80;
1155+
struct winsize size;
1156+
ioctl(STDOUT_FILENO, TIOCGWINSZ, &size);
1157+
1158+
this->screenWidth = std::max(std::min((int)size.ws_col - 1, 80), 10);
11521159
}
11531160

11541161
/**
@@ -1427,7 +1434,7 @@ namespace CommandLine {
14271434
}
14281435

14291436
/**
1430-
* @brief Wrap a text to the maximal width, to be
1437+
* @brief Wrap a text to the screen width, to be
14311438
* outputted on a terminal.
14321439
*
14331440
* @param text The text to be formatted.
@@ -1565,7 +1572,7 @@ namespace CommandLine {
15651572
terminated++;
15661573
} else {
15671574
this->FormatLine(texts[column], cursors[column], width[column], softHyphen,
1568-
textAttributes[column], buff);
1575+
textAttributes[column], buff, breakAll);
15691576
}
15701577

15711578
if (rightPaddings[column] > 0) {

protocol_doc/monet-explorer/README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ Arguments and options:
2424
--auth-algo, -a algo The hash algorithm to be used for the 'salted
2525
hashing'. The MonetDB server has to support it.
2626
This is typically a weaker hash algorithm,
27-
which is used together with a stronger 'pass-
27+
which is used together with the stronger 'pass-
2828
word hash' that is now SHA512. The currently
29-
supported values are: SHA1, SHA256, SHA512.
29+
supported values are: SHA1, SHA256, SHA512,
30+
RIPEMD160, SHA224, SHA384. Default is SHA1.
3031
3132
--file-transfer, -t Enable the file transfer protocol for the con-
3233
nection.
@@ -39,7 +40,8 @@ Arguments and options:
3940
--password, -P password User password for the database login. The de-
4041
fault value is 'monetdb'.
4142
42-
--port, -p port The port of the MonetDB server.
43+
--port, -p port The port of the MonetDB server. The default
44+
value is 50000.
4345
4446
--unix-domain-socket, -x Use a unix domain socket for connecting to the
4547
MonetDB server, instead of connecting through
@@ -48,12 +50,14 @@ Arguments and options:
4850
socket file with the proper name in the /tmp
4951
folder.
5052
51-
--user, -u user_name User name for the database login.
53+
--user, -u user_name User name for the database login. The default
54+
value is 'monetdb'.
5255
5356
5457
Positional operands:
5558
5659
1. database The name of the database to connect to.
60+
5761
```
5862

5963
# Build

protocol_doc/monet-explorer/main.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ int main(int argc, char *argv[]) {
2727

2828
cmd.Argument.String("host", 'h', "127.0.0.1", "host_name", "The host name or IP add|ress "
2929
"of the \033[1mMonetDB server\033[0m.");
30-
cmd.Argument.Int("port", 'p', 50000, "port", "The port of the \033[1mMonetDB server\033[0m."
31-
"The de-fault value is 50000.");
32-
cmd.Argument.String("user", 'u', "monetdb", "user_name", "User name for the database login.");
30+
cmd.Argument.Int("port", 'p', 50000, "port", "The port of the \033[1mMonetDB server\033[0m. "
31+
"The de|fault value is 50000.");
32+
cmd.Argument.String("user", 'u', "monetdb", "user_name", "User name for the database login. "
33+
"The de|fault value is 'monetdb'.");
3334
cmd.Argument.String("password", 'P', "monetdb", "password", "User password for the database login. "
3435
"The de|fault value is 'monetdb'.");
3536
cmd.Operand("database", "The name of the data|base to connect to.");

0 commit comments

Comments
 (0)