Skip to content

Commit

Permalink
initial alpha version of sheet (#201)
Browse files Browse the repository at this point in the history
* initial alpha version of `sheet`
  • Loading branch information
liquidaty authored Oct 3, 2024
1 parent 0f9e186 commit 9c5f13d
Show file tree
Hide file tree
Showing 15 changed files with 1,138 additions and 16 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ The ZSV CLI can be compiled to virtually any target, including
direct CSV `sql`, `flatten`, `serialize`, `2json` conversion, `2db` sqlite3
conversion, `stack`, `pretty`, `2tsv`, `compare`, `paste` and more.

The ZSV CLI also includes `sheet`, an in-console interactive grid viewer
that can be extended with your custom code for manipulating and viewing data.

Pre-built CLI packages are available via `brew` and `nuget`.

A pre-built library package is available for Node (`npm install zsv-lib`).
Expand Down Expand Up @@ -94,6 +97,7 @@ that implements the expected
- Easy to use as a library in a few lines of code, via either pull or push
parsing
- Includes the `zsv` CLI with the following built-in commands:
- `sheet`, an in-console interactive and extendable grid viewer
- `select`, `count`, `sql` query, `desc`ribe, `flatten`, `serialize`, `2json`,
`2db`, `stack`, `pretty`, `2tsv`, `paste`, `compare`, `jq`, `prop`, `rm`
- easily [convert between CSV/JSON/sqlite3](docs/csv_json_sqlite.md)
Expand Down Expand Up @@ -244,6 +248,7 @@ needs.

`zsv` comes with several built-in commands:

- `sheet`: an in-console, interactive grid viewer
- `echo`: read CSV from stdin and write it back out to stdout. This is mostly
useful for demonstrating how to use the API and also how to create a plug-in,
and has several uses beyond that including adding/removing BOM, cleaning up
Expand Down
15 changes: 11 additions & 4 deletions app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,13 @@ ifeq ($(WIN),0)
CFLAGS_EXE+= -s USE_PTHREADS=1 -s PTHREAD_POOL_SIZE=2 -s PTHREAD_POOL_SIZE=8
endif
endif
CFLAGS_SETENV=
else
BUILD_SUBDIR=win/${DBG_SUBDIR}
EXE=.exe
CFLAGS+= -D__USE_MINGW_ANSI_STDIO -D_ISOC99_SOURCE
CFLAGS+= -D__USE_MINGW_ANSI_STDIO -D_ISOC99_SOURCE -D_GNU_SOURCE
CFLAGS+= -Wl,--strip-all
CONFIGURE_HOST=x86_64-w64-mingw32
CFLAGS_SETENV=-Dsetenv\(a,b,c\)=_putenv_s\(a,b\)
CFLAGS+=-Dsetenv\(a,b,c\)=_putenv_s\(a,b\)
endif

JQ_CONFIGURE_HOST=
Expand Down Expand Up @@ -188,6 +187,14 @@ ZSV=$(BINDIR)/zsv${EXE}
SOURCES= echo paste count count-pull select select-pull 2tsv 2json serialize flatten pretty stack desc sql 2db compare prop rm mv jq
CLI_SOURCES=echo select desc count paste 2tsv pretty sql flatten 2json serialize stack 2db compare prop rm mv jq

ifeq ($(ZSV_BUILD_SHEET),1)
SOURCES+=sheet
CLI_SOURCES+=sheet
CFLAGS+=-DZSV_BUILD_SHEET
CFLAGS+=${CFLAGS_NCURSES}
LDFLAGS+=${LDFLAGS_NCURSES}
endif

CFLAGS+= -DUSE_JQ

STATIC_LIB_FLAGS=
Expand Down Expand Up @@ -398,7 +405,7 @@ lib-jq: ${JQ_LIB}

${JQ_BUNDLE_LIB}: ${JQ_SRC} # -D_REENTRANT needed for clang to not break
cd ${JQ_SRC} \
&& CC="${CC}" CFLAGS="${CFLAGS} -D_REENTRANT ${CFLAGS_SETENV}" ./configure \
&& CC="${CC}" CFLAGS="${CFLAGS} -D_REENTRANT" ./configure \
--prefix="${JQ_PREFIX}" \
--disable-maintainer-mode \
--without-oniguruma \
Expand Down
6 changes: 6 additions & 0 deletions app/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ ZSV_MAIN_DECL(desc);
ZSV_MAIN_DECL(sql);
ZSV_MAIN_DECL(2db);
ZSV_MAIN_DECL(compare);
#ifdef ZSV_BUILD_SHEET
ZSV_MAIN_DECL(sheet);
#endif
ZSV_MAIN_DECL(echo);
ZSV_MAIN_NO_OPTIONS_DECL(prop);
ZSV_MAIN_NO_OPTIONS_DECL(rm);
Expand Down Expand Up @@ -108,6 +111,9 @@ struct builtin_cmd builtin_cmds[] = {
CLI_BUILTIN_COMMAND(sql),
CLI_BUILTIN_COMMAND(2db),
CLI_BUILTIN_COMMAND(compare),
#ifdef ZSV_BUILD_SHEET
CLI_BUILTIN_COMMAND(sheet),
#endif
CLI_BUILTIN_COMMAND(echo),
CLI_BUILTIN_NO_OPTIONS_COMMAND(prop),
CLI_BUILTIN_NO_OPTIONS_COMMAND(rm),
Expand Down
1 change: 0 additions & 1 deletion app/cli_ini.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* This file is part of zsv/lib, distributed under the license defined at
* https://opensource.org/licenses/MIT
*/

#include <zsv/utils/string.h>
#include <zsv/utils/os.h>
#include <zsv/utils/dirs.h>
Expand Down
7 changes: 3 additions & 4 deletions app/select.c
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,6 @@ int ZSV_MAIN_FUNC(ZSV_COMMAND)(int argc, const char *argv[], struct zsv_opts *op
return zsv_status_ok;
}

int err = 0;
char fixed_auto = 0;
struct zsv_select_data data = {0};
data.opts = opts;
Expand Down Expand Up @@ -863,9 +862,9 @@ int ZSV_MAIN_FUNC(ZSV_COMMAND)(int argc, const char *argv[], struct zsv_opts *op
else
data.sample_pct = d;
} else if (!strcmp(argv[arg_i], "--prepend-header")) {
int err = 0;
data.prepend_header = zsv_next_arg(++arg_i, argc, argv, &err);
if (err)
int err1 = 0;
data.prepend_header = zsv_next_arg(++arg_i, argc, argv, &err1);
if (err1)
stat = zsv_status_error;
} else if (!strcmp(argv[arg_i], "--no-header"))
data.no_header = 1;
Expand Down
Loading

0 comments on commit 9c5f13d

Please sign in to comment.