Skip to content

Commit

Permalink
Acceptable solution to cursor ownership
Browse files Browse the repository at this point in the history
  • Loading branch information
NorseDreki committed Feb 25, 2024
1 parent 28847be commit 72c7462
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 27 deletions.
2 changes: 2 additions & 0 deletions src/nativeMain/kotlin/AppStateHolder.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import dogcat.LogFilter.ByPackage
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import logger.Logger

data class AppStateHolder(

Expand Down Expand Up @@ -55,6 +56,7 @@ class InternalAppState : AppState {
}

override fun holdCursor(hold: Boolean) {
Logger.d("HOLD CURSOR $hold")
state.value = state.value.copy(isCursorHeld = hold)
}

Expand Down
2 changes: 1 addition & 1 deletion src/nativeMain/kotlin/ui/AppPresenter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class AppPresenter(
else -> dogcat(Start.PickAllApps)
}

appState.setInputFilterLocation("Filter: ".length, 49)
appState.setInputFilterLocation(AppConfig.INPUT_FILTER_PREFIX.length, 49)

view.start()

Expand Down
4 changes: 2 additions & 2 deletions src/nativeMain/kotlin/ui/logLines/LogLinesPresenter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ class LogLinesPresenter(

scope.launch {
appState.state
.map { it.isCursorHeld }
.collect {
view.state = view.state.copy(
isCursorHeld = it
isCursorHeld = it.isCursorHeld,
cursorReturnLocation = it.inputFilterLocation
)
}
}
Expand Down
22 changes: 7 additions & 15 deletions src/nativeMain/kotlin/ui/logLines/LogLinesView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,9 @@ class LogLinesView {
val autoscroll: Boolean = false,
val isCursorHeld: Boolean = false,
val cursorReturnLocation: Pair<Int, Int>? = null,

//val holdRequest: ((x: Int, y: Int) -> Unit)? = null
)

var state: State by Delegates.observable(State()) { p, o, n ->
}

//var isCursorHeld: Boolean = false
var state = State()

private val sx = getmaxx(stdscr)
private val sy = getmaxy(stdscr)
Expand All @@ -34,8 +29,6 @@ class LogLinesView {
internal val pageSize = position.endY - position.startY + 1
private val lastPageSize = pageSize - 1

//internal var autoscroll = false

init {
scrollok(pad, true)
}
Expand Down Expand Up @@ -112,7 +105,6 @@ class LogLinesView {
curs_set(0)
firstVisibleLine += second
refresh()
Logger.d("Down, $firstVisibleLine")
}

fun home() {
Expand Down Expand Up @@ -171,22 +163,22 @@ class LogLinesView {
internal fun refresh() {
val notSeeingLastLine = firstVisibleLine <= linesCount - pageSize

if (state.isCursorHeld) {
curs_set(0)
}

prefresh(pad, firstVisibleLine, 0, position.startY, position.startX, position.endY, position.endX)
//call doupdate with pnoutrefresh

when {
state.isCursorHeld -> {
Logger.d("Cursor held")
// wmove(stdscr, state.cursorReturnLocation!!.second, state.cursorReturnLocation!!.first)
wmove(stdscr, state.cursorReturnLocation!!.second, state.cursorReturnLocation!!.first)
curs_set(1)
wrefresh(stdscr)
}

!notSeeingLastLine -> {
/*val x = getcurx(pad)
val y = getpary(pad)
Logger.d("Hold location $x $y")
state.holdRequest!!.invoke(x, y)*/
Logger.d("seeing last line, cursor held? ${state.isCursorHeld}")
curs_set(1)
}

Expand Down
2 changes: 1 addition & 1 deletion src/nativeMain/kotlin/ui/status/StatusPresenter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class StatusPresenter(
.state
.filterIsInstance<Active>()
.flatMapLatest { it.heartbeat }
//.distinctUntilChanged()
.distinctUntilChanged()
.onEach {
view.state = view.state.copy(emulator = "DEVICE", running = it)
}
Expand Down
6 changes: 3 additions & 3 deletions src/nativeMain/kotlin/ui/status/StatusView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,9 @@ class StatusView {
}

private fun updateView(n: State) {
Logger.d("UPDATE VIEW: $n")
//Logger.d("UPDATE VIEW: $n")

updateBackground()
mvwprintw(window, 1, 0, AppConfig.INPUT_FILTER_PREFIX)

updatePackageName(n.packageName)
updateFilters(n.filters)
updateAutoscroll(n.autoscroll)
Expand All @@ -51,6 +49,7 @@ class StatusView {
wrefresh(window)

if (state.isCursorHeld) {
Logger.d("STATUS VIEW -- RETURN CURSOR")
wmove(stdscr, state.cursorReturnLocation!!.second, state.cursorReturnLocation!!.first)
curs_set(1)
wrefresh(stdscr)
Expand Down Expand Up @@ -110,6 +109,7 @@ class StatusView {
curs_set(0)

val cp = if (running) 2 else 1

wattron(window, COLOR_PAIR(cp))
mvwprintw(window, 1, getmaxx(window) - device.length - 1, device)
wattroff(window, COLOR_PAIR(cp))
Expand Down
11 changes: 6 additions & 5 deletions src/nativeMain/kotlin/userInput/Input.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,8 @@ class DefaultInput(
appState.holdCursor(true)
inputMode = true

//mvwaddstr(stdscr, y, 0, "Filter: ")
wmove(stdscr, y , cursorPosition)
waddstr(stdscr, " ".repeat(100))
mvwprintw(stdscr, y, 0, AppConfig.INPUT_FILTER_PREFIX)
waddstr(stdscr, " ".repeat(100)) //max input
//wclrtoeol(stdscr)

//move not needed?
Expand All @@ -74,7 +73,6 @@ class DefaultInput(
continue
}


// limit max input
if (inputMode) {
when (key) {
Expand All @@ -87,7 +85,9 @@ class DefaultInput(
inputBuffer.deleteAt(cursorPosition - x - 1)
cursorPosition--

mvdelch(y, cursorPosition)
//DEVICE on the right is blinking
//mvdelch(y, cursorPosition)
wdelch(stdscr)
}
}

Expand Down Expand Up @@ -118,6 +118,7 @@ class DefaultInput(
}
}
wmove(stdscr, y, cursorPosition)
appState.setInputFilterLocation(cursorPosition, y)

} else {
Logger.d("${context()} Process key $key")
Expand Down

0 comments on commit 72c7462

Please sign in to comment.