packages/core/src/modules/answer.ts
import { IQCoreAssets, IQModuleACLS, IQFrameColorOptions, IQMenuLoopMessageResponse, IQModule, IQModuleRuntime, IQReactor, IQ } from "../index"
import { IQCoreModules } from "./index"
@IQModule({
basepath: "/iniquity/core/src/assets",
access: IQModuleACLS.low,
assets: "",
encoding: "CP437",
data: IQReactor({
message: "Umm, yeah this needs to change",
number: 1,
time: time(),
system: system.stats
}),
computed: {}
})
class Answer extends IQ {
@IQModuleRuntime({
debug: true
})
start() {
/** Observe changes to "message" and react */
this.data.observe("message", () => {
const box = { width: 40, height: 5 }
const frame = this.frame({
x: (this.terminfo.x - box.width) / 2,
y: (this.terminfo.y - box.height) / 2,
width: box.width,
height: box.height,
color: IQFrameColorOptions.black
})
frame.open()
frame.say(this.data.model.message)
frame.draw()
this.wait(3000)
frame.close()
})
// For terminals that are too small e.g 80x25.
while (this.terminfo.x < 132 || this.terminfo.y < 37) {
const menu = this.menu({
name: "Unsupported terminal scale.",
description: "A simple menu for letting the user know their terminal settings are not supported.",
commands: {
/**
* Perhaps you want to be able to capture some data from a command once it's hit.
* Maybe there is information you have generated and you want it available nicely as
* a data structure.
* @param options
* @returns
*/
Q: (options = { description: "Go wide screen bbs with 132x37!" }) => {
return { options }
},
E: (options = { description: "Disconnect from iniquity." }) => {
// this.data.model.message = this.ask("What should I change the message to?")
return { options }
},
default: (options = { description: "Disconnect from iniquity." }) => {
// this.say("please try again.".gotoxy(1, 1))
return { options }
}
}
})
menu.render(
(res: IQMenuLoopMessageResponse, cmdkey: Function) => {
this.artwork({ filename: IQCoreAssets.sm_iniq2 }).render({
clearScreenBefore: true,
mode: "line",
data: { ...this.data.model, ...menu }
})
const frame = this.frame({
x: 32,
y: 10,
width: 40,
height: 4,
color: IQFrameColorOptions.black
})
for (const [cmdkey, command] of Object.entries(menu.commands))
frame.say(`${cmdkey} : ${command().options.description}\r\n`.color("white"))
frame.draw()
menu.prompt({ text: "commands: ".color("bright cyan"), x: 20, y: 20 }).command(cmdkey)
},
{
maxInterval: 3000,
data: this.data
}
)
this.wait(100)
}
IQCoreModules.wfc()
}
}
export { Answer }
export default new Answer()