Initial version of scripting (#40)

* scripting: added service and controller for scripting

* scripting: have got prompts working

Scripts are now running in a separate go-routine.  When a prompt is encountered, the
script is paused and the user is prompted for input.  This means that the script no
longer needs to worry about synchronisation issues.

* scripting: started working on the session methods

* scripting: added methods to get items and attributes

* scripting: have got loading of scripts working

These act more like plugins and allow defining new commands.

* scripting: have got script scheduling working

Scripts are now executed on a dedicated goroutine and only one script can run at any one time.

* scripting: added session.set_result_set(rs)

* scripting: upgraded tamarin to 0.14

* scripting: started working on set_value

* tamarin: replaced ad-hoc path with query expressions

* scripting: changed value() and set_value() to attr() and set_attr()

Also added 'delete_attr()'

* scripting: added os.exec()

This method is controlled by permissions which govern whether shellouts are allowed
Also fixed a resizing bug with the status window which was not properly handling status messages with newlines

* scripting: added the session.current_item() method

* scripting: added placeholders to query expressions

* scripting: added support for setting and deleteing items with placeholders

Also refactored the dot AST type so that it support placeholders.  Placeholders are not yet supported
for subrefs yet, they need to be identifiers.

* scripting: made setting the result-set push the current result-set to the backstack

* scripting: started working on byte encoding of attribute values

* scripting: finished attrcodec

* scripting: integrated codec into expression

* scripting: added equals and hashcode to queryexpr

This finally finishes the work required to store queries in the backstack

* scripting: fixed some bugs with the back-stack

* scripting: upgraded Tamarin

* scripting: removed some commented out code
This commit is contained in:
Leon Mika 2023-01-10 22:27:13 +11:00 committed by GitHub
parent cd9700569c
commit c89b09447c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
66 changed files with 4588 additions and 281 deletions

View file

@ -15,12 +15,14 @@ import (
)
type CommandController struct {
commandList *CommandList
commandList *CommandList
lookupExtensions []CommandLookupExtension
}
func NewCommandController() *CommandController {
return &CommandController{
commandList: nil,
commandList: nil,
lookupExtensions: nil,
}
}
@ -29,6 +31,10 @@ func (c *CommandController) AddCommands(ctx *CommandList) {
c.commandList = ctx
}
func (c *CommandController) AddCommandLookupExtension(ext CommandLookupExtension) {
c.lookupExtensions = append(c.lookupExtensions, ext)
}
func (c *CommandController) Prompt() tea.Msg {
return events.PromptForInputMsg{
Prompt: ":",
@ -80,6 +86,12 @@ func (c *CommandController) lookupCommand(name string) Command {
return cmd
}
}
for _, exts := range c.lookupExtensions {
if cmd := exts.LookupCommand(name); cmd != nil {
return cmd
}
}
return nil
}

View file

@ -15,3 +15,7 @@ type CommandList struct {
parent *CommandList
}
type CommandLookupExtension interface {
LookupCommand(name string) Command
}

View file

@ -20,6 +20,7 @@ type ModeMessage string
// PromptForInput indicates that the context is requesting a line of input
type PromptForInputMsg struct {
Prompt string
OnDone func(value string) tea.Msg
Prompt string
OnDone func(value string) tea.Msg
OnCancel func() tea.Msg
}