mterm-io / mterm

An electron terminal written with TypeScript, and rendered with React. Extend your terminal with themes, plugins and commands written in typescript. Scripting for the modern age.
https://mterm.io
9 stars 0 forks source link

fix: content api for frontend events from backend, ui updates and reset command #101

Closed daretodave closed 6 months ago

daretodave commented 6 months ago

resolves #14

introduces the context.content() operation

content can have events attached to them e.g

  const no = context.content(`<button>No</button>`)

  no.on('click', () => {
    context.out('\n\nDeclined reset')
    context.finish(0)
  })

or more complex -

  context.out('Reset all mterm settings, commands, modules?\n')

  const yes = context.content(`<button>Yes</button>`)

  context.out('|')

  const no = context.content(`<button>No</button>`)

  no.on('click', () => {
    context.out('\n\nDeclined reset')
    context.finish(0)
  })

  yes.on('click', async () => {
    context.out('\n\nCleaning...')

    await remove(context.workspace.folder)

    context.out('\nReloading...')

    await context.workspace.load()
    context.out('- settings reloaded \n')

    await context.workspace.commands.load(context.workspace.settings)
    context.out('- commands reloaded \n')

    await context.workspace.reload(RunnerWindow)
    context.out('- window reloaded \n')

    context.finish(0)
  })

image

content can also be updated e.g (a clock)

  context.out('Time: ')

  let minute = 0
  let second = 0

  const M = context.content(`<span>00</span>`)

  context.out(':')

  const S = context.content(`<span>00</span>`)

  setInterval(() => {
    S.update(`<span>${`${second++}`.padStart(2, '0')}</span>`)
  }, 1000)
  setInterval(() => {
    M.update(`<span>${`${minute++}`.padStart(2, '0')}</span>`)
  }, 1000 * 60)

image