Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .scalafix.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ OrganizeImports {
removeUnused = false
}
OrganizeImports.targetDialect = Scala3
OrganizeImports.removeUnused = false
OrganizeImports.removeUnused = true
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package cue4s

import scala.concurrent.ExecutionContext
import scala.concurrent.Future

private trait InputProviderCompanionPlatform:
def apply(o: Terminal): InputProvider = InputProviderImpl(o)
end InputProviderCompanionPlatform
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,7 @@ import scala.concurrent.Future
private trait InputProviderPlatform:
self: InputProvider =>

def evaluate[Result](f: Handler[Result]): Completion[Result]
def evaluateFuture[Result](f: Handler[Result])(using
def evaluate[Result](f: EventHandler[Result]): Completion[Result]
def evaluateFuture[Result](f: EventHandler[Result])(using
ExecutionContext,
): Future[Completion[Result]]

private trait InputProviderCompanionPlatform:
def apply(o: Terminal): InputProvider = InputProviderImpl(o)

end InputProviderCompanionPlatform
86 changes: 0 additions & 86 deletions modules/core/src/main/scala/AnsiTerminal.scala
Original file line number Diff line number Diff line change
Expand Up @@ -68,89 +68,3 @@ end AnsiTerminal
object AnsiTerminal:
final val ESC = '\u001b'
final val CSI = s"$ESC["

// inline def call(name: Char, inline args: Int*) =
// s"$CSI${args.mkString(";")}$name"

// inline def m(args: Int*) =
// call('m', args*)

// object cursor:
// inline def show() =
// s"$CSI?25h"

// inline def hide() =
// s"$CSI?25l"

// object screen:
// inline def clear() =
// s"${ESC}c"

// object move:
// inline def up(n: Int) =
// call('A', n)

// inline def down(n: Int) =
// call('B', n)

// inline def forward(n: Int) =
// call('C', n)

// inline def back(n: Int) =
// call('D', n)

// inline def nextLine(n: Int) =
// call('E', n)

// inline def previousLine(n: Int) =
// call('F', n)

// inline def horizontalTo(column: Int) =
// call('G', column)

// inline def position(row: Int, column: Int) =
// call('H', row, column)
// end move

// object erase:
// object line:
// inline def apply(n: Int) =
// call('K', n)

// inline def toEndOfLine() =
// apply(0)

// inline def toBeginningOfLine() =
// apply(1)

// inline def entireLine() =
// apply(2)
// end line

// object display:
// inline def apply(n: Int) =
// call('J', n)

// inline def toEndOfScreen() =
// apply(0)

// inline def toBeinningOfScreen() =
// apply(1)

// inline def entireScreen() =
// apply(2)
// end display
// end erase

// inline def save() =
// call('s')

// inline def restore() =
// call('u')

// inline def withRestore[A](writer: String => Unit)(inline f: => A) =
// writer(save())
// f
// writer(restore())

// end ANSI
6 changes: 3 additions & 3 deletions modules/core/src/main/scala/Event.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package cue4s

private[cue4s] enum Event:
enum Event:
case Init
case Key(which: KeyEvent)
case Char(which: Int)
Expand All @@ -32,9 +32,9 @@ private[cue4s] enum Event:
case Interrupt => "Event.Interrupt"
end Event

private[cue4s] object Event:
object Event:
object Char:
def apply(c: scala.Char): Event.Char = Event.Char(c.toInt)

private[cue4s] enum KeyEvent:
enum KeyEvent:
case UP, DOWN, LEFT, RIGHT, ENTER, DELETE, TAB
4 changes: 4 additions & 0 deletions modules/core/src/main/scala/EventHandler.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package cue4s

abstract class EventHandler[Result]:
def apply(ev: Event): Next[Result]
5 changes: 1 addition & 4 deletions modules/core/src/main/scala/InputProvider.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@

package cue4s

private[cue4s] abstract class Handler[Result]:
def apply(ev: Event): Next[Result]

private[cue4s] abstract class InputProvider(protected val terminal: Terminal)
abstract class InputProvider(protected val terminal: Terminal)
extends AutoCloseable,
InputProviderPlatform

Expand Down
2 changes: 1 addition & 1 deletion modules/core/src/main/scala/Next.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package cue4s

private[cue4s] enum Next[+Result]:
enum Next[+Result]:
case Stop, Continue
case Done(value: Result)
case Error(msg: String)
2 changes: 1 addition & 1 deletion modules/core/src/main/scala/PromptFramework.scala
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private[cue4s] trait PromptFramework[Result](terminal: Terminal, out: Output):

end mapValidated

final val handler = new Handler[Result]:
final val handler = new EventHandler[Result]:
override def apply(ev: Event): Next[Result] =
if ev == Event.Init then printPrompt()
handleEvent(ev) match
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ trait InputProviderPlatform:
self: InputProvider =>

def evaluateFuture[Result](
f: Handler[Result],
f: EventHandler[Result],
)(using ExecutionContext): Future[Completion[Result]]

trait InputProviderCompanionPlatform:
Expand Down
2 changes: 1 addition & 1 deletion modules/core/src/main/scalajs/InputProviderImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ private class InputProviderImpl(o: Terminal)
extends InputProvider(o),
InputProviderPlatform:
override def evaluateFuture[Result](
handler: Handler[Result],
handler: EventHandler[Result],
)(using ExecutionContext): Future[Completion[Result]] =

val stdin = Process.stdin
Expand Down
4 changes: 2 additions & 2 deletions modules/core/src/main/scalajvm/InputProviderImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ private class InputProviderImpl(o: Terminal)

@volatile private var asyncHookSet = false

override def evaluateFuture[Result](handler: Handler[Result])(using
override def evaluateFuture[Result](handler: EventHandler[Result])(using
ExecutionContext,
) =

Expand All @@ -56,7 +56,7 @@ private class InputProviderImpl(o: Terminal)
Future.firstCompletedOf(Seq(cancellation.future, fut))
end evaluateFuture

override def evaluate[Result](handler: Handler[Result]): Completion[Result] =
override def evaluate[Result](handler: EventHandler[Result]): Completion[Result] =
InputProviderImpl.nativeInterop.changemode(1)

var lastRead = 0
Expand Down
10 changes: 4 additions & 6 deletions modules/core/src/main/scalanative/InputProviderImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import scala.concurrent.Future
import scala.util.boundary

import scalanative.libc.stdio.getchar
import scalanative.unsafe.*
import scalanative.posix.termios.*
import boundary.break
import CharCollector.*

Expand All @@ -32,7 +30,7 @@ private class InputProviderImpl(o: Terminal)

@volatile private var asyncHookSet = false

override def evaluateFuture[Result](handler: Handler[Result])(using
override def evaluateFuture[Result](handler: EventHandler[Result])(using
ExecutionContext,
) =
val hook = () =>
Expand All @@ -54,9 +52,9 @@ private class InputProviderImpl(o: Terminal)
fut
end evaluateFuture

private var flags = Option.empty[CLong]

override def evaluate[Result](handler: Handler[Result]): Completion[Result] =
override def evaluate[Result](
handler: EventHandler[Result],
): Completion[Result] =
Changemode.changeMode(rawMode = true)

val hook = () =>
Expand Down
Loading