zpm-project / zpm-zsh

zsh plugin manager in ansi C.
GNU General Public License v3.0
5 stars 3 forks source link

Enhance message output #32

Open desyncr opened 7 years ago

desyncr commented 7 years ago

Related Trello card: https://trello.com/c/fZHPQp8q/9-fancy-output

Probably [ZPM] to start every line except for list. Maybe green for standard message and red for error. Also plugin name should be bold.

fennecdjay commented 7 years ago

what about usage? Does it need [ZPM] header? I think the whole usage string should be defined as static const char*.


Also do we have to ouput errors to stderr?

desyncr commented 7 years ago

Also do we have to ouput errors to stderr?

Sure thing about this.

what about usage?

I think we can have a wrapper/lib around message/output handling. This is particularly useful when trying to debug and you need extended output. So I'm thinking on a logging library, probably there's one out there that fits our needs.

fennecdjay commented 7 years ago

So I'm thinking on a logging library

Well, i think enums and a simple function could do, so I do not see the benefit of a logging library.

fennecdjay commented 7 years ago
enum ZPM_MSG_TYPE {
    ZPM_MSG,
    ZPM_ERR,
    ZPM_NONE
};

void zpm_msg(enum ZPM_MSG_TYPE type, const char* format, ...) {
    char msg[PATH_MAX];
    FILE* f = type = ZPM_ERR ? stderr : stdout;
    va_list arg;
    va_start(arg, fmt);
    vsnprintf(msg, 256, fmt, arg);
    if (type != ZPM_NONE) {
        fprintf(f, "[ZPM] ");
    }
    fprintf(f, "%s\n", msg);
    va_end(arg);

}

Do we need coloration? I'd quite like that.

    if (type != ZPM_NONE {
        int color = type == ZPM_ERR : 31 : 32;
        fprintf(f, "\033[1m[\033[0m\033[%imZPM\033[0m\033[1m]\033[0m", color);
    }

also

printf("\033[1m%s\033[0m", plugin_name);

in plugin_print_list would make plugin_name bold, which, in my opinion, is nice :smile:

desyncr commented 7 years ago

Well, having different error levels (debug, info, error, etc) would be nice. If we can have that in a couple of lines it's welcome! :D

fennecdjay commented 7 years ago

Would you like me to give it a try based on what I posted before (thus renaming ZPM_NONE to ZPM_INFO) ?

desyncr commented 7 years ago

Yeah sure, it will be great to tell zpm what to log:

zpm "zsh-users/zsh-syntax-highlighting" --log=info
[INFO] Installing plugin from "https://github.com/zsh-users/zsh-syntax-highlighting.git"
[INFO] ... 

zpm "zsh-users/zsh-syntax-highlighting" --log=debug
[DEBUG] Parting argument: "zsh-users/zsh-syntax-highlighting"
[DEBUG] No host provided. Using default "github.com"
[DEBUG] Converting FQ URL: "https://github.com/zsh-users/zsh-syntax-highlighting.git"
[INFO] Installing plugin from "https://github.com/zsh-users/zsh-syntax-highlighting.git"
...
fennecdjay commented 7 years ago

We migth need to make color optionnal, maybe depending on wther or not it is running in a pipe, as it mess with cram.

desyncr commented 7 years ago

Yep a --color flag would also be useful.

fennecdjay commented 7 years ago

I have trouble finding info on check the process is running in a pipe in C :confused: But I was thinking on having a ZPM_COLOR environment variable.

fennecdjay commented 7 years ago

see #33.