package runner include RunnerForm.feather include RunnerBehaviour.feather class Runner : SimpleComponent() { class var maxHistory = 20 // ==== Register ==== override meth register() { registerRunnerPrefix( "help", "List Runner Prefixes (this list)", ::listPrefixesAction ) addFeatures( Context.NONE ).apply { val openRunner = Action( "Runner", ::openRunnerAction ) .icon("runner") menus( MenuFeature( "Tools", openRunner ) ) } } // ==== Actions ==== func openRunnerAction() { openBehaviour( RunnerBehaviour() ) } // ==== API ==== func runnerInput( folder : File ) : Feature { return StringFeature( ::runInFolder.curry(folder) ) .description( "Run a command" ) } func run( command : String ) { if (! invokeRunnerPrefix( command ) ) { openBehaviour( RunnerBehaviour( RunnerForm().apply { commandString.value = command } ) ) } } func runInFolder( inFolder : File, command : String ) { if (! invokeRunnerPrefix( command ) ) { val form = RunnerForm().apply { commandString.value = command folder.value = inFolder } RunnerBehaviour( form ).openBehaviour() } } func listPrefixesAction( remainder : String ) : Boolean { if (remainder != "") return false val tb = TextBehaviour("Prefixes").apply { append( "Prefix Description\n" ) append( "-".repeat(70) ) append( "\n" ) for ( registered in listRunnerPrefixes() ) { val prefix = registered.prefix val pad = if (prefix.size() > 15) 0 else 15 - prefix.size() val spaces = " ".repeat(pad) append( "$prefix $spaces${registered.description}\n" ) } }.openBehaviour() return true } }