Skip to content

Commit 575fd26

Browse files
committed
Fix errors
1 parent d33febe commit 575fd26

File tree

9 files changed

+47
-31
lines changed

9 files changed

+47
-31
lines changed

assets/locales/en/asset.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
"platforms": {
7676
"darwin-icon": "terminal:macos",
7777
"linux-icon": "terminal:linux",
78-
"win32-icon": "terminal:windows"
78+
"win32-icon": "grid-2x2"
7979
},
8080
"profile-icon": "$t(asset:generic.terminal-alt-icon)",
8181
"profile-types": {

sources/icons.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@ import {
22
UnnamespacedID,
33
registerIcon,
44
} from "@polyipseity/obsidian-plugin-library"
5-
import { siLinux, siMacos, siWindows } from "simple-icons"
5+
import { siLinux, siMacos } from "simple-icons"
66
import type { TerminalPlugin } from "./main.js"
77

88
export function loadIcons(context: TerminalPlugin): void {
99
for (const [key, value] of Object.entries({
1010
linux: siLinux,
1111
macos: siMacos,
12-
windows: siWindows,
1312
})) {
1413
registerIcon(
1514
context,

sources/patch.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ export class EarlyPatchManager extends ResourceComponent<EarlyPatch> {
192192

193193
public constructor(
194194
protected readonly app: App,
195-
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
196195
protected readonly options?: Parameters<typeof earlyPatch>[1],
197196
) { super() }
198197

@@ -217,6 +216,7 @@ function patchRequire(
217216
const { settings } = context
218217
return around(self0, {
219218
require(next) {
219+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
220220
return function fn(
221221
this: typeof self0 | undefined,
222222
...args: Parameters<typeof next>
@@ -228,7 +228,7 @@ function patchRequire(
228228
/* @__PURE__ */ self0.console.debug(error)
229229
return dynamicRequireSync(new Map(), ...args)
230230
}
231-
} as NodeRequire
231+
} as NodeJS.Require
232232
},
233233
toString: aroundIdentityFactory(),
234234
})

sources/settings-data.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,8 @@ export namespace Settings {
217217
profile,
218218
})
219219
}
220-
export type Platforms<T extends string> = { readonly [_ in T]?: boolean }
220+
export type Platforms<T extends string> =
221+
Readonly<Partial<Record<T, boolean>>>
221222
interface Base {
222223
readonly type: Type
223224
readonly name: string
@@ -304,7 +305,7 @@ export namespace Settings {
304305
V extends Platforms<Vs[number]>,
305306
const Vs extends ReadonlyTuple<string>,
306307
>(defaults: V, from: Unchecked<V>, set: Vs): Platforms<Vs[number]> => {
307-
const ret2: { [_ in Vs[number]]?: boolean } = {}
308+
const ret2: Partial<Record<Vs[number], boolean>> = {}
308309
for (const platform0 of set) {
309310
const platform: Vs[number] = platform0
310311
if (!(platform in from)) { continue }
@@ -641,6 +642,7 @@ export namespace Settings {
641642
: ((): ILinkHandler => {
642643
const unc2 = launderUnchecked<ILinkHandler>(unc.linkHandler),
643644
ret = {
645+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
644646
activate: fixTyped(
645647
DEFAULT_LINK_HANDLER,
646648
unc2,
@@ -653,12 +655,14 @@ export namespace Settings {
653655
"allowNonHttpProtocols",
654656
["undefined", "boolean"],
655657
),
658+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
656659
hover: fixTyped(
657660
DEFAULT_LINK_HANDLER,
658661
unc2,
659662
"hover",
660663
["undefined", "function"],
661664
) as ILinkHandler["hover"],
665+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
662666
leave: fixTyped(
663667
DEFAULT_LINK_HANDLER,
664668
unc2,
@@ -682,30 +686,35 @@ export namespace Settings {
682686
: ((): ILogger => {
683687
const unc2 = launderUnchecked<ILogger>(unc.logger),
684688
ret = {
689+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
685690
debug: fixTyped(
686691
DEFAULT_LOGGER,
687692
unc2,
688693
"debug",
689694
["function"],
690695
) as ILogger["debug"],
696+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
691697
error: fixTyped(
692698
DEFAULT_LOGGER,
693699
unc2,
694700
"error",
695701
["function"],
696702
) as ILogger["error"],
703+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
697704
info: fixTyped(
698705
DEFAULT_LOGGER,
699706
unc2,
700707
"info",
701708
["function"],
702709
) as ILogger["info"],
710+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
703711
trace: fixTyped(
704712
DEFAULT_LOGGER,
705713
unc2,
706714
"trace",
707715
["function"],
708716
) as ILogger["trace"],
717+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
709718
warn: fixTyped(
710719
DEFAULT_LOGGER,
711720
unc2,

sources/terminal/emulator-addons.ts

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export class DisposerAddon extends Functions implements ITerminalAddon {
1515
super({ async: false, settled: true }, ...args)
1616
}
1717

18+
// eslint-disable-next-line @typescript-eslint/class-methods-use-this
1819
public activate(_terminal: Terminal): void {
1920
// Noop
2021
}

sources/terminal/profile-presets.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,14 @@ export interface ProfilePresets0 {
7070
readonly wslIntegrated: Settings.Profile.Integrated
7171
readonly zshIntegrated: Settings.Profile.Integrated
7272
}
73-
type ExternalDefaults = {
74-
readonly [_ in `${Pseudoterminal.SupportedPlatforms[number]
75-
}ExternalDefault`]: Settings.Profile.External
76-
}
77-
type IntegratedDefaults = {
78-
readonly [_ in `${Pseudoterminal.SupportedPlatforms[number]
79-
}IntegratedDefault`]: Settings.Profile.Integrated
80-
}
73+
type ExternalDefaults = Readonly<
74+
Record<`${Pseudoterminal.SupportedPlatforms[number]
75+
}ExternalDefault`, Settings.Profile.External>
76+
>
77+
type IntegratedDefaults = Readonly<
78+
Record<`${Pseudoterminal.SupportedPlatforms[number]
79+
}IntegratedDefault`, Settings.Profile.Integrated>
80+
>
8181
export interface ProfilePresets
8282
extends ProfilePresets0, ExternalDefaults, IntegratedDefaults { }
8383
const PROFILE_PRESETS0 = deepFreeze({

sources/terminal/pseudoterminal.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import {
4040
remove,
4141
replaceAllRegex,
4242
sleep2,
43+
toJSONOrString,
4344
typedKeys,
4445
} from "@polyipseity/obsidian-plugin-library"
4546
import type { IMarker, Terminal } from "@xterm/xterm"
@@ -118,7 +119,7 @@ export class RefPsuedoterminal<T extends Pseudoterminal,
118119
}
119120
this.delegate.onExit.then(
120121
async ret => { (await this.#exit).resolve(ret) },
121-
async error => { (await this.#exit).reject(error) },
122+
async (error: unknown) => { (await this.#exit).reject(error) },
122123
)
123124
++this.#ref[0]
124125
}
@@ -981,7 +982,7 @@ class UnixPseudoterminal implements Pseudoterminal {
981982
const [shell, stream2] = await Promise.all([this.shell, stream]),
982983
cmdio = shell.stdio[UnixPseudoterminal.#cmdio]
983984
if (!(cmdio instanceof stream2.Writable)) {
984-
throw new TypeError(String(cmdio))
985+
throw new TypeError(toJSONOrString(cmdio))
985986
}
986987
await writePromise(cmdio, `${columns}x${rows}\n`)
987988
}

sources/terminal/util.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,8 @@ export class TerminalTextArea implements IDisposable {
247247
datum !== void 0;
248248
datum = data0.shift()) {
249249
const { cursorX, cursorY } = active,
250-
lineWidth = this.#widths[cursorY] ?? 0,
250+
// eslint-disable-next-line no-multi-assign
251+
lineWidth = this.#widths[cursorY] ??= 0,
251252
line = active.getLine(cursorY)
252253
switch (datum) {
253254
case "": break

sources/terminal/view.ts

+18-13
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import {
2020
consumeEvent,
2121
createChildElement,
2222
deepFreeze,
23-
destroyWithOutro,
2423
dynamicRequire,
2524
extname,
2625
fixTyped,
@@ -61,6 +60,7 @@ import {
6160
openProfile,
6261
} from "./profile-properties.js"
6362
import { cloneDeep, noop } from "lodash-es"
63+
import { mount, unmount } from "svelte"
6464
import { BUNDLE } from "../import.js"
6565
import type { DeepWritable } from "ts-essentials"
6666
import type { LigaturesAddon } from "@xterm/addon-ligatures"
@@ -258,7 +258,7 @@ export class TerminalView extends ItemView {
258258
protected readonly focusedScope = new Scope()
259259
#title0 = ""
260260
#emulator0: TerminalView.EMULATOR | null = null
261-
#find0: FindComponent | null = null
261+
#find0: ReturnType<typeof FindComponent> | null = null
262262
#state = TerminalView.State.DEFAULT
263263

264264
public constructor(
@@ -303,7 +303,7 @@ export class TerminalView extends ItemView {
303303
return this.#emulator0
304304
}
305305

306-
get #find(): FindComponent | null {
306+
get #find(): ReturnType<typeof FindComponent> | null {
307307
return this.#find0
308308
}
309309

@@ -368,8 +368,13 @@ export class TerminalView extends ItemView {
368368
this.#emulator0 = val
369369
}
370370

371-
set #find(val: FindComponent | null) {
372-
if (this.#find) { destroyWithOutro(this.#find) }
371+
set #find(val: ReturnType<typeof FindComponent> | null) {
372+
if (this.#find) {
373+
unmount(this.#find, { outro: true })
374+
.catch((error: unknown) => {
375+
activeSelf(this.contentEl).console.warn(error)
376+
})
377+
}
373378
this.#find0 = val
374379
}
375380

@@ -498,7 +503,7 @@ export class TerminalView extends ItemView {
498503

499504
this.register(language.onChangeLanguage.listen(() => {
500505
updateView(context, this)
501-
this.#find?.$set({ i18n: i18n.t })
506+
this.#find?.setI18n(i18n.t)
502507
}))
503508

504509
this.register(() => { keymap.popScope(scope) })
@@ -564,11 +569,11 @@ export class TerminalView extends ItemView {
564569
/* @__PURE__ */ activeSelf(contentEl).console.debug(error)
565570
empty = true
566571
}
567-
if (empty) { this.#find?.$set({ results: "" }) }
572+
if (empty) { this.#find?.setResults("") }
568573
},
569574
optional: { anchor?: Element } = {}
570575
assignExact(optional, "anchor", contentEl.firstElementChild ?? void 0)
571-
this.#find = new FindComponent({
576+
this.#find = mount(FindComponent, {
572577
intro: true,
573578
props: {
574579
i18n: i18n.t,
@@ -583,8 +588,8 @@ export class TerminalView extends ItemView {
583588
...optional,
584589
})
585590
}
586-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
587-
this.#find["focus"]()
591+
592+
this.#find.focus()
588593
}
589594

590595
protected startEmulator(focus: boolean): void {
@@ -715,7 +720,7 @@ export class TerminalView extends ItemView {
715720
emulator.reopen()
716721
emulator.resize(false).catch(warn)
717722
}),
718-
() => { this.#find?.$set({ results: "" }) },
723+
() => { this.#find?.setResults("") },
719724
),
720725
dragAndDrop: new DragAndDropAddon(ele),
721726
ligatures: new LigaturesAddon({}),
@@ -747,7 +752,7 @@ export class TerminalView extends ItemView {
747752
: settings.value.errorNoticeTimeout,
748753
context,
749754
)
750-
}, error => {
755+
}, (error: unknown) => {
751756
printError(anyToError(error), () =>
752757
i18n.t("errors.error-spawning-terminal"), context)
753758
})
@@ -775,7 +780,7 @@ export class TerminalView extends ItemView {
775780
index: resultIndex + 1,
776781
},
777782
})
778-
this.#find?.$set({ results })
783+
this.#find?.setResults(results)
779784
})
780785

781786
emulator.resize().catch(warn)

0 commit comments

Comments
 (0)