Add -q/--quiet flag to suppress info logs
This commit is contained in:
parent
cf7712830b
commit
d8edd92302
34
main.cpp
34
main.cpp
@ -8,6 +8,7 @@
|
||||
#include <csignal>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <getopt.h>
|
||||
#include <string>
|
||||
#include <sys/stat.h>
|
||||
@ -17,6 +18,10 @@
|
||||
|
||||
static volatile bool g_interrupted = false;
|
||||
|
||||
static void noop_log(enum ggml_log_level level, const char * text, void * user_data) {
|
||||
(void)level; (void)text; (void)user_data;
|
||||
}
|
||||
|
||||
static void sigint_handler(const int signo) {
|
||||
(void)signo;
|
||||
g_interrupted = true;
|
||||
@ -113,13 +118,13 @@ static std::vector<unsigned char> read_clipboard() {
|
||||
return data;
|
||||
}
|
||||
|
||||
static std::string capture_screenshot() {
|
||||
static std::string capture_screenshot(bool quiet) {
|
||||
const char *tmpdir = getenv("TMPDIR");
|
||||
if (!tmpdir)
|
||||
tmpdir = "/tmp";
|
||||
std::string path = std::string(tmpdir) + "/ocr_screenshot.png";
|
||||
|
||||
fprintf(stderr, "Select a screen region to OCR...\n");
|
||||
if (!quiet) fprintf(stderr, "Select a screen region to OCR...\n");
|
||||
|
||||
auto check = [&]() -> bool {
|
||||
struct stat st {};
|
||||
@ -178,6 +183,7 @@ static void print_usage(const char *prog) {
|
||||
" --json output in JSON format\n"
|
||||
" --chat-template <name> chat template (default: auto from model)\n"
|
||||
" --screenshot interactively select screen region to OCR\n"
|
||||
" -q, --quiet suppress info logs, show only OCR result\n"
|
||||
" -h show this help\n"
|
||||
"\n"
|
||||
"If <image_path> is omitted, reads image from clipboard.\n"
|
||||
@ -204,6 +210,14 @@ int main(int argc, char **argv) {
|
||||
float temp = 0.0f;
|
||||
uint32_t seed = LLAMA_DEFAULT_SEED;
|
||||
bool json_output = false;
|
||||
bool quiet = false;
|
||||
|
||||
// pre-process -mm to --mmproj so getopt handles it correctly
|
||||
for (int i = 1; i < argc; i++) {
|
||||
if (strcmp(argv[i], "-mm") == 0) {
|
||||
argv[i] = (char *)"--mmproj";
|
||||
}
|
||||
}
|
||||
|
||||
while (true) {
|
||||
static option long_opts[] = {
|
||||
@ -215,10 +229,11 @@ int main(int argc, char **argv) {
|
||||
{"model", required_argument, nullptr, 'm'},
|
||||
{"chat-template", required_argument, nullptr, 4},
|
||||
{"screenshot", no_argument, nullptr, 5},
|
||||
{"quiet", no_argument, nullptr, 6},
|
||||
{"help", no_argument, nullptr, 'h'},
|
||||
{nullptr, 0, nullptr, 0}};
|
||||
int idx = 0;
|
||||
int c = getopt_long(argc, argv, "m:p:t:c:s:h", long_opts, &idx);
|
||||
int c = getopt_long(argc, argv, "m:p:t:c:s:qh", long_opts, &idx);
|
||||
if (c == -1)
|
||||
break;
|
||||
switch (c) {
|
||||
@ -240,6 +255,10 @@ int main(int argc, char **argv) {
|
||||
case 5:
|
||||
screenshot_mode = true;
|
||||
break;
|
||||
case 6:
|
||||
case 'q':
|
||||
quiet = true;
|
||||
break;
|
||||
case 'm':
|
||||
model_path = optarg;
|
||||
break;
|
||||
@ -270,7 +289,7 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
|
||||
if (screenshot_mode) {
|
||||
image_path = capture_screenshot();
|
||||
image_path = capture_screenshot(quiet);
|
||||
if (image_path.empty()) {
|
||||
fprintf(stderr,
|
||||
"ERROR: no screenshot tool found. Install gnome-screenshot, "
|
||||
@ -287,6 +306,11 @@ int main(int argc, char **argv) {
|
||||
|
||||
llama_backend_init();
|
||||
|
||||
if (quiet) {
|
||||
llama_log_set(noop_log, nullptr);
|
||||
mtmd_helper_log_set(noop_log, nullptr);
|
||||
}
|
||||
|
||||
llama_model_params mparams = llama_model_default_params();
|
||||
mparams.n_gpu_layers = n_gpu_layers;
|
||||
|
||||
@ -343,7 +367,7 @@ int main(int argc, char **argv) {
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr, "Reading image from clipboard...\n");
|
||||
if (!quiet) fprintf(stderr, "Reading image from clipboard...\n");
|
||||
auto clip = read_clipboard();
|
||||
if (clip.empty()) {
|
||||
fprintf(stderr,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user