Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Ggml org Llama cpp Console Header

From Leeroopedia
Revision as of 12:39, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Ggml_org_Llama_cpp_Console_Header.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains Terminal, IO
Last Updated 2026-02-15 00:00 GMT

Overview

Declares the console namespace API for terminal initialization, colored output, interactive line reading, spinner animation, and logging.

Description

This header defines the `display_type` enum with values RESET, INFO, PROMPT, REASONING, USER_INPUT, and ERROR for controlling output color and style. The `console` namespace provides `init`/`cleanup` for terminal state management, `set_display` for switching color modes, `readline` for interactive input with history support, and a `spinner` sub-namespace with `start`/`stop` for animated loading indicators. It also provides `log` and `error` functions for formatted output directly to stdout, with a note that these should only be used from a dedicated CLI thread, not inference threads.

Usage

Use this header when building CLI tools that need colored terminal output, interactive input with line editing, or spinner animations. Include it in the main CLI thread of chat or inference applications that require a terminal user interface.

Code Reference

Source Location

Signature

enum display_type {
    DISPLAY_TYPE_RESET = 0,
    DISPLAY_TYPE_INFO,
    DISPLAY_TYPE_PROMPT,
    DISPLAY_TYPE_REASONING,
    DISPLAY_TYPE_USER_INPUT,
    DISPLAY_TYPE_ERROR
};

namespace console {
    void init(bool use_simple_io, bool use_advanced_display);
    void cleanup();
    void set_display(display_type display);
    bool readline(std::string & line, bool multiline_input);

    namespace spinner {
        void start();
        void stop();
    }

    void log(const char * fmt, ...);
    void error(const char * fmt, ...);
    void flush();
}

Import

#include "console.h"

I/O Contract

Inputs

Name Type Required Description
use_simple_io bool Yes Whether to use simple I/O mode without advanced terminal features
use_advanced_display bool Yes Whether to enable advanced display features like colors
display display_type Yes The display type enum value controlling output color/style
line std::string & Yes Reference to string that receives the user input line
multiline_input bool Yes Whether to allow multi-line input mode
fmt const char * Yes Printf-style format string for log/error output

Outputs

Name Type Description
readline return bool True if a line was successfully read, false on EOF or error

Usage Examples

#include "console.h"

// Initialize terminal with advanced display
console::init(false, true);

// Set display to user input mode (colored)
console::set_display(DISPLAY_TYPE_USER_INPUT);

// Read a line of input
std::string line;
if (console::readline(line, false)) {
    console::set_display(DISPLAY_TYPE_INFO);
    console::log("You entered: %s\n", line.c_str());
}

// Show spinner during processing
console::spinner::start();
// ... do work ...
console::spinner::stop();

// Cleanup terminal state
console::cleanup();

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment