Skip to content

Commit

Permalink
feat(tui): add info hidden (#630)
Browse files Browse the repository at this point in the history
* feat(tui): add info hidden

* [skip ci] compgen & mangen

* use match for easier handling of future options

* refactor model into mod

* fmt

---------

Co-authored-by: LoricAndre <loric.andre@pm.me>
  • Loading branch information
LoricAndre and LoricAndre authored Nov 30, 2024
1 parent fa4a73f commit b0868e8
Show file tree
Hide file tree
Showing 9 changed files with 308 additions and 168 deletions.
53 changes: 53 additions & 0 deletions e2e/tests/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,59 @@ fn opt_tabstop_3() -> Result<()> {
tmux.until(|l| l.len() > 2 && l[2].trim() == "> aa b")
}

#[test]
fn opt_info_control() -> Result<()> {
let (tmux, _) = setup("a\\nb\\nc", &[])?;

tmux.until(|l| l[0].starts_with(">"))?;
tmux.until(|l| l[1].starts_with(" 3/3") && l[1].ends_with("0/0"))?;

tmux.send_keys(&[Key('a')])?;
tmux.until(|l| l[1].starts_with(" 1/3") && l[1].ends_with("0/0"))
}
#[test]
fn opt_info_default() -> Result<()> {
let (tmux, _) = setup("a\\nb\\nc", &["--info", "default"])?;

tmux.until(|l| l[0].starts_with(">"))?;
tmux.until(|l| l[1].starts_with(" 3/3") && l[1].ends_with("0/0"))?;

tmux.send_keys(&[Key('a')])?;
tmux.until(|l| l[1].starts_with(" 1/3") && l[1].ends_with("0/0"))
}
#[test]
fn opt_no_info() -> Result<()> {
let (tmux, _) = setup("a\\nb\\nc", &["--no-info"])?;

tmux.until(|l| l[0].starts_with(">"))?;
let cap = tmux.capture()?;

assert_eq!(cap[0], ">");
assert_eq!(cap[1], "> a");

Ok(())
}
#[test]
fn opt_info_hidden() -> Result<()> {
let (tmux, _) = setup("a\\nb\\nc", &["--info", "hidden"])?;

tmux.until(|l| l[0].starts_with(">"))?;
let cap = tmux.capture()?;

assert_eq!(cap[0], ">");
assert_eq!(cap[1], "> a");

Ok(())
}
#[test]
fn opt_info_inline() -> Result<()> {
let (tmux, _) = setup("a\\nb\\nc", &["--info", "inline"])?;

tmux.until(|l| l[0].starts_with("> < 3/3") && l[0].ends_with("0/0"))?;

tmux.send_keys(&[Key('a')])?;
tmux.until(|l| l[0].starts_with("> a < 1/3") && l[0].ends_with("0/0"))
}
#[test]
fn opt_inline_info() -> Result<()> {
let (tmux, _) = setup("a\\nb\\nc", &["--inline-info"])?;
Expand Down
20 changes: 16 additions & 4 deletions man/man1/sk.1
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.TH sk 1 "sk 0.14.0"
.TH sk 1 "sk 0.14.3"
.SH NAME
sk \- sk \- fuzzy finder in Rust
.SH SYNOPSIS
\fBsk\fR [\fB\-\-tac\fR] [\fB\-\-no\-sort\fR] [\fB\-t\fR|\fB\-\-tiebreak\fR] [\fB\-n\fR|\fB\-\-nth\fR] [\fB\-\-with\-nth\fR] [\fB\-d\fR|\fB\-\-delimiter\fR] [\fB\-e\fR|\fB\-\-exact\fR] [\fB\-\-regex\fR] [\fB\-\-algo\fR] [\fB\-\-case\fR] [\fB\-b\fR|\fB\-\-bind\fR] [\fB\-m\fR|\fB\-\-multi\fR] [\fB\-\-no\-multi\fR] [\fB\-\-no\-mouse\fR] [\fB\-c\fR|\fB\-\-cmd\fR] [\fB\-i\fR|\fB\-\-interactive\fR] [\fB\-I \fR] [\fB\-\-color\fR] [\fB\-\-no\-hscroll\fR] [\fB\-\-keep\-right\fR] [\fB\-\-skip\-to\-pattern\fR] [\fB\-\-no\-clear\-if\-empty\fR] [\fB\-\-no\-clear\-start\fR] [\fB\-\-no\-clear\fR] [\fB\-\-show\-cmd\-error\fR] [\fB\-\-layout\fR] [\fB\-\-reverse\fR] [\fB\-\-height\fR] [\fB\-\-no\-height\fR] [\fB\-\-min\-height\fR] [\fB\-\-margin\fR] [\fB\-p\fR|\fB\-\-prompt\fR] [\fB\-\-cmd\-prompt\fR] [\fB\-\-ansi\fR] [\fB\-\-tabstop\fR] [\fB\-\-inline\-info\fR] [\fB\-\-header\fR] [\fB\-\-header\-lines\fR] [\fB\-\-history\fR] [\fB\-\-history\-size\fR] [\fB\-\-cmd\-history\fR] [\fB\-\-cmd\-history\-size\fR] [\fB\-\-preview\fR] [\fB\-\-preview\-window\fR] [\fB\-q\fR|\fB\-\-query\fR] [\fB\-\-cmd\-query\fR] [\fB\-\-expect\fR] [\fB\-\-read0\fR] [\fB\-\-print0\fR] [\fB\-\-print\-query\fR] [\fB\-\-print\-cmd\fR] [\fB\-\-print\-score\fR] [\fB\-1\fR|\fB\-\-select\-1\fR] [\fB\-0\fR|\fB\-\-exit\-0\fR] [\fB\-\-sync\fR] [\fB\-\-pre\-select\-n\fR] [\fB\-\-pre\-select\-pat\fR] [\fB\-\-pre\-select\-items\fR] [\fB\-\-pre\-select\-file\fR] [\fB\-f\fR|\fB\-\-filter\fR] [\fB\-\-tmux\fR] [\fB\-h\fR|\fB\-\-help\fR] [\fB\-V\fR|\fB\-\-version\fR]
\fBsk\fR [\fB\-\-tac\fR] [\fB\-\-no\-sort\fR] [\fB\-t\fR|\fB\-\-tiebreak\fR] [\fB\-n\fR|\fB\-\-nth\fR] [\fB\-\-with\-nth\fR] [\fB\-d\fR|\fB\-\-delimiter\fR] [\fB\-e\fR|\fB\-\-exact\fR] [\fB\-\-regex\fR] [\fB\-\-algo\fR] [\fB\-\-case\fR] [\fB\-b\fR|\fB\-\-bind\fR] [\fB\-m\fR|\fB\-\-multi\fR] [\fB\-\-no\-multi\fR] [\fB\-\-no\-mouse\fR] [\fB\-c\fR|\fB\-\-cmd\fR] [\fB\-i\fR|\fB\-\-interactive\fR] [\fB\-I \fR] [\fB\-\-color\fR] [\fB\-\-no\-hscroll\fR] [\fB\-\-keep\-right\fR] [\fB\-\-skip\-to\-pattern\fR] [\fB\-\-no\-clear\-if\-empty\fR] [\fB\-\-no\-clear\-start\fR] [\fB\-\-no\-clear\fR] [\fB\-\-show\-cmd\-error\fR] [\fB\-\-layout\fR] [\fB\-\-reverse\fR] [\fB\-\-height\fR] [\fB\-\-no\-height\fR] [\fB\-\-min\-height\fR] [\fB\-\-margin\fR] [\fB\-p\fR|\fB\-\-prompt\fR] [\fB\-\-cmd\-prompt\fR] [\fB\-\-ansi\fR] [\fB\-\-tabstop\fR] [\fB\-\-info\fR] [\fB\-\-no\-info\fR] [\fB\-\-inline\-info\fR] [\fB\-\-header\fR] [\fB\-\-header\-lines\fR] [\fB\-\-history\fR] [\fB\-\-history\-size\fR] [\fB\-\-cmd\-history\fR] [\fB\-\-cmd\-history\-size\fR] [\fB\-\-preview\fR] [\fB\-\-preview\-window\fR] [\fB\-q\fR|\fB\-\-query\fR] [\fB\-\-cmd\-query\fR] [\fB\-\-expect\fR] [\fB\-\-read0\fR] [\fB\-\-print0\fR] [\fB\-\-print\-query\fR] [\fB\-\-print\-cmd\fR] [\fB\-\-print\-score\fR] [\fB\-1\fR|\fB\-\-select\-1\fR] [\fB\-0\fR|\fB\-\-exit\-0\fR] [\fB\-\-sync\fR] [\fB\-\-pre\-select\-n\fR] [\fB\-\-pre\-select\-pat\fR] [\fB\-\-pre\-select\-items\fR] [\fB\-\-pre\-select\-file\fR] [\fB\-f\fR|\fB\-\-filter\fR] [\fB\-\-tmux\fR] [\fB\-h\fR|\fB\-\-help\fR] [\fB\-V\fR|\fB\-\-version\fR]
.SH DESCRIPTION
sk \- fuzzy finder in Rust
.PP
Expand Down Expand Up @@ -395,8 +395,20 @@ Parse ANSI color codes in input strings
\fB\-\-tabstop\fR=\fITABSTOP\fR [default: 8]
Number of spaces that make up a tab
.TP
\fB\-\-info\fR=\fIINFO\fR [default: default]
Set matching result count display position

hidden: do not display info inline: display info in the same row as the input default: display info in a dedicated row above the input
.br

.br
[\fIpossible values: \fRdefault, inline, hidden]
.TP
\fB\-\-no\-info\fR
Alias for \-\-info=hidden
.TP
\fB\-\-inline\-info\fR
Display info next to the query
Alias for \-\-info=inline
.TP
\fB\-\-header\fR=\fIHEADER\fR
Set header, displayed next to the info
Expand Down Expand Up @@ -545,4 +557,4 @@ Print help (see a summary with \*(Aq\-h\*(Aq)
\fB\-V\fR, \fB\-\-version\fR
Print version
.SH VERSION
v0.14.0
v0.14.3
6 changes: 5 additions & 1 deletion shell/completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ _sk() {

case "${cmd}" in
sk)
opts="-t -n -d -e -b -m -c -i -I -p -q -1 -0 -f -x -h -V --tac --no-sort --tiebreak --nth --with-nth --delimiter --exact --regex --algo --case --bind --multi --no-multi --no-mouse --cmd --interactive --color --no-hscroll --keep-right --skip-to-pattern --no-clear-if-empty --no-clear-start --no-clear --show-cmd-error --layout --reverse --height --no-height --min-height --margin --prompt --cmd-prompt --ansi --tabstop --inline-info --header --header-lines --history --history-size --cmd-history --cmd-history-size --preview --preview-window --query --cmd-query --expect --read0 --print0 --print-query --print-cmd --print-score --select-1 --exit-0 --sync --pre-select-n --pre-select-pat --pre-select-items --pre-select-file --filter --tmux --extended --literal --cycle --hscroll-off --filepath-word --jump-labels --border --no-bold --info --pointer --marker --phony --help --version"
opts="-t -n -d -e -b -m -c -i -I -p -q -1 -0 -f -x -h -V --tac --no-sort --tiebreak --nth --with-nth --delimiter --exact --regex --algo --case --bind --multi --no-multi --no-mouse --cmd --interactive --color --no-hscroll --keep-right --skip-to-pattern --no-clear-if-empty --no-clear-start --no-clear --show-cmd-error --layout --reverse --height --no-height --min-height --margin --prompt --cmd-prompt --ansi --tabstop --info --no-info --inline-info --header --header-lines --history --history-size --cmd-history --cmd-history-size --preview --preview-window --query --cmd-query --expect --read0 --print0 --print-query --print-cmd --print-score --select-1 --exit-0 --sync --pre-select-n --pre-select-pat --pre-select-items --pre-select-file --filter --tmux --extended --literal --cycle --hscroll-off --filepath-word --jump-labels --border --no-bold --pointer --marker --phony --help --version"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
Expand Down Expand Up @@ -121,6 +121,10 @@ _sk() {
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
--info)
COMPREPLY=($(compgen -W "default inline hidden" -- "${cur}"))
return 0
;;
--header)
COMPREPLY=($(compgen -f "${cur}"))
return 0
Expand Down
5 changes: 3 additions & 2 deletions shell/completion.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ _sk() {
'--prompt=[Set prompt]:PROMPT:_default' \
'--cmd-prompt=[Set prompt in command mode]:CMD_PROMPT:_default' \
'--tabstop=[Number of spaces that make up a tab]:TABSTOP:_default' \
'--info=[Set matching result count display position]:INFO:(default inline hidden)' \
'--header=[Set header, displayed next to the info]:HEADER:_default' \
'--header-lines=[Number of lines of the input treated as header]:HEADER_LINES:_default' \
'--history=[History file]:HISTORY_FILE:_default' \
Expand Down Expand Up @@ -80,7 +81,8 @@ _sk() {
'--reverse[Shorthand for reverse layout]' \
'--no-height[Disable height feature]' \
'--ansi[Parse ANSI color codes in input strings]' \
'--inline-info[Display info next to the query]' \
'--no-info[Alias for --info=hidden]' \
'--inline-info[Alias for --info=inline]' \
'--read0[Read input delimited by ASCII NUL(\\\\0) characters]' \
'--print0[Print output delimited by ASCII NUL(\\\\0) characters]' \
'--print-query[Print the query as the first line]' \
Expand All @@ -98,7 +100,6 @@ _sk() {
'--filepath-word[Reserved for later use]' \
'--border[Reserved for later use]' \
'--no-bold[Reserved for later use]' \
'--info[Reserved for later use]' \
'--pointer[Reserved for later use]' \
'--marker[Reserved for later use]' \
'--phony[Reserved for later use]' \
Expand Down
Loading

0 comments on commit b0868e8

Please sign in to comment.