package processes class ProcessesBehaviour( val form : ProcessesForm ) : TableBehaviour( form.title ), Promptable { val refresh = Action( "Refresh", this:>refresh ) .icon("refresh").shortcut( Key.F5.noMods() ) init { columns = listOf( TableColumn( "UID", 100 ), TableColumn( "PID", 100 ), TableColumn( "Command" ) ) form.every.listen( this:>refresh ) } override meth toolbar() = listOf( form.every, separator, TextFeature("-C"), form.selectByCommand, TextFeature("-u"), form.selectByUser, TextFeature("-g"), form.selectByGroup, refresh ) override meth attached( container : Container ) { super.attached( container ) refresh() } meth refresh() { rows.clear() // TODO Shell Escape val everyFlag = if (form.every.value) "-e" else "" val commandOption = if (form.selectByCommand.value == "" ) "" else "-C ${form.selectByCommand.value}" val userOption = if (form.selectByUser.value == "" ) "" else "-u ${form.selectByUser.value}" val groupOption = if (form.selectByGroup.value == "" ) "" else "-g ${form.selectByGroup.value}" val command = $( ps $commandOption $userOption $groupOption $everyFlag -f ) val lines = command.eval().split("\n") val pattern = Pattern.compile("(\\S*)\\s+(\\S*)\\s+(\\S*)\\s+(\\S*)\\s+(\\S*)\\s+(\\S*)\\s+(\\S*)\\s+(.*)") var first = true for (line in lines) { if (first) { first = false continue } pattern.matcher( line ).apply { if (find()) { val row = ProcessData( group(1), group(2), group(8) ) rows.add(row) } } } } override meth promptForm() = form }