1
/* NSC -- new Scala compiler
2
* Copyright 2005-2011 LAMP/EPFL
3
* @author Paul Phillips
6
package scala.tools.nsc
9
case class KeyBinding(name: String, code: Int, aliases: List[String], description: String) {
10
def nameString = if (aliases.nonEmpty) aliases mkString ", " else name
11
override def toString = "%3d %s: %s".format(code, nameString, description)
15
def parse(bindings: String): List[KeyBinding] = {
16
def loop(xs: List[String]): List[KeyBinding] = {
17
val (comment, lines) = xs span (_ startsWith "#")
18
val description = comment map (_ drop 1 trim) mkString " "
19
val (aliases, desc) = description span (_ != ':') match {
21
x split ',' map (_.trim) toList,
22
if (y == "") "" else y.tail.trim
28
val kb = (hd indexOf '=') match {
29
case -1 => KeyBinding(hd, -1, aliases, desc)
30
case idx => KeyBinding(hd drop idx + 1, hd take idx toInt, aliases, desc)
35
// This is verrrrrrrry specific to the current contents
36
// of the keybindings.properties in jline.
37
loop(bindings split "\\n" map (_.trim) dropWhile (_ != "") filterNot (_ == "") toList) sortBy (_.code)