feat: add configurable max height

This commit is contained in:
Daylin Morgan 2023-11-10 13:51:00 -06:00
parent f68672bb7f
commit 34a2cb9940
Signed by: daylin
GPG key ID: C1E52E7DD81DF79F
3 changed files with 19 additions and 5 deletions

View file

@ -17,7 +17,9 @@ nimble install https://github.com/daylinmorgan/tsm
## Usage ## 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: 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`. 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 ```sh
bind f display-popup \ bind f display-popup \

View file

@ -1,12 +1,24 @@
import std/[enumerate, os, strformat, strutils, terminal] import std/[enumerate, os, strformat, strutils, terminal]
from illwill import illwillDeinit, illwillInit, getKey, Key from illwill import illwillDeinit, illwillInit, getKey, Key
import bbansi import term
import project import project
func toStr(k: Key): string = $chr(ord(k)) 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 type
Cursor = object Cursor = object
min, y: Natural = 1 min, y: Natural = 1
@ -165,7 +177,7 @@ proc draw() =
proc update(s: var State) = proc update(s: var State) =
s.buffer.width = terminalWidth() 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 s.cursor.max = s.buffer.height - state.buffer.inputPad
proc clear(b: var Buffer) = proc clear(b: var Buffer) =

View file

@ -1,6 +1,6 @@
import std/strutils import std/strutils
import bbansi import bbansi
export bbansi
const const
sep = " [magenta]|[/] " sep = " [magenta]|[/] "
prefix = "[cyan]tsm[/]" & sep prefix = "[cyan]tsm[/]" & sep