Skip to content

Commit 7b7258c

Browse files
committed
feat: interpreter
1 parent f86b904 commit 7b7258c

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

README.md

+14-2
Original file line numberDiff line numberDiff line change
@@ -128,17 +128,18 @@ directive is required.
128128
| `commands` | See [Commands](#commands) | `Object` | `{}` | No | No |
129129
| `cursor-position` | Cursor position | `Number` | `0` | No | Yes |
130130
| `dispatched-queries` | Non-empty dispatched queries | `Set` | `new Set()` | No | Yes |
131-
| `event-resolver` | See [Event resolver](#Event-resolver) | `Function` | `newDefaultEventResolver` | No | No |
131+
| `event-resolver` | See [Event resolver](#event-resolver) | `Function` | `newDefaultEventResolver` | No | No |
132132
| `help-text` | Command help | `String` | `''` | No | Yes |
133133
| `help-timeout` | Command help timeout | `Number` | `3000` | No | No |
134134
| `hide-bar` | Hides the bar | `Boolean` | `false` | No | No |
135135
| `hide-prompt` | Hides the prompt | `Boolean` | `false` | No | No |
136136
| `hide-title` | Hides the title | `Boolean` | `false` | No | No |
137137
| `history` | Terminal history | `Array` | `[]` | No | Yes |
138138
| `history-position` | Points to the latest dispatched query entry | `Number` | `0` | No | Yes |
139+
| `interpreter` | See [Interpreter](#interpreter) | `Function` | `null` | No | No |
139140
| `invert` | Inverts the terminals colors | `Boolean` | `false` | No | No |
140141
| `is-fullscreen` | Terminal fullscreen mode | `Boolean` | `false` | No | Yes |
141-
| `options-resolver` | See [Options resolver](#Options-resolver) | `Function` | `null` | No | No |
142+
| `options-resolver` | See [Options resolver](#options-resolver) | `Function` | `null` | No | No |
142143
| `parser` | Query parser | `Function` | `defaultParser` | No | No |
143144
| `prompt` | Terminal prompt | `String` | `~$` | No | No |
144145
| `show-help` | Show query help | `Boolean` | `false` | No | No |
@@ -171,6 +172,17 @@ as the query has been autocompleted by the terminal, it's calling the options
171172
resolver provided as property. The resolver is called with the program, parsed
172173
query and a setter to update the query.
173174

175+
### Interpreter
176+
177+
An interpreter allows to execute arbitrary code after the query has been
178+
dispatched and to not rely on missing functionality which includes pipes,
179+
streams or running multiple commands in parallel.
180+
181+
The interpreter is a property function that is called with the unparsed query
182+
right after the query component calls `dispatch` and terminates it at the same
183+
time. After the call, you must use the [properties](#properties) and
184+
[exposed functions](#exposed) to reach the desired behaviour.
185+
174186
## Slots
175187

176188
### Bar

src/components/VueCommand.vue

+18-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@
7171
'vue-command__history__entry': !invert,
7272
'vue-command__history__entry--invert': invert,
7373
'vue-command__history__entry--fullscreen': shouldBeFullscreen(index),
74-
'vue-command__history__entry--fullscreen--invert': invert && shouldBeFullscreen(index)
74+
'vue-command__history__entry--fullscreen--invert': and(
75+
invert,
76+
shouldBeFullscreen(index)
77+
)
7578
}">
7679
<!-- Components -->
7780
<component
@@ -204,6 +207,14 @@ const props = defineProps({
204207
type: Boolean
205208
},
206209
210+
// An interpreter allows to execute arbitrary code after a query has been
211+
// dispatched
212+
interpreter: {
213+
default: null,
214+
required: false,
215+
type: Function
216+
},
217+
207218
isFullscreen: {
208219
default: false,
209220
required: false,
@@ -345,6 +356,12 @@ const appendToHistory = (...components) => {
345356
// Parses the query, looks for a user given command and appends the resulting
346357
// component to the history
347358
const dispatch = async query => {
359+
// Call given interpreter to execute arbitrary code, if given
360+
if (isFunction(props.interpreter)) {
361+
props.interpreter(query)
362+
return
363+
}
364+
348365
// An empty query is an empty string
349366
if (isEmpty(query)) {
350367
appendToHistory(createQuery())

src/hosted/App.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
v-model:dispatched-queries="dispatchedQueries"
1717
v-model:is-fullscreen="isFullscreen"
1818
v-model:history="history"
19-
v-model:historyPosition="historyPosition"
19+
v-model:history-position="historyPosition"
2020
v-model:query="query"
2121
:commands="commands"
2222
:help-text="helpText"

0 commit comments

Comments
 (0)