예제 #1
0
파일: help.c 프로젝트: 0xheart0/vlc
static void print_desc(const char *str, unsigned margin, bool color)
{
    unsigned width = ConsoleWidth() - margin;

    if (color)
        fputs(BLUE, stdout);

    const char *word = str;
    int wordlen = 0, wordwidth = 0;
    unsigned offset = 0;
    bool newline = true;

    while (str[0])
    {
        uint32_t cp;
        size_t charlen = vlc_towc(str, &cp);
        if (unlikely(charlen == (size_t)-1))
            break;

        int charwidth = wcwidth(cp);
        if (charwidth < 0)
            charwidth = 0;

        str += charlen;

        if (iswspace(cp))
        {
            if (!newline)
            {
                putchar(' '); /* insert space */
                charwidth = 1;
            }
            fwrite(word, 1, wordlen, stdout); /* write complete word */
            word = str;
            wordlen = 0;
            wordwidth = 0;
            newline = false;
        }
        else
        {
            wordlen += charlen;
            wordwidth += charwidth;
        }

        offset += charwidth;
        if (offset >= width)
        {
            if (newline)
            {   /* overflow (word wider than line) */
                fwrite(word, 1, wordlen - charlen, stdout);
                word = str - charlen;
                wordlen = charlen;
                wordwidth = charwidth;
            }
            printf("\n%*s", margin, ""); /* new line */
            offset = wordwidth;
            newline = true;
        }
    }

    if (!newline)
        putchar(' ');
    printf(color ? "%s\n"GRAY : "%s\n", word);
}
예제 #2
0
    static void _reportHead(const char* modName, const char* sourceInfo, Level severity)
    {
        /* Clear current line out */
        int width = ConsoleWidth();
        fprintf(stderr, "\r");
        for (int w=0 ; w<width ; ++w)
            fprintf(stderr, " ");
        fprintf(stderr, "\r");

        std::chrono::steady_clock::duration tm = CurrentUptime();
        double tmd = tm.count() *
            std::chrono::steady_clock::duration::period::num /
            (double)std::chrono::steady_clock::duration::period::den;
        std::thread::id thrId = std::this_thread::get_id();
        const char* thrName = nullptr;
        if (ThreadMap.find(thrId) != ThreadMap.end())
            thrName = ThreadMap[thrId];

        if (XtermColor)
        {
            fprintf(stderr, BOLD "[");
            fprintf(stderr, GREEN "%5.4f ", tmd);
            uint_fast64_t fIdx = FrameIndex.load();
            if (fIdx)
                fprintf(stderr, "(%" PRIu64 ") ", fIdx);
            switch (severity)
            {
                case Info:
                    fprintf(stderr, BOLD CYAN "INFO");
                    break;
                case Warning:
                    fprintf(stderr, BOLD YELLOW "WARNING");
                    break;
                case Error:
                    fprintf(stderr, RED BOLD "ERROR");
                    break;
                case Fatal:
                    fprintf(stderr, BOLD RED "FATAL ERROR");
                    break;
                default:
                    break;
            };
            fprintf(stderr, NORMAL BOLD " %s", modName);
            if (sourceInfo)
                fprintf(stderr, BOLD YELLOW " {%s}", sourceInfo);
            if (thrName)
                fprintf(stderr, BOLD MAGENTA " (%s)", thrName);
            fprintf(stderr, NORMAL BOLD "] " NORMAL);
        }
        else
        {
#if _WIN32
            SetConsoleTextAttribute(Term, FOREGROUND_INTENSITY | FOREGROUND_WHITE);
            fprintf(stderr, "[");
            SetConsoleTextAttribute(Term, FOREGROUND_INTENSITY | FOREGROUND_GREEN);
            fprintf(stderr, "%5.4f ", tmd);
            uint64_t fi = FrameIndex.load();
            if (fi)
                fprintf(stderr, "(%" PRIu64 ") ", fi);
            switch (severity)
            {
            case Info:
                SetConsoleTextAttribute(Term, FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_BLUE);
                fprintf(stderr, "INFO");
                break;
            case Warning:
                SetConsoleTextAttribute(Term, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
                fprintf(stderr, "WARNING");
                break;
            case Error:
                SetConsoleTextAttribute(Term, FOREGROUND_INTENSITY | FOREGROUND_RED);
                fprintf(stderr, "ERROR");
                break;
            case Fatal:
                SetConsoleTextAttribute(Term, FOREGROUND_INTENSITY | FOREGROUND_RED);
                fprintf(stderr, "FATAL ERROR");
                break;
            default:
                break;
            };
            SetConsoleTextAttribute(Term, FOREGROUND_INTENSITY | FOREGROUND_WHITE);
            fprintf(stderr, " %s", modName);
            SetConsoleTextAttribute(Term, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
            if (sourceInfo)
                fprintf(stderr, " {%s}", sourceInfo);
            SetConsoleTextAttribute(Term, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_BLUE);
            if (thrName)
                fprintf(stderr, " (%s)", thrName);
            SetConsoleTextAttribute(Term, FOREGROUND_INTENSITY | FOREGROUND_WHITE);
            fprintf(stderr, "] ");
            SetConsoleTextAttribute(Term, FOREGROUND_WHITE);
#else
            fprintf(stderr, "[");
            fprintf(stderr, "%5.4f ", tmd);
            uint_fast64_t fIdx = FrameIndex.load();
            if (fIdx)
                fprintf(stderr, "(%" PRIu64 ") ", fIdx);
            switch (severity)
            {
            case Info:
                fprintf(stderr, "INFO");
                break;
            case Warning:
                fprintf(stderr, "WARNING");
                break;
            case Error:
                fprintf(stderr, "ERROR");
                break;
            case Fatal:
                fprintf(stderr, "FATAL ERROR");
                break;
            default:
                break;
            };
            fprintf(stderr, " %s", modName);
            if (sourceInfo)
                fprintf(stderr, " {%s}", sourceInfo);
            if (thrName)
                fprintf(stderr, " (%s)", thrName);
            fprintf(stderr, "] ");
#endif
        }
    }