Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mkasout #63

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions packages/frontend/src/components/MkAsOut.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<!--
SPDX-FileCopyrightText: syuilo and misskey-project
SPDX-License-Identifier: AGPL-3.0-only
-->

<template>
<div :class="$style.root">
<div v-for="log in model.logs" :key="log.id" :class="$style[log.type]">{{ log.text }}</div>
</div>
</template>

<script lang="ts">
export class AsOutTL {
constructor(){}

Check failure on line 14 in packages/frontend/src/components/MkAsOut.vue

View workflow job for this annotation

GitHub Actions / lint (frontend)

Missing space before opening brace
readonly logs = ref<AsOutLog[]>([]);

Check failure on line 15 in packages/frontend/src/components/MkAsOut.vue

View workflow job for this annotation

GitHub Actions / lint (frontend)

'AsOutLog' is not defined
private push(type: AsOutLog['type'], text: string) {

Check failure on line 16 in packages/frontend/src/components/MkAsOut.vue

View workflow job for this annotation

GitHub Actions / lint (frontend)

'AsOutLog' is not defined
this.logs.value.push({type, text, id: Math.random().toString()});

Check failure on line 17 in packages/frontend/src/components/MkAsOut.vue

View workflow job for this annotation

GitHub Actions / lint (frontend)

A space is required after '{'

Check failure on line 17 in packages/frontend/src/components/MkAsOut.vue

View workflow job for this annotation

GitHub Actions / lint (frontend)

A space is required before '}'
}
flush() { this.logs.value = [] }

Check failure on line 19 in packages/frontend/src/components/MkAsOut.vue

View workflow job for this annotation

GitHub Actions / lint (frontend)

Missing semicolon
out(value: values.Value): void {
this.push('out', value.type === 'str' ? value.value : utils.valToString(value));
}
log(type: string, params: values.Value): void {
switch (type) {
case 'end':
this.push('log', utils.valToString(params.val, true));
default: break;

Check failure on line 27 in packages/frontend/src/components/MkAsOut.vue

View workflow job for this annotation

GitHub Actions / lint (frontend)

Expected a 'break' statement before 'default'
}
}
logManually(mes: string): void {
this.push('log', mes);
}
err(err: errors.AiScriptError): void {
this.push('err', `${err}`);
}
};

Check failure on line 36 in packages/frontend/src/components/MkAsOut.vue

View workflow job for this annotation

GitHub Actions / lint (frontend)

Unnecessary semicolon
</script>

<script lang="ts" setup>
import { ref } from 'vue';
import { values, utils, errors } from '@syuilo/aiscript';

const model = defineModel<AsOutTL>({ required: true });

type AsOutLog = {
type: 'out' | 'log' | 'err',
text: string,
id: string,
};
</script>

<style lang="scss" module>
.root {
padding: 16px;
}

.out {
}
.log {
opacity: 0.7;
}
.err {
color: var(--error);
}
</style>
39 changes: 7 additions & 32 deletions packages/frontend/src/pages/scratchpad.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ SPDX-License-Identifier: AGPL-3.0-only

<MkContainer :foldable="true" class="">
<template #header>{{ i18n.ts.output }}</template>
<div :class="$style.logs">
<div v-for="log in logs" :key="log.id" class="log" :class="{ print: log.print }">{{ log.text }}</div>
</div>
<MkAsOut v-model="logtl"/>
</MkContainer>

<div class="">
Expand All @@ -51,13 +49,14 @@ import { i18n } from '@/i18n.js';
import { definePageMetadata } from '@/scripts/page-metadata.js';
import { AsUiComponent, AsUiRoot, registerAsUiLib } from '@/scripts/aiscript/ui.js';
import MkAsUi from '@/components/MkAsUi.vue';
import MkAsOut, { AsOutTL } from '@/components/MkAsOut.vue';
import { miLocalStorage } from '@/local-storage.js';
import { claimAchievement } from '@/scripts/achievements.js';

const parser = new Parser();
let aiscript: Interpreter;
const code = ref('');
const logs = ref<any[]>([]);
const logtl = new AsOutTL();
const root = ref<AsUiRoot>();
const components = ref<Ref<AsUiComponent>[]>([]);
const uiKey = ref(0);
Expand All @@ -76,7 +75,7 @@ async function run() {
root.value = undefined;
components.value = [];
uiKey.value++;
logs.value = [];
logtl.flush();
aiscript = new Interpreter(({
...createAiScriptEnv({
storageKey: 'widget',
Expand All @@ -91,29 +90,17 @@ async function run() {
if (value.type === 'str' && value.value.toLowerCase().replace(',', '').includes('hello world')) {
claimAchievement('outputHelloWorldOnScratchpad');
}
logs.value.push({
id: Math.random(),
text: value.type === 'str' ? value.value : utils.valToString(value),
print: true,
});
logtl.out(value);
},
err: (err) => {
os.alert({
type: 'error',
title: 'AiScript Error',
text: err.toString(),
});
logtl.err(err);
},
log: (type, params) => {
switch (type) {
case 'end': logs.value.push({
id: Math.random(),
text: utils.valToString(params.val, true),
print: false,
}); break;
default: break;
}
},
log: logtl.log,
});

let ast;
Expand Down Expand Up @@ -180,16 +167,4 @@ definePageMetadata(() => ({
.ui {
padding: 32px;
}

.logs {
padding: 16px;

&:global {
> .log {
&:not(.print) {
opacity: 0.7;
}
}
}
}
</style>
Loading