Skip to content

Commit

Permalink
KtLint format
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredrummler committed Jun 27, 2021
1 parent c319100 commit 8ff0137
Show file tree
Hide file tree
Showing 14 changed files with 207 additions and 135 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
2 changes: 1 addition & 1 deletion demo/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ dependencies {
implementation(Dependencies.BlackSquircle.editor)
implementation(Dependencies.BlackSquircle.shell)
testImplementation(Dependencies.Testing.junit)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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].
*/
Expand Down Expand Up @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ package com.jaredrummler.ktsh.demo

import com.jaredrummler.ktsh.demo.terminal.Terminal

interface TerminalEmulatorView : Terminal.CommandExecutor
interface TerminalEmulatorView : Terminal.CommandExecutor
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -68,4 +77,4 @@ internal class CommandOutputTextView @JvmOverloads constructor(
if (condition()) append(str)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -72,4 +82,4 @@ internal class PromptStatementOne @JvmOverloads constructor(
companion object {
private const val CMD_PWD = "echo \${PWD:-?}"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -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 {
Expand All @@ -129,4 +135,3 @@ internal class PromptStatementTwo @JvmOverloads constructor(
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand Down Expand Up @@ -92,7 +95,6 @@ enum class ShellConstruct(
-1
}
}

}
}
}
Loading

0 comments on commit 8ff0137

Please sign in to comment.