From ede759497140bcad4877925312f81d4bcb992a08 Mon Sep 17 00:00:00 2001 From: nick black Date: Sun, 14 Mar 2021 22:53:52 -0400 Subject: [PATCH] [ncls] accept -s for scaling mode #1411 --- doc/man/man1/ncls.1.md | 4 +++- src/ls/main.cpp | 16 ++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/doc/man/man1/ncls.1.md b/doc/man/man1/ncls.1.md index cd9afc76f..c47a31332 100644 --- a/doc/man/man1/ncls.1.md +++ b/doc/man/man1/ncls.1.md @@ -8,7 +8,7 @@ ncls - List paths with rendering of multimedia # SYNOPSIS -**ncls** [**-h**|**--help**] [**-V**|**--version**] [**-d**] [**-l**] [**-L**] [**-R**] [**-a**|**--align** ***type***] [**-b** ***blitter***] [ paths ] +**ncls** [**-h**|**--help**] [**-V**|**--version**] [**-d**] [**-l**] [**-L**] [**-R**] [**-a**|**--align** ***type***] [**-b**|**--blitter** ***blitter***] [**-s**|**--scale** ***scale***] [ paths ] # DESCRIPTION @@ -33,6 +33,8 @@ ncls - List paths with rendering of multimedia **-b**|**--blitter** ***blitter***: Blitter, one of **ascii**, **half**, **quad**, **sex**, **braille**, or **pixel**. +**-s**|**--scale** ***scalemode***: Scaling mode, one of **none**, **hires**, **scale**, **scalehi**, or **stretch**. + paths: Run on the specified paths. If none are supplied, run on the current directory. diff --git a/src/ls/main.cpp b/src/ls/main.cpp index c81e56f30..c1496255d 100644 --- a/src/ls/main.cpp +++ b/src/ls/main.cpp @@ -26,6 +26,7 @@ void usage(std::ostream& os, const char* name, int code){ os << " -R: list subdirectories recursively\n"; os << " -a|--align type: 'left', 'right', or 'center'\n"; os << " -b|--blitter blitter: 'ascii', 'half', 'quad', 'sex', 'braille', or 'pixel'\n"; + os << " -s|--scale scaling: one of 'none', 'hires', 'scale', 'scalehi', or 'stretch'\n"; os << " -h: print usage information\n"; os << " -V: print version information\n"; os << std::flush; @@ -52,6 +53,7 @@ struct lsContext { bool dereflinks; ncpp::NCAlign alignment; ncblitter_e blitter; + ncscale_e scaling; }; int handle_path(int dirfd, std::filesystem::path& dir, const char* p, const lsContext& ctx, bool toplevel); @@ -145,7 +147,7 @@ void ncls_thread(const lsContext* ctx) { work.pop(); pthread_mutex_unlock(&mtx); auto s = j.dir / j.p; - auto faken = ctx->nc.prep_image(s.c_str(), ctx->blitter, NCSCALE_SCALE_HIRES, -1, -1); + auto faken = ctx->nc.prep_image(s.c_str(), ctx->blitter, ctx->scaling, -1, -1); pthread_mutex_lock(&outmtx); std::cout << j.p << '\n'; if(faken){ @@ -184,15 +186,17 @@ int main(int argc, char* const * argv){ bool dereflinks = false; ncpp::NCAlign alignment = ncpp::NCAlign::Right; ncblitter_e blitter = NCBLIT_DEFAULT; + ncscale_e scale = NCSCALE_SCALE_HIRES; const struct option opts[] = { { "align", 1, nullptr, 'a' }, { "blitter", 1, nullptr, 'b' }, + { "scale", 1, nullptr, 's' }, { "help", 0, nullptr, 'h' }, { "version", 0, nullptr, 'V' }, { nullptr, 0, nullptr, 0 }, }; int c, lidx; - while((c = getopt_long(argc, argv, "Va:b:dhlLR", opts, &lidx)) != -1){ + while((c = getopt_long(argc, argv, "Va:b:s:dhlLR", opts, &lidx)) != -1){ switch(c){ case 'V': printf("ncls version %s\n", notcurses_version()); @@ -216,6 +220,13 @@ int main(int argc, char* const * argv){ usage(std::cerr, argv[0], EXIT_FAILURE); } break; + case 's': + if(notcurses_lex_scalemode(optarg, &scale)){ + std::cerr << "Invalid scaling specification (got " + << optarg << ")" << std::endl; + usage(std::cerr, argv[0], EXIT_FAILURE); + } + break; case 'd': directories = true; break; @@ -252,6 +263,7 @@ int main(int argc, char* const * argv){ dereflinks, alignment, blitter, + scale, }; ctx.nc.check_pixel_support(); keep_working = true;