clicon/clixon

beautiful configuration display

Closed this issue · 2 comments

@olofhagsand Is there a function cli_show_common have you considered displaying the configuration using less, for example, so that a search is available?

example

int pipefd[2];
pipe(pipefd);

pid_t pid = fork();
if (pid == 0) {
    dup2(pipefd[0], STDIN_FILENO);

    close(pipefd[0]);
    close(pipefd[1]);
    /* установим переменную окружения, чтобы включить защищенный режим */
    setenv("LESSSECURE", "1", 1);
    execlp("less", "less", "-S", NULL);
} else {
    close(pipefd[0]);

    write(pipefd[1], stream_data.str().c_str(), stream_data.str().length());
    close(pipefd[1]);

    wait(nullptr);
}

Sure one could hardcode a less fork in that function, but it would be only for that function.
There is some discussion in https://github.com/clicon/cligen/blob/ff6a39448a124a396366f21572668bc16535979c/cligen_io.c#L227 on different designs of scrolling and piping.
Forking less is one solution.
I think rather than calling less directly in this single function (there are many others), one would want a more abstract functionality where all stdout is redirected.
The current piping solution could also be considered which is mostly implemented in cligen_eval.
Instead of using cligen_output there, one could use less directly.

One could maybe just add less in cligen_output/cligen_eval to get it for full coverage, but I have not tested.