From 8ff0137c0d9582c7654473f8c2a72634ac9036dd Mon Sep 17 00:00:00 2001 From: jaredrummler Date: Sat, 26 Jun 2021 23:17:59 -0700 Subject: [PATCH] KtLint format --- build.gradle.kts | 2 +- demo/build.gradle.kts | 2 +- .../ktsh/demo/TerminalEmulatorActivity.kt | 9 ++- .../ktsh/demo/TerminalEmulatorView.kt | 2 +- .../demo/terminal/CommandOutputTextView.kt | 19 +++-- .../ktsh/demo/terminal/PromptStatement.kt | 6 +- .../ktsh/demo/terminal/PromptStatementOne.kt | 68 ++++++++++------- .../ktsh/demo/terminal/PromptStatementTwo.kt | 71 ++++++++++-------- .../ktsh/demo/terminal/ShellConstruct.kt | 6 +- .../ktsh/demo/terminal/Terminal.kt | 75 +++++++++++-------- .../jaredrummler/ktsh/demo/terminal/utils.kt | 5 +- .../ktsh/demo/terminal/ShellFormatterTest.kt | 8 +- .../kotlin/com/jaredrummler/ktsh/Shell.kt | 52 +++++++++---- .../kotlin/com/jaredrummler/ktsh/ShellTest.kt | 17 +++-- 14 files changed, 207 insertions(+), 135 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 0ea7bff..4c80193 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -53,4 +53,4 @@ tasks.register("clean", Delete::class) { } apply(plugin = Plugins.NexusPublish.id) -apply(from = "${rootDir}/scripts/publish-root.gradle") +apply(from = "$rootDir/scripts/publish-root.gradle") diff --git a/demo/build.gradle.kts b/demo/build.gradle.kts index 73e0115..6ce6210 100644 --- a/demo/build.gradle.kts +++ b/demo/build.gradle.kts @@ -55,4 +55,4 @@ dependencies { implementation(Dependencies.BlackSquircle.editor) implementation(Dependencies.BlackSquircle.shell) testImplementation(Dependencies.Testing.junit) -} \ No newline at end of file +} diff --git a/demo/src/main/kotlin/com/jaredrummler/ktsh/demo/TerminalEmulatorActivity.kt b/demo/src/main/kotlin/com/jaredrummler/ktsh/demo/TerminalEmulatorActivity.kt index eccf7c5..926b667 100644 --- a/demo/src/main/kotlin/com/jaredrummler/ktsh/demo/TerminalEmulatorActivity.kt +++ b/demo/src/main/kotlin/com/jaredrummler/ktsh/demo/TerminalEmulatorActivity.kt @@ -28,7 +28,6 @@ import androidx.lifecycle.ViewModelProvider import com.jaredrummler.ktsh.Shell import com.jaredrummler.ktsh.demo.terminal.Terminal - /** * A simple terminal emulator demo using [Shell.SH]. */ @@ -90,8 +89,12 @@ class TerminalEmulatorActivity : AppCompatActivity(), TerminalEmulatorView { } override fun onKeyUp(keyCode: Int, event: KeyEvent?): Boolean = when (keyCode) { - KeyEvent.KEYCODE_DPAD_UP, KeyEvent.KEYCODE_PAGE_UP -> terminal.navigate(Terminal.History.Direction.UP) - KeyEvent.KEYCODE_DPAD_DOWN, KeyEvent.KEYCODE_PAGE_DOWN -> terminal.navigate(Terminal.History.Direction.DOWN) + KeyEvent.KEYCODE_DPAD_UP, KeyEvent.KEYCODE_PAGE_UP -> terminal.navigate( + Terminal.History.Direction.UP + ) + KeyEvent.KEYCODE_DPAD_DOWN, KeyEvent.KEYCODE_PAGE_DOWN -> terminal.navigate( + Terminal.History.Direction.DOWN + ) else -> super.onKeyUp(keyCode, event) } diff --git a/demo/src/main/kotlin/com/jaredrummler/ktsh/demo/TerminalEmulatorView.kt b/demo/src/main/kotlin/com/jaredrummler/ktsh/demo/TerminalEmulatorView.kt index 3fecc57..88d80b0 100644 --- a/demo/src/main/kotlin/com/jaredrummler/ktsh/demo/TerminalEmulatorView.kt +++ b/demo/src/main/kotlin/com/jaredrummler/ktsh/demo/TerminalEmulatorView.kt @@ -18,4 +18,4 @@ package com.jaredrummler.ktsh.demo import com.jaredrummler.ktsh.demo.terminal.Terminal -interface TerminalEmulatorView : Terminal.CommandExecutor \ No newline at end of file +interface TerminalEmulatorView : Terminal.CommandExecutor diff --git a/demo/src/main/kotlin/com/jaredrummler/ktsh/demo/terminal/CommandOutputTextView.kt b/demo/src/main/kotlin/com/jaredrummler/ktsh/demo/terminal/CommandOutputTextView.kt index ead0d36..5db93b7 100644 --- a/demo/src/main/kotlin/com/jaredrummler/ktsh/demo/terminal/CommandOutputTextView.kt +++ b/demo/src/main/kotlin/com/jaredrummler/ktsh/demo/terminal/CommandOutputTextView.kt @@ -30,7 +30,9 @@ import com.blacksquircle.ui.editorkit.model.ColorScheme import kotlin.math.roundToInt internal class CommandOutputTextView @JvmOverloads constructor( - context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 + context: Context, + attrs: AttributeSet? = null, + defStyleAttr: Int = 0 ) : AppCompatTextView(context, attrs, defStyleAttr) { @get:ColorInt @@ -56,9 +58,16 @@ internal class CommandOutputTextView @JvmOverloads constructor( fun appendStdErr(line: String) { append("\n") { !text.isNullOrEmpty() } - append(SpannableString(line).apply { - setSpan(ForegroundColorSpan(stdErrTextColor), 0, line.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE) - }) + append( + SpannableString(line).apply { + setSpan( + ForegroundColorSpan(stdErrTextColor), + 0, + line.length, + Spannable.SPAN_EXCLUSIVE_EXCLUSIVE + ) + } + ) } private val Int.dp: Int get() = (this * context.resources.displayMetrics.density).roundToInt() @@ -68,4 +77,4 @@ internal class CommandOutputTextView @JvmOverloads constructor( if (condition()) append(str) } } -} \ No newline at end of file +} diff --git a/demo/src/main/kotlin/com/jaredrummler/ktsh/demo/terminal/PromptStatement.kt b/demo/src/main/kotlin/com/jaredrummler/ktsh/demo/terminal/PromptStatement.kt index 79b9a62..6f74fcd 100644 --- a/demo/src/main/kotlin/com/jaredrummler/ktsh/demo/terminal/PromptStatement.kt +++ b/demo/src/main/kotlin/com/jaredrummler/ktsh/demo/terminal/PromptStatement.kt @@ -23,7 +23,9 @@ import com.blacksquircle.ui.editorkit.model.ColorScheme import com.jaredrummler.ktsh.Shell internal abstract class PromptStatement @JvmOverloads constructor( - context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 + context: Context, + attrs: AttributeSet? = null, + defStyleAttr: Int = 0 ) : LinearLayout(context, attrs, defStyleAttr) { init { @@ -35,4 +37,4 @@ internal abstract class PromptStatement @JvmOverloads constructor( abstract fun init(shell: Shell, scheme: ColorScheme): PromptStatement protected val Int.dp: Int get() = (this * context.resources.displayMetrics.density).toInt() -} \ No newline at end of file +} diff --git a/demo/src/main/kotlin/com/jaredrummler/ktsh/demo/terminal/PromptStatementOne.kt b/demo/src/main/kotlin/com/jaredrummler/ktsh/demo/terminal/PromptStatementOne.kt index 9ceef40..1eaf5df 100644 --- a/demo/src/main/kotlin/com/jaredrummler/ktsh/demo/terminal/PromptStatementOne.kt +++ b/demo/src/main/kotlin/com/jaredrummler/ktsh/demo/terminal/PromptStatementOne.kt @@ -31,37 +31,47 @@ import com.jaredrummler.ktsh.Shell.Command.Config.Companion.silent import com.jaredrummler.ktsh.demo.R internal class PromptStatementOne @JvmOverloads constructor( - context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 + context: Context, + attrs: AttributeSet? = null, + defStyleAttr: Int = 0 ) : PromptStatement(context, attrs, defStyleAttr) { override fun init(shell: Shell, scheme: ColorScheme): PromptStatementOne = apply { - addView(ImageView(context).apply { - super.setBackgroundColor(scheme.backgroundColor) - this.layoutParams = createFillHeightParams() - this.setPadding(6.dp, 2.dp, 6.dp, 2.dp) - this.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_android_green_16dp)) - }) - addView(TextView(context).apply { - super.setBackgroundColor(scheme.backgroundColor) - this.layoutParams = createFillHeightParams() - this.typeface = Typeface.MONOSPACE - this.text = Build.DEVICE - }) - addView(ImageView(context).apply { - super.setBackgroundColor(scheme.backgroundColor) - this.layoutParams = createFillHeightParams() - this.setPadding(6.dp, 2.dp, 6.dp, 2.dp) - this.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_folder_white_16dp)) - }) - addView(TextView(context).apply { - super.setBackgroundColor(scheme.backgroundColor) - this.layoutParams = createWrapParams() - this.typeface = Typeface.MONOSPACE - this.ellipsize = TextUtils.TruncateAt.MIDDLE - this.isSingleLine = true - this.maxLines = 1 - this.text = shell.run(CMD_PWD, silent()).stdout() - }) + addView( + ImageView(context).apply { + super.setBackgroundColor(scheme.backgroundColor) + this.layoutParams = createFillHeightParams() + this.setPadding(6.dp, 2.dp, 6.dp, 2.dp) + this.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_android_green_16dp)) + } + ) + addView( + TextView(context).apply { + super.setBackgroundColor(scheme.backgroundColor) + this.layoutParams = createFillHeightParams() + this.typeface = Typeface.MONOSPACE + this.text = Build.DEVICE + } + ) + addView( + ImageView(context).apply { + super.setBackgroundColor(scheme.backgroundColor) + this.layoutParams = createFillHeightParams() + this.setPadding(6.dp, 2.dp, 6.dp, 2.dp) + this.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_folder_white_16dp)) + } + ) + addView( + TextView(context).apply { + super.setBackgroundColor(scheme.backgroundColor) + this.layoutParams = createWrapParams() + this.typeface = Typeface.MONOSPACE + this.ellipsize = TextUtils.TruncateAt.MIDDLE + this.isSingleLine = true + this.maxLines = 1 + this.text = shell.run(CMD_PWD, silent()).stdout() + } + ) } override fun setBackgroundColor(color: Int) { @@ -72,4 +82,4 @@ internal class PromptStatementOne @JvmOverloads constructor( companion object { private const val CMD_PWD = "echo \${PWD:-?}" } -} \ No newline at end of file +} diff --git a/demo/src/main/kotlin/com/jaredrummler/ktsh/demo/terminal/PromptStatementTwo.kt b/demo/src/main/kotlin/com/jaredrummler/ktsh/demo/terminal/PromptStatementTwo.kt index 13e633f..f0c22ca 100644 --- a/demo/src/main/kotlin/com/jaredrummler/ktsh/demo/terminal/PromptStatementTwo.kt +++ b/demo/src/main/kotlin/com/jaredrummler/ktsh/demo/terminal/PromptStatementTwo.kt @@ -33,7 +33,9 @@ import com.blacksquircle.ui.language.shell.ShellLanguage import com.jaredrummler.ktsh.Shell internal class PromptStatementTwo @JvmOverloads constructor( - context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 + context: Context, + attrs: AttributeSet? = null, + defStyleAttr: Int = 0 ) : PromptStatement(context, attrs, defStyleAttr) { lateinit var editor: TextProcessor @@ -56,36 +58,40 @@ internal class PromptStatementTwo @JvmOverloads constructor( } override fun init(shell: Shell, scheme: ColorScheme): PromptStatementTwo = apply { - addView(TextView(context).apply { - super.setBackgroundColor(scheme.backgroundColor) - this.setPadding(6.dp, 3.dp, 6.dp, 3.dp) - this.minWidth = 28.dp - this.layoutParams = createFillHeightParams() - this.gravity = Gravity.CENTER - this.text = ">" - this.setTextColor(Color.GREEN) - }) - addView(TextProcessor(context).apply { - super.setBackgroundColor(scheme.backgroundColor) - this.setPadding(16.dp, 5.dp, 16.dp, 5.dp) - this.layoutParams = createFillParams() - this.language = ShellLanguage() - this.gravity = Gravity.CENTER xor Gravity.START - this.isCursorVisible = true - this.editorConfig = EditorConfig( - fontType = Typeface.MONOSPACE, - codeCompletion = true, - lineNumbers = false, - highlightCurrentLine = false, - highlightDelimiters = false - ) - onNewLineListener { command -> - callback.onEnter(command) + addView( + TextView(context).apply { + super.setBackgroundColor(scheme.backgroundColor) + this.setPadding(6.dp, 3.dp, 6.dp, 3.dp) + this.minWidth = 28.dp + this.layoutParams = createFillHeightParams() + this.gravity = Gravity.CENTER + this.text = ">" + this.setTextColor(Color.GREEN) } - doOnNextLayout { view -> - view.requestFocus() - } - }.also { editor = it }) + ) + addView( + TextProcessor(context).apply { + super.setBackgroundColor(scheme.backgroundColor) + this.setPadding(16.dp, 5.dp, 16.dp, 5.dp) + this.layoutParams = createFillParams() + this.language = ShellLanguage() + this.gravity = Gravity.CENTER xor Gravity.START + this.isCursorVisible = true + this.editorConfig = EditorConfig( + fontType = Typeface.MONOSPACE, + codeCompletion = true, + lineNumbers = false, + highlightCurrentLine = false, + highlightDelimiters = false + ) + onNewLineListener { command -> + callback.onEnter(command) + } + doOnNextLayout { view -> + view.requestFocus() + } + }.also { editor = it } + ) } override fun setBackgroundColor(color: Int) { @@ -108,8 +114,8 @@ internal class PromptStatementTwo @JvmOverloads constructor( } override fun requestFocus(direction: Int, previouslyFocusedRect: Rect?): Boolean { - return editor.requestFocus(direction, previouslyFocusedRect) - || super.requestFocus(direction, previouslyFocusedRect) + return editor.requestFocus(direction, previouslyFocusedRect) || + super.requestFocus(direction, previouslyFocusedRect) } interface OnEnterCallback { @@ -129,4 +135,3 @@ internal class PromptStatementTwo @JvmOverloads constructor( } } } - diff --git a/demo/src/main/kotlin/com/jaredrummler/ktsh/demo/terminal/ShellConstruct.kt b/demo/src/main/kotlin/com/jaredrummler/ktsh/demo/terminal/ShellConstruct.kt index 2911776..9ed5e98 100644 --- a/demo/src/main/kotlin/com/jaredrummler/ktsh/demo/terminal/ShellConstruct.kt +++ b/demo/src/main/kotlin/com/jaredrummler/ktsh/demo/terminal/ShellConstruct.kt @@ -63,7 +63,10 @@ enum class ShellConstruct( else -> { val index = statement.indexOf(shellConstruct.end) if (index == -1) return@forEachRemaining - statement = statement.removeRange(index, index + shellConstruct.close.length) + statement = statement.removeRange( + index, + index + shellConstruct.close.length + ) iterator.remove() } } @@ -92,7 +95,6 @@ enum class ShellConstruct( -1 } } - } } } diff --git a/demo/src/main/kotlin/com/jaredrummler/ktsh/demo/terminal/Terminal.kt b/demo/src/main/kotlin/com/jaredrummler/ktsh/demo/terminal/Terminal.kt index 4e851fb..bef8daf 100644 --- a/demo/src/main/kotlin/com/jaredrummler/ktsh/demo/terminal/Terminal.kt +++ b/demo/src/main/kotlin/com/jaredrummler/ktsh/demo/terminal/Terminal.kt @@ -28,9 +28,10 @@ import com.blacksquircle.ui.editorkit.theme.EditorTheme import com.jaredrummler.ktsh.Shell import com.jaredrummler.ktsh.demo.R - class Terminal @JvmOverloads constructor( - context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 + context: Context, + attrs: AttributeSet? = null, + defStyleAttr: Int = 0 ) : ScrollView(context, attrs, defStyleAttr) { private val history = History() @@ -73,25 +74,29 @@ class Terminal @JvmOverloads constructor( this.console = Console(context) this.addView(console) - this.shell.addOnStdoutLineListener(object : Shell.OnLineListener { - override fun onLine(line: String) { - handler.post { - output.visibility = VISIBLE - output.appendStdOut(line) - scrollToBottom() + this.shell.addOnStdoutLineListener( + object : Shell.OnLineListener { + override fun onLine(line: String) { + handler.post { + output.visibility = VISIBLE + output.appendStdOut(line) + scrollToBottom() + } } } - }) - - this.shell.addOnStderrLineListener(object : Shell.OnLineListener { - override fun onLine(line: String) { - handler.post { - output.visibility = VISIBLE - output.appendStdErr(line) - scrollToBottom() + ) + + this.shell.addOnStderrLineListener( + object : Shell.OnLineListener { + override fun onLine(line: String) { + handler.post { + output.visibility = VISIBLE + output.appendStdErr(line) + scrollToBottom() + } } } - }) + ) } /** @@ -144,12 +149,14 @@ class Terminal @JvmOverloads constructor( // Remove PS1 console.removeChildrenOf() // Add the TextView for standard out/err streams. - console.addView(CommandOutputTextView(context).also { view -> - view.init(theme.scheme) - view.visibility = GONE - }.also { view -> - output = view - }) + console.addView( + CommandOutputTextView(context).also { view -> + view.init(theme.scheme) + view.visibility = GONE + }.also { view -> + output = view + } + ) // Add the new PS2 view and disable all others. addPromptStatementTwo() // Set focus to the bottom of the Terminal @@ -157,20 +164,22 @@ class Terminal @JvmOverloads constructor( } private fun addPromptStatementTwo() { - console.addView(ps2().also { prompt -> - command?.let { command -> - prompt.constructs = ShellConstruct.constructs(command) - } - prompt.doOnNextLayout { - (0 until console.childCount - 1).onEach { index -> - when (val child = console.getChildAt(index)) { - is PromptStatementTwo -> { - child.isEnabled = false + console.addView( + ps2().also { prompt -> + command?.let { command -> + prompt.constructs = ShellConstruct.constructs(command) + } + prompt.doOnNextLayout { + (0 until console.childCount - 1).onEach { index -> + when (val child = console.getChildAt(index)) { + is PromptStatementTwo -> { + child.isEnabled = false + } } } } } - }) + ) scrollToBottom() } diff --git a/demo/src/main/kotlin/com/jaredrummler/ktsh/demo/terminal/utils.kt b/demo/src/main/kotlin/com/jaredrummler/ktsh/demo/terminal/utils.kt index e9667db..c755a27 100644 --- a/demo/src/main/kotlin/com/jaredrummler/ktsh/demo/terminal/utils.kt +++ b/demo/src/main/kotlin/com/jaredrummler/ktsh/demo/terminal/utils.kt @@ -37,7 +37,10 @@ internal inline fun createFillHeightParams( createParams(WRAP_CONTENT, MATCH_PARENT) internal inline fun createParams(width: Int, height: Int): T = - T::class.java.getDeclaredConstructor(Int::class.java, Int::class.java).newInstance(width, height) + T::class.java.getDeclaredConstructor(Int::class.java, Int::class.java).newInstance( + width, + height + ) internal val View.activity: Activity get() = context as Activity diff --git a/demo/src/test/kotlin/com/jaredrummler/ktsh/demo/terminal/ShellFormatterTest.kt b/demo/src/test/kotlin/com/jaredrummler/ktsh/demo/terminal/ShellFormatterTest.kt index 1d947a8..5bdbe6d 100644 --- a/demo/src/test/kotlin/com/jaredrummler/ktsh/demo/terminal/ShellFormatterTest.kt +++ b/demo/src/test/kotlin/com/jaredrummler/ktsh/demo/terminal/ShellFormatterTest.kt @@ -34,7 +34,8 @@ class ShellFormatterTest { } companion object { - private const val TEST_CODE_UNFORMATTED = """ + private const val TEST_CODE_UNFORMATTED = + """ for i in `seq 1 100`; do if [ ${'$'}i%15 -eq 15 ]; then echo "FizzBuzz" @@ -48,7 +49,8 @@ fi done """ - private const val TEST_CODE_FORMATTED_WITH_SPACES = """ + private const val TEST_CODE_FORMATTED_WITH_SPACES = + """ for i in `seq 1 100`; do if [ ${'$'}i%15 -eq 15 ]; then echo "FizzBuzz" @@ -65,4 +67,4 @@ done private val TEST_CODE_FORMATTED_WITH_TABS = TEST_CODE_FORMATTED_WITH_SPACES.replace(" ", "\t") } -} \ No newline at end of file +} diff --git a/library/src/main/kotlin/com/jaredrummler/ktsh/Shell.kt b/library/src/main/kotlin/com/jaredrummler/ktsh/Shell.kt index 0c9fdab..d62421b 100644 --- a/library/src/main/kotlin/com/jaredrummler/ktsh/Shell.kt +++ b/library/src/main/kotlin/com/jaredrummler/ktsh/Shell.kt @@ -50,7 +50,8 @@ typealias EnvironmentMap = Map * @since 05-05-2021 */ class Shell @Throws(NotFoundException::class) @JvmOverloads constructor( - val path: String, val environment: EnvironmentMap = emptyMap() + val path: String, + val environment: EnvironmentMap = emptyMap() ) { /** @@ -61,7 +62,7 @@ class Shell @Throws(NotFoundException::class) @JvmOverloads constructor( * with the system environment. */ constructor(shell: String, vararg environment: Pair) : - this(shell, environment.toEnvironmentMap()) + this(shell, environment.toEnvironmentMap()) /** * Construct a new [Shell] with optional environment variable arguments as an array. @@ -71,7 +72,7 @@ class Shell @Throws(NotFoundException::class) @JvmOverloads constructor( * with the system environment. */ constructor(shell: String, environment: Array) : - this(shell, environment.toEnvironmentMap()) + this(shell, environment.toEnvironmentMap()) private val onResultListeners = mutableSetOf() private val onStdOutListeners = mutableSetOf() @@ -201,13 +202,14 @@ class Shell @Throws(NotFoundException::class) @JvmOverloads constructor( val onComplete = { marker: Command.Marker -> when (marker.uuid) { - uuid -> try { // Reached the end of reading the stream for the command. - if (marker.status != Command.Status.INVALID) { - exitCode = marker.status + uuid -> + try { // Reached the end of reading the stream for the command. + if (marker.status != Command.Status.INVALID) { + exitCode = marker.status + } + } finally { + watchdog.signal() } - } finally { - watchdog.signal() - } } } @@ -266,7 +268,15 @@ class Shell @Throws(NotFoundException::class) @JvmOverloads constructor( } // Create the result from running the command. - val result = Command.Result.create(uuid, command, stdout, stderr, output, exitCode, startTime) + val result = Command.Result.create( + uuid, + command, + stdout, + stderr, + output, + exitCode, + startTime + ) if (config.notify) { onResultListeners.forEach { listener -> @@ -429,7 +439,13 @@ class Shell @Throws(NotFoundException::class) @JvmOverloads constructor( exitCode: Int, startTime: Long, endTime: Long = System.currentTimeMillis(), - ) = Result(stdout, stderr, output, exitCode, Details(uuid, command, startTime, endTime)) + ) = Result( + stdout, + stderr, + output, + exitCode, + Details(uuid, command, startTime, endTime) + ) } } @@ -484,7 +500,16 @@ class Shell @Throws(NotFoundException::class) @JvmOverloads constructor( * @return A new [Config] for a command. */ fun create() = - Config(uuid, redirectErrorStream, onStdOut, onStdErr, onCancelled, onTimeout, timeout, notify) + Config( + uuid, + redirectErrorStream, + onStdOut, + onStdErr, + onCancelled, + onTimeout, + timeout, + notify + ) } companion object { @@ -671,7 +696,8 @@ class Shell @Throws(NotFoundException::class) @JvmOverloads constructor( * @param stream Either the [Process.getInputStream] or [Process.getErrorStream] */ private class StreamReader private constructor( - name: String, private val stream: InputStream + name: String, + private val stream: InputStream ) : Thread(name) { /** diff --git a/library/src/test/kotlin/com/jaredrummler/ktsh/ShellTest.kt b/library/src/test/kotlin/com/jaredrummler/ktsh/ShellTest.kt index 3e190a7..ae2e64d 100644 --- a/library/src/test/kotlin/com/jaredrummler/ktsh/ShellTest.kt +++ b/library/src/test/kotlin/com/jaredrummler/ktsh/ShellTest.kt @@ -51,7 +51,7 @@ class ShellTest { do echo ${'$'}i done - """.trimIndent() + """.trimIndent() ) Assert.assertEquals(listOf("1", "2", "3"), result.stdout) } @@ -59,12 +59,14 @@ class ShellTest { @Test fun `should add command result listener`() { var gotResult = false - Shell.SH.addOnCommandResultListener(object : Shell.OnCommandResultListener { - override fun onResult(result: Shell.Command.Result) { - Shell.SH.removeOnCommandResultListener(this) - gotResult = true + Shell.SH.addOnCommandResultListener( + object : Shell.OnCommandResultListener { + override fun onResult(result: Shell.Command.Result) { + Shell.SH.removeOnCommandResultListener(this) + gotResult = true + } } - }) + ) Shell.SH.run(TEST_COMMAND) Assert.assertTrue(gotResult) } @@ -156,5 +158,4 @@ class ShellTest { private const val ERROR_STATUS = Shell.Command.Status.NOT_FOUND private const val ERROR_STDERR = "command not found" } - -} \ No newline at end of file +}