本文整理汇总了Scala中scala.tools.jline.console.ConsoleReader类的典型用法代码示例。如果您正苦于以下问题:Scala ConsoleReader类的具体用法?Scala ConsoleReader怎么用?Scala ConsoleReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ConsoleReader类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: CQRRunner
//设置package包名称以及导入依赖的类
package cqr
import scala.tools.jline.console.ConsoleReader
import cqr._
import cqr.Dir._
class CQRRunner(val qr: QRCode) {
def this(version: Int) = this(QRCode.fromVersion(version))
def this() = this(3)
def this(str: String) = this(QRCode.fromString(str))
val frame = new QRFrame(qr)
val reader = new ConsoleReader()
private def step() {
reader.readVirtualKey().toChar match {
case 'h' => frame.move(LEFT)
case 'j' => frame.move(DOWN)
case 'k' => frame.move(UP)
case 'l' => frame.move(RIGHT)
case 'x' | ' ' => frame.invert()
case 'q' => throw new RuntimeException()
case _ =>
}
}
def run(): String = {
frame.redraw()
try while (true) step()
catch {
case e: RuntimeException =>
}
frame.eraseScreen()
frame.qr.toString(black = 'X', white = '_', unknown = '?')
}
}
示例2: ServerApplication
//设置package包名称以及导入依赖的类
package com.mildlyskilled
import com.mildlyskilled.core.{ConsoleAction, Network}
import java.util.logging.Logger
import akka.actor.{ActorSystem, Props}
import com.mildlyskilled.actors.Server
import com.mildlyskilled.protocol.Message._
import com.typesafe.config.ConfigFactory
import scala.tools.jline.console.ConsoleReader
object ServerApplication extends App {
implicit val logger = Logger.getLogger("Server Logger")
logger.info(Console.GREEN_B + "Starting server" + Console.RESET)
val ipSelection = ConsoleAction.promptSelection(Network.addressMap, "Select an IP address", Some("127.0.0.1"))
val serverName = ConsoleAction.clean(ConsoleAction.promptInput("Name this server"))
val serverConfiguration = ConfigFactory.parseString(s"""akka.remote.netty.tcp.hostname="$ipSelection" """)
val defaultConfig = ConfigFactory.load.getConfig("server")
val completeConfig = serverConfiguration.withFallback(defaultConfig)
val system = ActorSystem("sIRC", completeConfig)
val server = system.actorOf(Props[Server], serverName)
val cReader = new ConsoleReader()
Iterator.continually(cReader.readLine("> ")).takeWhile(_ != "/exit").foreach {
case "/start" =>
server ! Start
case "/users" =>
server.tell(RegisteredUsers, server)
case "/channels" =>
server.tell(ListChannels, server)
case "/stop" =>
server ! Stop
case "/shutdown" =>
system.terminate()
case userCommandMessageRegex("add", c) =>
server.tell(RegisterChannel(ConsoleAction.clean(c)), server)
case msg =>
server ! Info(msg)
}
system.terminate()
}
示例3: ClientApplication
//设置package包名称以及导入依赖的类
package com.mildlyskilled
import akka.actor.{ActorSystem, Props}
import com.mildlyskilled.actors.Client
import com.mildlyskilled.core.{ConsoleAction, Network}
import com.mildlyskilled.protocol.Message._
import com.typesafe.config.ConfigFactory
import java.util.logging.Logger
import scala.tools.jline.console.ConsoleReader
object ClientApplication extends App {
implicit val logger = Logger.getLogger("Client Logger")
logger.info(Console.GREEN_B + "Starting client" + Console.RESET)
val username = ConsoleAction.promptInput("Username")
val serverName = ConsoleAction.promptInput("Server Name")
val ipSelection = ConsoleAction.promptSelection(Network.addressMap, "Select an IP address", Some("127.0.0.1"))
val clientConfig = ConfigFactory.parseString(s"""akka.remote.netty.tcp.hostname="$ipSelection" """)
val defaultConfig = ConfigFactory.load.getConfig("client")
val completeConfig = clientConfig.withFallback(defaultConfig)
val system = ActorSystem("sIRC", completeConfig)
val client = system.actorOf(Props[Client], username)
val serverconfig = ConfigFactory.load.getConfig("server")
val serverAddress = ConsoleAction.promptInput(s"Server IP Address or hostname [$ipSelection]", s"$ipSelection")
val serverPort = serverconfig.getString("akka.remote.netty.tcp.port")
val serverPath = s"akka.tcp://[email protected]$serverAddress:$serverPort/user/$serverName"
val server = system.actorSelection(serverPath) // <-- this is where we get the server reference
server.tell(Login("username", "password"), client)
val cReader = new ConsoleReader
Iterator.continually(cReader.readLine("> ")).takeWhile(_ != "/exit").foreach {
case "/start" =>
server ! Start
case "/users" =>
server.tell(RegisteredUsers, client)
case "/channels" =>
server.tell(ListChannels, client)
case "/leave" =>
server.tell(Leave, client)
case msg =>
server ! Info(msg)
case userCommandMessageRegex("join", c) =>
server.tell(JoinChannel(ConsoleAction.clean(c)), client)
}
system.terminate()
}