From dbd613649474292a5d76e3d9a2b0d1aa9bb7c305 Mon Sep 17 00:00:00 2001 From: Felipe Beline Baravieira Date: Mon, 20 Apr 2020 18:03:47 -0300 Subject: [PATCH 1/6] app imports remove unused imports --- source/luneta/app.d | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/source/luneta/app.d b/source/luneta/app.d index 31738d4..56c50e0 100644 --- a/source/luneta/app.d +++ b/source/luneta/app.d @@ -1,15 +1,13 @@ import std.stdio; import std.string; -import std.conv; -import std.typecons; -import std.algorithm; -import std.array; +import std.getopt; import fuzzyd.core; import deimos.ncurses.curses; import luneta.printers; import luneta.keyboard; import luneta.window; +private: string[] parseStdin() { string l; @@ -39,6 +37,7 @@ void delegate() loop(fuzzyFn fzy, ref string result) }; } +public: int main() { auto fzy = fuzzy(parseStdin()); From 5d87ae0bfb0c1d3fe3508b51f16b06609134f657 Mon Sep 17 00:00:00 2001 From: Felipe Beline Baravieira Date: Mon, 20 Apr 2020 19:15:32 -0300 Subject: [PATCH 2/6] application opts - parsing arguments - custom max window height --- source/luneta/app.d | 14 +++++++++++++- source/luneta/opts.d | 9 +++++++++ source/luneta/window.d | 5 ++--- 3 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 source/luneta/opts.d diff --git a/source/luneta/app.d b/source/luneta/app.d index 56c50e0..c1d74cf 100644 --- a/source/luneta/app.d +++ b/source/luneta/app.d @@ -6,6 +6,7 @@ import deimos.ncurses.curses; import luneta.printers; import luneta.keyboard; import luneta.window; +import luneta.opts; private: string[] parseStdin() @@ -38,8 +39,19 @@ void delegate() loop(fuzzyFn fzy, ref string result) } public: -int main() +int main(string[] args) { + + int height; + auto helpInformation = getopt(args, "height", &height); + luneta.opts.initialize(height); + + if (helpInformation.helpWanted) + { + defaultGetoptPrinter("usage: luneta [options]", helpInformation.options); + return 0; + } + auto fzy = fuzzy(parseStdin()); string result; init(loop(fzy, result)); diff --git a/source/luneta/opts.d b/source/luneta/opts.d new file mode 100644 index 0000000..8ef120b --- /dev/null +++ b/source/luneta/opts.d @@ -0,0 +1,9 @@ +module luneta.opts; + +static int height = 22; /// window height + +/// initialize application options +void initialize(int _height) { + if (_height > 0) + height = _height; +} \ No newline at end of file diff --git a/source/luneta/window.d b/source/luneta/window.d index fe3c114..7f7cecf 100644 --- a/source/luneta/window.d +++ b/source/luneta/window.d @@ -4,8 +4,7 @@ import std.stdio; import std.algorithm; import std.string : toStringz; import deimos.ncurses.curses; - -private const MAX_L = 22; +import luneta.opts; /// window size struct Wsize @@ -17,7 +16,7 @@ struct Wsize /// get window size Wsize getWindowSize() { - return Wsize(getmaxx(stdscr), min(MAX_L, getmaxy(stdscr))); + return Wsize(getmaxx(stdscr), min(luneta.opts.height, getmaxy(stdscr))); } /// ncurses mvprintw wrapper From bf83a268ba04799cc1ca3b69f8635f361a1ca580 Mon Sep 17 00:00:00 2001 From: Felipe Beline Baravieira Date: Mon, 20 Apr 2020 20:21:47 -0300 Subject: [PATCH 3/6] Improve Documentation --- README.md | 8 ++++++++ dub.json | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 32728fd..d163b8a 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,14 @@ Luneta is an interactive filter that can be easily composed within any script.

+## About + +- fast. +- small and portable. (~ 1mb binary) +- adaptable screen size. + +Run `luneta -h` for help. + ## Usage examples Pick a command in your shell history: diff --git a/dub.json b/dub.json index 5d5d25e..4dc204a 100644 --- a/dub.json +++ b/dub.json @@ -9,7 +9,7 @@ "fuzzyd": "1.0.0-beta", "ncurses": "~master" }, - "description": "Terminal fuzzy search", + "description": "Luneta is an interactive filter that can be easily composed within any script.", "license": "MIT", "name": "luneta" } From 605e1cee37cd06f43c26b0c28c04c4c163f18a01 Mon Sep 17 00:00:00 2001 From: Felipe Beline Baravieira Date: Mon, 20 Apr 2020 20:30:38 -0300 Subject: [PATCH 4/6] height param provide a description. --- source/luneta/app.d | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/source/luneta/app.d b/source/luneta/app.d index c1d74cf..e93fa9c 100644 --- a/source/luneta/app.d +++ b/source/luneta/app.d @@ -43,7 +43,9 @@ int main(string[] args) { int height; - auto helpInformation = getopt(args, "height", &height); + auto helpInformation = getopt( + args, + "height", "set the maximum window height (number of lines), e.g --height 25", &height); luneta.opts.initialize(height); if (helpInformation.helpWanted) @@ -51,7 +53,7 @@ int main(string[] args) defaultGetoptPrinter("usage: luneta [options]", helpInformation.options); return 0; } - + auto fzy = fuzzy(parseStdin()); string result; init(loop(fzy, result)); From 3c36f4b98174a6a0f5e9e4d8131ceb2cdd5840ed Mon Sep 17 00:00:00 2001 From: Felipe Beline Baravieira Date: Mon, 20 Apr 2020 20:37:42 -0300 Subject: [PATCH 5/6] version param option to return the project version. --- source/luneta/app.d | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/source/luneta/app.d b/source/luneta/app.d index e93fa9c..44fcec2 100644 --- a/source/luneta/app.d +++ b/source/luneta/app.d @@ -9,6 +9,8 @@ import luneta.window; import luneta.opts; private: +const string VERSION = "v1.0.0"; + string[] parseStdin() { string l; @@ -43,9 +45,12 @@ int main(string[] args) { int height; + bool _version; auto helpInformation = getopt( args, - "height", "set the maximum window height (number of lines), e.g --height 25", &height); + std.getopt.config.passThrough, + "height", "set the maximum window height (number of lines), e.g --height 25", &height, + "version|v", "version", &_version); luneta.opts.initialize(height); if (helpInformation.helpWanted) @@ -53,6 +58,10 @@ int main(string[] args) defaultGetoptPrinter("usage: luneta [options]", helpInformation.options); return 0; } + if (_version) { + writeln(VERSION); + return 0; + } auto fzy = fuzzy(parseStdin()); string result; From 36a98e655e3805f87b38b643649d9c7443091baf Mon Sep 17 00:00:00 2001 From: Felipe Beline Baravieira Date: Mon, 20 Apr 2020 20:43:41 -0300 Subject: [PATCH 6/6] fix line chopping --- source/luneta/printers.d | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/luneta/printers.d b/source/luneta/printers.d index e6284b1..5f77e54 100644 --- a/source/luneta/printers.d +++ b/source/luneta/printers.d @@ -30,7 +30,7 @@ void printMatches(KeyProcessor kp) mvprintw(line, i + 2, m.value[i].to!string); } } - if (m.value.length > getWindowSize.width) + if (m.value.length > getWindowSize.width-1) { mvprintw(line, getWindowSize.width-2, "..."); }