Skip to content

Commit

Permalink
vhs: basic tests
Browse files Browse the repository at this point in the history
initial version - some are still broken
  • Loading branch information
rsteube committed Jan 16, 2025
1 parent 101736c commit 761a5cf
Show file tree
Hide file tree
Showing 70 changed files with 1,652 additions and 3 deletions.
43 changes: 43 additions & 0 deletions .dockerfile/home/.config/nushell/config.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# config.nu

let carapace_completer = {|spans|
if "TARGET" in $env {
^$env.TARGET _carapace nushell ...$spans | from json
}
}

$env.config = {
completions: {
case_sensitive: false # set to true to enable case-sensitive completions
quick: true # set this to false to prevent auto-selecting completions when only one remains
partial: true # set this to false to prevent partial filling of the prompt
algorithm: "prefix" # prefix or fuzzy
external: {
enable: true # set to false to prevent nushell looking into $env.PATH to find more suggestions, `false` recommended for WSL users as this look up may be very slow
max_results: 100 # setting it lower can improve completion performance at the cost of omitting some options
completer: $carapace_completer # check 'carapace_completer' above as an example
}
use_ls_colors: true # set this to true to enable file/path/directory completions using LS_COLORS
}

menus: [
{
name: completion_menu
only_buffer_difference: false
marker: "| "
type: {
layout: columnar
columns: 4
col_width: 20 # Optional value. If missing all the screen width is used to calculate column width
col_padding: 2
}
style: {
text: white
selected_text: {attr: r}
description_text: white_dimmed
}
}
]
}

source ~/.config/nushell/starship.nu
14 changes: 14 additions & 0 deletions .dockerfile/home/.config/nushell/env.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Nushell Environment Config File

$env.PROMPT_COMMAND_RIGHT = ''

$env.ENV_CONVERSIONS = {
"PATH": {
from_string: { |s| $s | split row (char esep) | path expand --no-symlink }
to_string: { |v| $v | path expand --no-symlink | str join (char esep) }
}
"Path": {
from_string: { |s| $s | split row (char esep) | path expand --no-symlink }
to_string: { |v| $v | path expand --no-symlink | str join (char esep) }
}
}
38 changes: 38 additions & 0 deletions .dockerfile/home/.config/nushell/starship.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# this file is both a valid
# - overlay which can be loaded with `overlay use starship.nu`
# - module which can be used with `use starship.nu`
# - script which can be used with `source starship.nu`
export-env { $env.STARSHIP_SHELL = "nu"; load-env {
STARSHIP_SESSION_KEY: (random chars -l 16)
PROMPT_MULTILINE_INDICATOR: (
^/usr/bin/starship prompt --continuation
)
# Does not play well with default character module.
# TODO: Also Use starship vi mode indicators?
PROMPT_INDICATOR: ""
PROMPT_COMMAND: {||
# jobs are not supported
(
^/usr/bin/starship prompt
--cmd-duration $env.CMD_DURATION_MS
$"--status=($env.LAST_EXIT_CODE)"
--terminal-width (term size).columns
)
}

config: ($env.config? | default {} | merge {
render_right_prompt_on_last_line: true
})

PROMPT_COMMAND_RIGHT: {||
(
^/usr/bin/starship prompt
--right
--cmd-duration $env.CMD_DURATION_MS
$"--status=($env.LAST_EXIT_CODE)"
--terminal-width (term size).columns
)
}
}}
41 changes: 39 additions & 2 deletions .github/workflows/doc.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,42 @@
name: Doc

on:
pull_request:
push:
branches:
- 'master'

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: shallow clone
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.22.0'

- name: build
run: |
cd example
go build
- uses: actions/upload-artifact@v4
with:
name: example
path: example/example
retention-days: 1


word: {needs: build, uses: ./.github/workflows/vhs-template.yml, with: {topic: word}}
nospace: {needs: build, uses: ./.github/workflows/vhs-template.yml, with: {topic: nospace}}
doubleQuote: {needs: build, uses: ./.github/workflows/vhs-template.yml, with: {topic: doubleQuote}}

doc:
needs:
- word
- nospace
- doubleQuote
runs-on: ubuntu-latest
container: ghcr.io/carapace-sh/carapace
steps:
Expand All @@ -17,6 +47,13 @@ jobs:
key: linkcheck
path: docs/book/linkcheck

- uses: actions/download-artifact@v4
with:
path: docs/src/development/vhs/

- name: Display structure of downloaded files
run: ls -R docs/src/development/vhs/

- name: "build docs"
run: |
mdbook build docs
Expand Down
47 changes: 47 additions & 0 deletions .github/workflows/vhs-template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: vhs template

on:
workflow_call:
inputs:
topic:
required: true
type: string

jobs:
vhs:
runs-on: ubuntu-latest
continue-on-error: true
container: ghcr.io/carapace-sh/vhs
env:
RC_BASH: "ln -sf /carapace/example/example /usr/local/bin/example"
RC_NUSHELL_ENV: "mkdir ~/.cache/\nexample _carapace nushell | save --force ~/.cache/example.nu"
RC_NUSHELL: "source ~/.cache/example.nu\n$$env.config.completions.external.completer = $$example_completer"
steps:
- name: shallow clone
uses: actions/checkout@v4

- uses: actions/download-artifact@v4
with:
name: example
path: /usr/local/bin/

- run: chmod +x /usr/local/bin/example

- name: vhs
run: |
cd docs/src/development/vhs/${{ inputs.topic }}
ls *.tape | xargs -n1 vhs
- uses: actions/upload-artifact@v4
with:
name: ${{ inputs.topic }}
path: |
docs/src/development/vhs/${{ inputs.topic }}/
!docs/src/development/vhs/${{ inputs.topic }}/*.tape
retention-days: 1

- name: check
run: |
git diff
[ -z "$(git status --porcelain)" ] # clean workspace unless .ascii files changed
4 changes: 4 additions & 0 deletions .github/workflows/vhs.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
RC_BASH="ln -sf /carapace/example/example /usr/local/bin/example"
RC_NUSHELL_ENV="mkdir ~/.cache/\nexample _carapace nushell | save --force ~/.cache/example.nu"
RC_NUSHELL="source ~/.cache/example.nu\n$$env.config.completions.external.completer = $$example_completer"

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ caraparse/caraparse
.cover
dist
docs/book
docs/src/development/vhs/*/out/*.gif
example/cmd/_test_files/*.txt
example/example
example-nonposix/example-nonposix
Expand Down
9 changes: 9 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,12 @@ services:
RC_ZSH: |
export PATH="/carapace/example/:$$PATH"
source <(example _carapace)
vhs:
image: ghcr.io/carapace-sh/vhs
volumes:
- '.:/carapace/'
working_dir: /carapace/docs/src/development/vhs
command: bash --login -c "ls -d */ | xargs -I'{}' bash -c \"cd {};ls *.tape | xargs -n1 vhs\""
env_file:
- .github/workflows/vhs.env
4 changes: 4 additions & 0 deletions docs/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,7 @@
- [Zsh](./development/shells/zsh.md)
- [Testing](./development/testing.md)
- [Asciinema](./development/asciinema.md)
- [VHS](./development/vhs.md)
- [Word](./development/vhs/word.md)
- [Nospace](./development/vhs/nospace.md)
- [Double Quote](./development/vhs/doubleQuote.md)
2 changes: 1 addition & 1 deletion docs/src/carapace/gen.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ exec($(command _carapace))
source <(command _carapace)
```
> Directly sourcing multiple completions in your shell init script increases startup time [considerably](https://medium.com/@jzelinskie/please-dont-ship-binaries-with-shell-completion-as-commands-a8b1bcb8a0d0). See [lazycomplete](https://github.com/rsteube/lazycomplete) for a solution to this problem.
> Directly sourcing multiple completions in your shell init script increases startup time [considerably](https://jzelinskie.com/posts/dont-recommend-sourcing-shell-completion/). See [lazycomplete](https://github.com/rsteube/lazycomplete) for a solution to this problem.
1 change: 1 addition & 0 deletions docs/src/development/vhs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# VHS
15 changes: 15 additions & 0 deletions docs/src/development/vhs/bash.tape
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Require example

Set Theme "Snazzy"
Set FontFamily "JetBrains Mono"
Set FontSize 30
Set Width 1400
Set Height 300
Set Padding 0

Set Shell "bash"

Hide
Type@10ms "source <(example _carapace bash)" Enter
Type@10ms "clear" Enter
Show
18 changes: 18 additions & 0 deletions docs/src/development/vhs/doubleQuote.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Double Quote

- bash
![](./doubleQuote/out/doubleQuote.bash.gif)
- elvish
![](./doubleQuote/out/doubleQuote.elvish.gif)
- fish
![](./doubleQuote/out/doubleQuote.fish.gif)
- nushell
![](./doubleQuote/out/doubleQuote.nushell.gif)
- oil
![](./doubleQuote/out/doubleQuote.oil.gif)
- powershell
![](./doubleQuote/out/doubleQuote.powershell.gif)
- xonsh
![](./doubleQuote/out/doubleQuote.xonsh.gif)
- zsh
![](./doubleQuote/out/doubleQuote.zsh.gif)
8 changes: 8 additions & 0 deletions docs/src/development/vhs/doubleQuote/doubleQuote.bash.tape
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Source ../bash.tape

Output out/doubleQuote.bash.gif
Output out/doubleQuote.bash.ascii

Type `example "ac"` Sleep 1 Tab@1

Sleep 2
8 changes: 8 additions & 0 deletions docs/src/development/vhs/doubleQuote/doubleQuote.elvish.tape
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Source ../elvish.tape

Output out/doubleQuote.elvish.gif
Output out/doubleQuote.elvish.ascii

Type `example "ac"` Sleep 1 Tab@1

Sleep 2
8 changes: 8 additions & 0 deletions docs/src/development/vhs/doubleQuote/doubleQuote.fish.tape
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Source ../fish.tape

Output out/doubleQuote.fish.gif
Output out/doubleQuote.fish.ascii

Type `example "ac"` Sleep 1 Tab@1

Sleep 2
8 changes: 8 additions & 0 deletions docs/src/development/vhs/doubleQuote/doubleQuote.nushell.tape
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Source ../nushell.tape

Output out/doubleQuote.nushell.gif
Output out/doubleQuote.nushell.ascii

Type `example "ac"` Sleep 1 Tab@1

Sleep 2
8 changes: 8 additions & 0 deletions docs/src/development/vhs/doubleQuote/doubleQuote.oil.tape
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Source ../oil.tape

Output out/doubleQuote.oil.gif
Output out/doubleQuote.oil.ascii

Type `example "ac"` Sleep 1 Tab@1

Sleep 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Source ../powershell.tape

Output out/doubleQuote.powershell.gif
Output out/doubleQuote.powershell.ascii

Type `example "ac"` Sleep 1 Tab@1

Sleep 2
8 changes: 8 additions & 0 deletions docs/src/development/vhs/doubleQuote/doubleQuote.xonsh.tape
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Source ../xonsh.tape

Output out/doubleQuote.xonsh.gif
Output out/doubleQuote.xonsh.ascii

Type `example "ac"` Sleep 1 Tab@1

Sleep 2
8 changes: 8 additions & 0 deletions docs/src/development/vhs/doubleQuote/doubleQuote.zsh.tape
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Source ../zsh.tape

Output out/doubleQuote.zsh.gif
Output out/doubleQuote.zsh.ascii

Type `example "ac"` Sleep 1 Tab@1

Sleep 2
40 changes: 40 additions & 0 deletions docs/src/development/vhs/doubleQuote/out/doubleQuote.bash.ascii
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
>






────────────────────────────────────────────────────────────────────────────────
> example "ac"






────────────────────────────────────────────────────────────────────────────────
> example "ac"






────────────────────────────────────────────────────────────────────────────────
> example action






────────────────────────────────────────────────────────────────────────────────
> example action






────────────────────────────────────────────────────────────────────────────────
Loading

0 comments on commit 761a5cf

Please sign in to comment.