Skip to content

Commit f92d85c

Browse files
committed
fix: set font
1 parent 9c7ed25 commit f92d85c

File tree

3 files changed

+29
-18
lines changed

3 files changed

+29
-18
lines changed

Diff for: README.md

+2
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ directive is required.
129129
| `cursor-position` | Cursor position | `Number` | `0` | No | Yes |
130130
| `dispatched-queries` | Non-empty dispatched queries | `Set` | `new Set()` | No | Yes |
131131
| `event-resolver` | See [Event resolver](#event-resolver) | `Function` | `newDefaultEventResolver` | No | No |
132+
| `font` | Terminal font | `String` | `''` | No | No |
132133
| `help-text` | Command help | `String` | `''` | No | Yes |
133134
| `help-timeout` | Command help timeout | `Number` | `3000` | No | No |
134135
| `hide-bar` | Hides the bar | `Boolean` | `false` | No | No |
@@ -246,6 +247,7 @@ Library provides helper methods to render terminal related content.
246247
| Function | Parameters | Description |
247248
| ----------------------------- | ------------------------------------------------------------------ | ------------------------------------- |
248249
| `createCommandNotFound` | `command, text = 'command not found', name = 'VueCommandNotFound'` | Creates a command not found component |
250+
| `createStderr` | `formatterOrText, name = 'VueCommandStderr'` | Creates a "stderr" component |
249251
| `createStdout` | `formatterOrText, name = 'VueCommandStdout'` | Creates a "stdout" component |
250252
| `createQuery` | | Creates a query component |
251253
| `defaultHistoryEventResolver` | `refs, eventProvider` | The default history event resolver |

Diff for: src/components/VueCommand.vue

+14-15
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,12 @@ const props = defineProps({
166166
type: Array
167167
},
168168
169+
font: {
170+
default: '',
171+
required: false,
172+
type: String
173+
},
174+
169175
helpText: {
170176
default: null,
171177
required: false,
@@ -271,12 +277,6 @@ const props = defineProps({
271277
default: '',
272278
required: false,
273279
type: String
274-
},
275-
276-
font: {
277-
default: undefined,
278-
required: false,
279-
type: String
280280
}
281281
})
282282
@@ -306,22 +306,21 @@ const local = reactive({
306306
historyPosition: props.historyPosition,
307307
isFullscreen: props.isFullscreen,
308308
prompt: props.prompt,
309-
query: props.query,
310-
font: props.font
309+
query: props.query
311310
})
312311
// Signals like SIGINT or SIGKILL
313312
const signals = reactive(newEventBus())
314313
// Reactive terminal state
315314
const terminal = computed(() => ({
316315
cursorPosition: local.cursorPosition,
317316
dispatchedQueries: local.dispatchedQueries,
317+
font: props.font,
318318
history: local.history,
319319
historyPosition: local.historyPosition,
320320
invert: props.invert,
321321
isFullscreen: local.isFullscreen,
322322
prompt: local.prompt,
323-
query: local.query,
324-
font: local.font
323+
query: local.query
325324
}))
326325
327326
// Provided commands as programs. It takes the keys of the commands object
@@ -378,7 +377,7 @@ const appendToHistory = (...components) => {
378377
// Parses the query, looks for a user given command and appends the resulting
379378
// component to the history
380379
const dispatch = async query => {
381-
// Call given interpreter to execute arbitrary code, if given
380+
// Call optional interpreter to execute arbitrary code
382381
if (isFunction(props.interpreter)) {
383382
props.interpreter(query)
384383
return
@@ -413,7 +412,7 @@ const dispatch = async query => {
413412
// instantly to history
414413
// TODO Find a better way to find out the name
415414
if (eq(get(command, '__name'), 'VueCommandQuery')) {
416-
appendToHistory(command)
415+
exit()
417416
return
418417
}
419418
@@ -435,9 +434,9 @@ const dispatch = async query => {
435434
})
436435
appendToHistory(markRaw(component))
437436
}
438-
// Tear down component and execute final steps
437+
// Tear down component, execute final steps and return a new query
439438
const exit = () => {
440-
// TODO Does order matter?
439+
// TODO: Does order matter?
441440
appendToHistory(createQuery())
442441
setCursorPosition(0)
443442
setFullscreen(false)
@@ -522,7 +521,7 @@ onMounted(() => {
522521
523522
// Scroll to bottom if history changes
524523
const resizeObsever = new ResizeObserver(() => {
525-
// TODO Only scroll to bottom if user scrolled to bottom before
524+
// TODO: Only scroll to bottom if user scrolled to bottom before
526525
vueCommandHistoryRef.value.scrollTop = vueCommandHistoryRef.value.scrollHeight
527526
})
528527
for (const vueCommandHistoryEntry of vueCommandHistoryRef.value.children) {

Diff for: src/components/VueCommandQuery.vue

+13-3
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@
88
<VueCommandPrompt />
99

1010
<!-- Query -->
11-
<!-- TODO Convert to textarea to enforce word breaks -->
11+
<!-- TODO: Implement line breaks -->
1212
<input
1313
ref="queryRef"
1414
v-model="local.query"
1515
class="vue-command__query__input"
1616
:disabled="isOutdatedQuery"
1717
:placeholder="placeholder"
18+
:style="queryStyle"
1819
autocapitalize="none"
1920
autocorrect="off"
2021
type="text"
21-
:style="terminal.font ? { 'font': `1rem ${terminal.font}`} : {}"
2222
@click="setCursorPosition($refs.queryRef.selectionStart)"
2323
@keydown.tab.exact.prevent="autocompleteQuery"
2424
@keydown.ctrl.r.exact.prevent="showReverseISearch()"
@@ -40,6 +40,7 @@
4040
ref="multilineQueryRefs"
4141
class="vue-command__multiline-query__input"
4242
:disabled="isOutdatedMultilineQuery(index)"
43+
:style="queryStyle"
4344
:value="multilineQuery"
4445
autocapitalize="none"
4546
autocorrect="off"
@@ -63,6 +64,7 @@
6364
v-model="reverseISearch"
6465
class="vue-command__reverse-i-search__input"
6566
:disabled="isOutdated"
67+
:style="queryStyle"
6668
autocapitalize="none"
6769
autocorrect="off"
6870
type="text"
@@ -163,9 +165,17 @@ const VueCommandPrompt = computed(() => {
163165
class: 'vue-command__query__prompt'
164166
}, prompt))
165167
})
168+
const queryStyle = computed(() => {
169+
if (!isEmpty(terminal.value.font)) {
170+
return {
171+
font: `1rem ${terminal.value.font}`
172+
}
173+
}
174+
175+
return {}
176+
})
166177
167178
const local = reactive({
168-
prompt: terminal.value.prompt,
169179
query: ''
170180
})
171181
// Entered with "\"

0 commit comments

Comments
 (0)