diff --git a/README.md b/README.md index a0a3ca9..faf7fa8 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,9 @@ nimble install https://github.com/daylinmorgan/tsm ## Usage -To configure `tsm` export the environment variable `TSM_DIRS`, with a colon-delimited set of parent directories to find projects. +To configure `tsm` export the below environment variables: +> `TSM_DIRS`: a colon-delimited set of parent directories to find projects. \ +> `TSM_HEIGHT`: integer specifying number of rows in terminal (default: 15) For example in your rc file: @@ -26,7 +28,7 @@ export TSM_DIRS="$HOME/projects/personal:$HOME/projects/work" ``` To make full use of `tsm` you should also add a new key binding to your `tmux.conf`. -For example you can bind the f key to show a popup with `tsm`: +For example, you can bind the f key to show a popup with `tsm`: ```sh bind f display-popup \ diff --git a/src/selector.nim b/src/selector.nim index c373ae8..822f34b 100644 --- a/src/selector.nim +++ b/src/selector.nim @@ -1,12 +1,24 @@ import std/[enumerate, os, strformat, strutils, terminal] from illwill import illwillDeinit, illwillInit, getKey, Key -import bbansi +import term import project func toStr(k: Key): string = $chr(ord(k)) +proc getMaxHeight(): int = + result = 10 + let setting = getEnv("TSM_HEIGHT") + if setting != "": + try: + result = parseInt(setting) + except ValueError: + termQuit fmt"failed to parse TSM_HEIGHT of `{setting}`, expected integer" + + +let maxHeight = getMaxHeight() + type Cursor = object min, y: Natural = 1 @@ -165,7 +177,7 @@ proc draw() = proc update(s: var State) = s.buffer.width = terminalWidth() - s.buffer.height = min(terminalHeight(), 10 + state.buffer.inputPad) + s.buffer.height = min(terminalHeight(), maxHeight + state.buffer.inputPad) s.cursor.max = s.buffer.height - state.buffer.inputPad proc clear(b: var Buffer) = diff --git a/src/term.nim b/src/term.nim index 6fb7788..f28a3ac 100644 --- a/src/term.nim +++ b/src/term.nim @@ -1,6 +1,6 @@ import std/strutils import bbansi - +export bbansi const sep = " [magenta]|[/] " prefix = "[cyan]tsm[/]" & sep