Implement rj ##json (#17443)

This commit is contained in:
Aswin C 2020-09-17 21:40:07 +05:30 committed by GitHub
parent 17a1cf6a77
commit 549784d73f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -268,6 +268,7 @@ static const char *help_msg_k[] = {
static const char *help_msg_r[] = {
"Usage:", "r[+-][ size]", "Resize file",
"r", "", "display file size",
"rj", "", "display the file size in JSON format",
"r", " size", "expand or truncate file to given size",
"r-", "num", "remove num bytes, move following data down",
"r+", "num", "insert num bytes, move following data up",
@ -1823,6 +1824,18 @@ static int cmd_resize(void *data, const char *input) {
}
}
return true;
case 'j': { // "rj"
PJ * pj = pj_new ();
pj_o (pj);
if (oldsize != -1) {
pj_kn (pj, "size", oldsize);
}
pj_end (pj);
char *s = pj_drain (pj);
r_cons_println (s);
free (s);
break;
}
case 'h':
if (core->file) {
if (oldsize != -1) {