Skip to content

Commit

Permalink
Merge pull request #13 from fbeline/custom-window-size
Browse files Browse the repository at this point in the history
Parsing in-line args
  • Loading branch information
fbeline authored Apr 20, 2020
2 parents 8e56cca + 36a98e6 commit 322ec55
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 10 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ Luneta is an interactive filter that can be easily composed within any script.
<img width="80%" src="https://user-images.githubusercontent.com/5730881/79627815-f864bc80-8111-11ea-9a14-11ab35f1962c.gif">
</p>

## About

- fast.
- small and portable. (~ 1mb binary)
- adaptable screen size.

Run `luneta -h` for help.

## Usage examples

Pick a command in your shell history:
Expand Down
2 changes: 1 addition & 1 deletion dub.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
32 changes: 27 additions & 5 deletions source/luneta/app.d
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
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;
import luneta.opts;

private:
const string VERSION = "v1.0.0";

string[] parseStdin()
{
Expand Down Expand Up @@ -39,8 +40,29 @@ void delegate() loop(fuzzyFn fzy, ref string result)
};
}

int main()
public:
int main(string[] args)
{

int height;
bool _version;
auto helpInformation = getopt(
args,
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)
{
defaultGetoptPrinter("usage: luneta [options]", helpInformation.options);
return 0;
}
if (_version) {
writeln(VERSION);
return 0;
}

auto fzy = fuzzy(parseStdin());
string result;
init(loop(fzy, result));
Expand Down
9 changes: 9 additions & 0 deletions source/luneta/opts.d
Original file line number Diff line number Diff line change
@@ -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;
}
2 changes: 1 addition & 1 deletion source/luneta/printers.d
Original file line number Diff line number Diff line change
Expand Up @@ -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, "...");
}
Expand Down
5 changes: 2 additions & 3 deletions source/luneta/window.d
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 322ec55

Please sign in to comment.