Made table information available to scripts (#49)

- Added a property with table information to session and result set Script types
- Added the ability to add new key bindings to the script
- Rebuilt the foreground job dispatcher to reduce the occurrence of the progress indicator showing up when no job was running.
- Fixed rebinding of keys. Rebinding a key will no longer clear other keys for the old or new bindings.
This commit is contained in:
Leon Mika 2023-02-22 21:53:05 +11:00 • committed by GitHub
parent 733e59ec95
commit 3f1aec2c87
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 710 additions and 115 deletions

View file

@ -4,10 +4,12 @@ import (
"context"
"github.com/cloudcmds/tamarin/exec"
"github.com/cloudcmds/tamarin/scope"
"github.com/lmika/audax/internal/dynamo-browse/services/keybindings"
"github.com/pkg/errors"
"io/fs"
"os"
"path/filepath"
"strings"
)
type Service struct {
@ -119,7 +121,7 @@ func (s *Service) loadScript(ctx context.Context, filename string, resChan chan
}
newPlugin := &ScriptPlugin{
name: filepath.Base(filename),
name: strings.TrimSuffix(filepath.Base(filename), filepath.Ext(filename)),
scriptService: s,
}
@ -176,6 +178,49 @@ func (s *Service) LookupCommand(name string) *Command {
return nil
}
func (s *Service) LookupKeyBinding(key string) (string, *Command) {
for _, p := range s.plugins {
if bindingName, hasBinding := p.keyToKeyBinding[key]; hasBinding {
if cmd, hasCmd := p.definedKeyBindings[bindingName]; hasCmd {
return bindingName, cmd
}
}
}
return "", nil
}
func (s *Service) UnbindKey(key string) {
for _, p := range s.plugins {
if _, hasBinding := p.keyToKeyBinding[key]; hasBinding {
delete(p.keyToKeyBinding, key)
}
}
}
func (s *Service) RebindKeyBinding(keyBinding string, newKey string) error {
if newKey == "" {
for _, p := range s.plugins {
for k, b := range p.keyToKeyBinding {
if b == keyBinding {
delete(p.keyToKeyBinding, k)
}
}
}
return nil
}
for _, p := range s.plugins {
if _, hasCmd := p.definedKeyBindings[keyBinding]; hasCmd {
if newKey != "" {
p.keyToKeyBinding[newKey] = keyBinding
}
return nil
}
}
return keybindings.InvalidBindingError(keyBinding)
}
func (s *Service) parentScope() *scope.Scope {
scp := scope.New(scope.Opts{})
(&uiModule{uiService: s.ifaces.UI}).register(scp)