Skip to content

Instantly share code, notes, and snippets.

@tstone
Created June 5, 2010 09:54
Show Gist options
  • Save tstone/426501 to your computer and use it in GitHub Desktop.
Save tstone/426501 to your computer and use it in GitHub Desktop.
import scala.io.Source
if (args.length > 0) {
def formatSourcePrefix(line: Int, suffix: String, max: Int = 5): String = {
var prefix: String = ""
for (i <- 1 to (max - line.toString.length))
prefix += " "
prefix + line.toString + suffix
}
def formatSourceLine(lines: List[String], line: Int = 1, output: String = ""): String = {
val out = output + formatSourcePrefix(line, " | ") + lines.head + "\n"
if (lines.length > 1)
formatSourceLine(lines.tail, line + 1, out)
else
out
}
// Read file from disk
val lines = Source.fromPath(args(0)).getLines().toList
// Print results to screen
println
print(formatSourceLine(lines))
}
else {
// Print out proper syntax
Console.err.println
Console.err.println("scala file.scala [filename]")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment