Skip to content

Commit 08895a4

Browse files
committed
Customizing banner text and prompt
1 parent 4900f6c commit 08895a4

File tree

4 files changed

+41
-17
lines changed

4 files changed

+41
-17
lines changed

build.sbt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import sbt._
2+
import NativePackagerHelper._
3+
import java.io.File
24

35
maintainer := "Mandar Chandorkar <[email protected]>"
46

@@ -9,6 +11,8 @@ packageDescription := "DynaML is a scala library/repl for implementing and worki
911
"which can be extended easily to implement advanced models for small and large scale applications.\n\n"+
1012
"But the library can also be used as an educational/research tool for data analysis."
1113

14+
val dataDirectory = settingKey[File]("The directory holding the data files for running example scripts")
15+
1216
lazy val commonSettings = Seq(
1317
name := "DynaML",
1418
organization := "io.github.mandar2812",
@@ -40,7 +44,9 @@ lazy val commonSettings = Seq(
4044
"org.jzy3d" % "jzy3d-api" % "0.9.1" % "compile",
4145
"com.lihaoyi" % "ammonite-repl_2.11.7" % "0.5.8"
4246
),
43-
initialCommands in console := """io.github.mandar2812.dynaml.DynaML.run();"""
47+
dataDirectory := new File("data/"),
48+
initialCommands in console := """io.github.mandar2812.dynaml.DynaML.run(banner="""" +
49+
target.value.getPath + """/universal/stage/conf/banner.txt");"""
4450
)
4551

4652
lazy val DynaML = (project in file(".")).enablePlugins(JavaAppPackaging, BuildInfoPlugin)
@@ -49,12 +55,15 @@ lazy val DynaML = (project in file(".")).enablePlugins(JavaAppPackaging, BuildIn
4955
buildInfoKeys := Seq[BuildInfoKey](name, version, scalaVersion, sbtVersion),
5056
buildInfoPackage := "io.github.mandar2812.dynaml.repl",
5157
buildInfoUsePackageAsPath := true,
52-
mappings in Universal += {
58+
mappings in Universal ++= Seq({
5359
// we are using the reference.conf as default application.conf
5460
// the user can override settings here
5561
val init = (resourceDirectory in Compile).value / "DynaMLInit.scala"
5662
init -> "conf/DynaMLInit.scala"
57-
},
63+
}, {
64+
val banner = (resourceDirectory in Compile).value / "dynamlBanner.txt"
65+
banner -> "conf/banner.txt"
66+
}),
5867
javaOptions in Universal ++= Seq(
5968
// -J params will be added as jvm parameters
6069
"-J-Xmx2048m",
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
___ ___ ___ ___ ___ ___
2+
/\ \ |\__\ /\__\ /\ \ /\__\ /\__\
3+
/::\ \ |:| | /::| | /::\ \ /::| | /:/ /
4+
/:/\:\ \ |:| | /:|:| | /:/\:\ \ /:|:| | /:/ /
5+
/:/ \:\__\ |:|__|__ /:/|:| |__ /::\~\:\ \ /:/|:|__|__ /:/ /
6+
/:/__/ \:|__| /::::\__\ /:/ |:| /\__\ /:/\:\ \:\__\ /:/ |::::\__\ /:/__/
7+
\:\ \ /:/ / /:/~~/~ \/__|:|/:/ / \/__\:\/:/ / \/__/~~/:/ / \:\ \
8+
\:\ /:/ / /:/ / |:/:/ / \::/ / /:/ / \:\ \
9+
\:\/:/ / \/__/ |::/ / /:/ / /:/ / \:\ \
10+
\::/__/ /:/ / /:/ / /:/ / \:\__\
11+
~~ \/__/ \/__/ \/__/ \/__/

src/main/scala/io/github/mandar2812/dynaml/DynaML.scala

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,12 @@ object DynaML {
129129

130130
val storage = Storage(defaultAmmoniteHome, None)
131131
val repl = new DynaMLRepl(
132-
System.in, System.out, System.err,
132+
input = System.in, output = System.out, error = System.err,
133133
storage = Ref(storage),
134134
predef = "",
135-
replArgs
135+
replArgs = replArgs,
136+
promptStr = "DynaML>",
137+
bannerText = "conf/banner.txt"
136138
)
137139

138140
repl.run()
@@ -148,14 +150,17 @@ object DynaML {
148150
predefFile: Option[Path] = None,
149151
file: Option[Path] = None,
150152
args: Seq[String] = Vector.empty,
151-
kwargs: Map[String, String] = Map.empty) = {
153+
kwargs: Map[String, String] = Map.empty,
154+
prompt: String = "DynaML>",
155+
banner: String = "conf/banner.txt") = {
152156

153157
Timer("Repl.run Start")
154158
def storage = Storage(ammoniteHome, predefFile)
155159
lazy val repl = new DynaMLRepl(
156160
System.in, System.out, System.err,
157161
storage = Ref(storage),
158-
predef = predef
162+
predef = predef, promptStr = prompt,
163+
bannerText = banner
159164
)
160165
(file, code) match{
161166
case (None, None) => println("Loading..."); repl.run()

src/main/scala/io/github/mandar2812/dynaml/repl/DynaMLRepl.scala

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import java.io.{InputStream, OutputStream}
44

55
import ammonite.repl.{Bind, Ref, Repl, Storage}
66

7+
import scala.io.Source
8+
79
/**
810
* Created by mandar on 1/6/16.
911
*/
@@ -12,20 +14,17 @@ class DynaMLRepl(input: InputStream,
1214
error: OutputStream,
1315
storage: Ref[Storage],
1416
predef: String = "",
15-
replArgs: Seq[Bind[_]] = Nil) extends
17+
replArgs: Seq[Bind[_]] = Nil,
18+
promptStr: String,
19+
bannerText: String) extends
1620
Repl(input, output, error, storage, predef, replArgs) {
1721

18-
override val prompt = Ref("DynaML>")
22+
override val prompt = Ref(promptStr)
23+
24+
val banner = Source.fromFile(bannerText).getLines.mkString("\n")
1925

2026
override def printBanner(): Unit = {
21-
printStream.println(" ___ ___ ___ ___ ___ ___ "+
22-
" \n /\\ \\ /\\__\\ /\\__\\ /\\ \\ /\\__\\ "+
23-
" /\\__\\ \n /::\\ \\ |::L__L /:| _|_ /::\\ \\ /::L_L_ "+
24-
" /:/ / \n /:/\\:\\__\\ |:::\\__\\ /::|/\\__\\ /::\\:\\__\\ "+
25-
"/:/L:\\__\\ /:/__/ \n \\:\\/:/ / /:;;/__/ \\/|::/ / \\/\\::/ "+
26-
" / \\/_/:/ / \\:\\ \\ \n \\::/ / \\/__/ |:/ / /:/ "+
27-
" / /:/ / \\:\\__\\ \n \\/__/ \\/__/ "+
28-
" \\/__/ \\/__/ \\/__/ ")
27+
printStream.println(banner)
2928
val version = BuildInfo.version
3029
printStream.println("\nWelcome to DynaML "+version+
3130
"\nInteractive Scala shell for Machine Learning Research")

0 commit comments

Comments
 (0)