Commit 297d1efa authored by Isabella Skořepová's avatar Isabella Skořepová
Browse files

Fix read in interactive mode

parent dd44fe48
......@@ -38,9 +38,10 @@ public class ReadCommand : Object, Command
p.reload_properties();
}
var display_fields = "Xc";
if(other_args.length >= (state.bound_port==null?2:1)){
if(other_args.length >= (state.bound_port==null?2:1)) {
display_fields = other_args[state.bound_port==null?1:0];
}
// format string
if(!display_fields.is_ascii()) return error(Err.NOT_ASCII_FORMAT_STRING);
FormatWrapper[] printers = new FormatWrapper[display_fields.char_count()];
......@@ -53,7 +54,7 @@ public class ReadCommand : Object, Command
if(other_args.length >= (state.bound_port==null?3:2)) {
print_length = int.parse(other_args[state.bound_port==null?2:1]);
if(print_length <= 0) return error(Err.NEGATIVE_LENGTH);
}else{
} else {
int rows;
int cols;
Readline.get_screen_size(out rows, out cols);
......@@ -79,13 +80,19 @@ public class ReadCommand : Object, Command
p.open();
});
p.data_recieved.connect((array) => {
ulong connection = p.data_recieved.connect((array) => {
for(int i = 0; i < array.length; i++) {
// For each char
uint8[1] onebuf = new uint8[1];
// Print it using first printer
onebuf[0] = array[i];
printers[0].a(onebuf);
stdout.flush();
// Save it
tmpbuf[counter++] = array[i];
stdout.flush();
if(counter >= print_length) {
for(int x = 1; x < printers.length; x++) {
stdout.printf(" ");
......@@ -102,6 +109,7 @@ public class ReadCommand : Object, Command
};
Posix.sigaction(Posix.SIGINT,action,null);
loop.run();
p.disconnect(connection);
stdout.printf("\n");
var dflact = Posix.sigaction_t();
Posix.sigaction(Posix.SIGINT,dflact,null);
......@@ -147,13 +155,23 @@ public class ReadCommand : Object, Command
}
};
fw.width_per_char = 4;
} else if(c == "s".get_char(0) ||
c == "c".get_char(0)) {
} else if(c == "c".get_char(0)) {
fw.a = (a) => {
for(int x = 0; x < a.length; x++) {
if(a[x]>=32&&a[x]<127){
stdout.printf("%c", a[x]);
}else if(c == "s".get_char(0)) {
} else {
stdout.printf(".");
}
}
};
fw.width_per_char = 1;
} else if(c == "s".get_char(0)) {
fw.a = (a) => {
for(int x = 0; x < a.length; x++) {
if(a[x]>=32&&a[x]<127){
stdout.printf("%c", a[x]);
} else {
if(a[x] == 10) { // \n (LF)
stdout.printf("\n");
} else if(a[x] == 13) { // \r (CR)
......@@ -162,8 +180,6 @@ public class ReadCommand : Object, Command
} else {
stdout.printf(".");
}
} else {
stdout.printf(".");
}
}
};
......@@ -202,12 +218,12 @@ public class ReadCommand : Object, Command
stdout.printf("Synopsis: read <port> [format-string] [format-length]\n");
stdout.printf("Reads from port\n");
stdout.printf("Format string consists of (one or more) folowing letters:\n");
stdout.printf(" X\tprints hexadecimal numbers (uppercase)\n");
stdout.printf(" x\tprints hexadecimal numbers (lowercase)\n");
stdout.printf(" c\tprints characters, nonprintable chars are replaced with dot\n");
stdout.printf(" s\tsame as c but also prints \\n as newline and \\t as tab and ignores \\r\n");
stdout.printf(" d\tprints decimal numbers (i is same)\n");
stdout.printf(" b\tprints binary representation\n");
stdout.printf(" X prints hexadecimal numbers (uppercase)\n");
stdout.printf(" x prints hexadecimal numbers (lowercase)\n");
stdout.printf(" c prints characters, nonprintable chars are replaced with dot\n");
stdout.printf(" s same as c but also prints \\n as newline and \\t as tab and ignores \\r\n");
stdout.printf(" d prints decimal numbers (i is same)\n");
stdout.printf(" b prints binary representation\n");
stdout.printf(" Default value is Xc\n");
stdout.printf("Format length specifies number of characters per line\n");
stdout.printf("Default is determined automagically from terminal width\n");
......
......@@ -150,7 +150,7 @@ private class PropertiesAccessor : GLib.Object {
}
}
public class SerialClient {
public class SerialClient : GLib.Object {
PropertiesAccessor properties;
Methods methods;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment