feat: Filterchains can now be passed inputs and outputs.

This commit is contained in:
Spencer Brower
2024-02-24 11:27:58 -05:00
parent 7ce5f70980
commit aa5c8fe9c9
2 changed files with 51 additions and 5 deletions

View File

@@ -36,9 +36,7 @@ export def "run" [
def "append last" [ def "append last" [
items: list items: list
]: list -> list { ]: list -> list {
let list = $in; update (($in | length) - 1) { $in | append $items }
($list | range 0..-2) | append [($list | default [] | last | append $items)]
} }
export def "cmd filters append" [ export def "cmd filters append" [
@@ -97,8 +95,8 @@ def "filter to-string" []: record<input: list<string> name: string params: table
# Set the input and outputs of a filter chain # Set the input and outputs of a filter chain
export def filterchain [ export def filterchain [
#input: list<string> --input (-i): list<string>
#output: list<string> --output (-o): list<string>
filter: closure filter: closure
] { ] {
let cmd = $in; let cmd = $in;
@@ -118,6 +116,22 @@ export def filterchain [
} }
} }
| do $filter | do $filter
| if ($input | is-empty | not $in) {
update filters {
update (($in | length) - 1) {
update 0.input $input
}
}
} else { $in }
| if ($output | is-empty | not $in) {
update filters {
update (($in | length) - 1) {
update (($in | length) - 1) {
update output $output
}
}
}
} else { $in }
| update options.chain_filters $original_option | update options.chain_filters $original_option
); );
} }

View File

@@ -227,3 +227,35 @@ def filterchain_appends_current_filter [] {
options: { chain_filters: false } options: { chain_filters: false }
}; };
} }
#[test]
def filterchains_can_set_inputs_and_outputs [] {
let got = (cmd ['INPUT'] ['OUTPUT'] | filterchain -i ['in'] -o ['out'] { fps 25 | settb '1/25' });
assert equal $got {
input: ['INPUT']
filters: [
[
{
input: ['in']
name: 'fps'
params: [
{param: 'fps' value: '25'}
]
output: []
}
{
input: []
name: 'settb'
params: [
{param: 'expr' value: '1/25'}
]
output: ['out']
}
]
]
output: ['OUTPUT']
args: []
options: { chain_filters: false }
}
}