Skip to content

Commit

Permalink
use jline3 line reader
Browse files Browse the repository at this point in the history
  • Loading branch information
Natalia Menshikova committed Jan 17, 2017
1 parent 2ee37cc commit 5180c3f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
20 changes: 12 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@
<java.version>1.8</java.version>
<scala.binary.version>2.10</scala.binary.version>
<scala.version>2.10.6</scala.version>
<spring-shell.version>1.2.0.RELEASE</spring-shell.version>
<log4j.version>1.2.17</log4j.version>
<slf4j.version>1.7.21</slf4j.version>
<spring-boot.version>1.4.2.RELEASE</spring-boot.version>
<org.jline3.version>3.1.2</org.jline3.version>
<scopt.version>3.5.0</scopt.version>

<kafka.version>0.9.0.1</kafka.version>
<!-- the last compatible version for kafka 9-->
<spring-kafka.version>1.0.3.RELEASE</spring-kafka.version>

<log4j.version>1.2.17</log4j.version>
<slf4j.version>1.7.21</slf4j.version>
</properties>


Expand All @@ -31,17 +32,20 @@
<artifactId>scala-library</artifactId>
<version>${scala.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.shell</groupId>
<artifactId>spring-shell</artifactId>
<version>${spring-shell.version}</version>
</dependency>

<!-- command line -->
<dependency>
<groupId>com.github.scopt</groupId>
<artifactId>scopt_${scala.binary.version}</artifactId>
<version>${scopt.version}</version>
</dependency>

<dependency>
<groupId>org.jline</groupId>
<artifactId>jline</artifactId>
<version>${org.jline3.version}</version>
</dependency>

<!-- kafka -->
<dependency>
<groupId>org.apache.kafka</groupId>
Expand Down
18 changes: 14 additions & 4 deletions src/main/scala/org/kafka/cli/KafkaCli.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.kafka.cli

import org.jline.reader.LineReaderBuilder
import org.jline.terminal.TerminalBuilder

/**
* @author Natalia Gorchakova
* @since 03.01.2017
Expand All @@ -8,11 +11,20 @@ object KafkaCli {


def main(args: Array[String]): Unit = {
val terminal = TerminalBuilder.builder()
.name("kafka-cli")
.system(true)
.build()

val lineReader = LineReaderBuilder.builder()
.terminal(terminal)
.build()


var continue = true

while (continue) {
prepareLine()
val line = readLine()
val line = lineReader.readLine("kafka-cli> ")
continue = line != null && line != "exit"

if (continue) {
Expand All @@ -28,6 +40,4 @@ object KafkaCli {
}
}

def prepareLine() = print("kafka-cli> ")

}

0 comments on commit 5180c3f

Please sign in to comment.