Skip to content

Commit f02cfda

Browse files
committed
Add Ammonite's MIT license
1 parent 3515901 commit f02cfda

15 files changed

+248
-231
lines changed

src/dotty/tools/dotc/repl/SyntaxHighlighter.scala renamed to src/dotty/tools/dotc/printing/SyntaxHighlighting.scala

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
package dotty.tools
22
package dotc
3-
package repl
3+
package printing
44

55
import parsing.Tokens._
6-
import ammonite.terminal.FilterTools._
7-
import ammonite.terminal.LazyList._
8-
import ammonite.terminal.SpecialKeys._
9-
import ammonite.terminal.Filter
10-
import ammonite.terminal._
116
import scala.annotation.switch
127
import scala.collection.mutable.StringBuilder
138

src/dotty/tools/dotc/repl/AmmoniteReader.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import filters._
1010
import BasicFilters._
1111
import GUILikeFilters._
1212
import util.SourceFile
13+
import printing.SyntaxHighlighting
1314

1415
class AmmoniteReader(val interpreter: Interpreter)(implicit ctx: Context) extends InteractiveReader {
1516
val interactive = true

src/dotty/tools/dotc/repl/ammonite/Ansi.scala

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ object Ansi {
1818
def matches(state: Short) = (state & resetMask) == applyMask
1919
def apply(s: Ansi.Str) = s.overlay(this, 0, s.length)
2020
}
21+
2122
object Attr {
2223
val Reset = new Attr(Some(Console.RESET), Short.MaxValue, 0)
2324

@@ -38,7 +39,7 @@ object Ansi {
3839
* Represents a set of [[Ansi.Attr]]s all occupying the same bit-space
3940
* in the state `Short`
4041
*/
41-
sealed abstract class Category(){
42+
sealed abstract class Category() {
4243
val mask: Int
4344
val all: Seq[Attr]
4445
lazy val bitsMap = all.map{ m => m.applyMask -> m}.toMap
@@ -47,7 +48,7 @@ object Ansi {
4748
}
4849
}
4950

50-
object Color extends Category{
51+
object Color extends Category {
5152

5253
val mask = 15 << 7
5354
val Reset = makeAttr(Some("\u001b[39m"), 0 << 7)
@@ -66,7 +67,7 @@ object Ansi {
6667
)
6768
}
6869

69-
object Back extends Category{
70+
object Back extends Category {
7071
val mask = 15 << 3
7172

7273
val Reset = makeAttr(Some("\u001b[49m"), 0 << 3)
@@ -84,43 +85,37 @@ object Ansi {
8485
Blue, Magenta, Cyan, White
8586
)
8687
}
87-
object Bold extends Category{
88+
89+
object Bold extends Category {
8890
val mask = 1 << 0
8991
val On = makeAttr(Some(Console.BOLD), 1 << 0)
9092
val Off = makeAttr(None , 0 << 0)
9193
val all = Seq(On, Off)
9294
}
9395

94-
object Underlined extends Category{
96+
object Underlined extends Category {
9597
val mask = 1 << 1
9698
val On = makeAttr(Some(Console.UNDERLINED), 1 << 1)
9799
val Off = makeAttr(None, 0 << 1)
98100
val all = Seq(On, Off)
99101
}
100-
object Reversed extends Category{
102+
103+
object Reversed extends Category {
101104
val mask = 1 << 2
102105
val On = makeAttr(Some(Console.REVERSED), 1 << 2)
103106
val Off = makeAttr(None, 0 << 2)
104107
val all = Seq(On, Off)
105108
}
106109

107110
val hardOffMask = Bold.mask | Underlined.mask | Reversed.mask
108-
val categories = Vector(
109-
Color,
110-
Back,
111-
Bold,
112-
Underlined,
113-
Reversed
114-
)
111+
val categories = List(Color, Back, Bold, Underlined, Reversed)
115112

116113
object Str {
117-
118-
lazy val ansiRegex = "\u001B\\[[;\\d]*m".r
114+
@sharable lazy val ansiRegex = "\u001B\\[[;\\d]*m".r
119115

120116
implicit def parse(raw: CharSequence): Str = {
121-
// This will
122-
val chars = new Array[Char](raw.length)
123-
val colors = new Array[Short](raw.length)
117+
val chars = new Array[Char](raw.length)
118+
val colors = new Array[Short](raw.length)
124119
var currentIndex = 0
125120
var currentColor = 0.toShort
126121

@@ -147,7 +142,6 @@ object Ansi {
147142

148143
Str(chars.take(currentIndex), colors.take(currentIndex))
149144
}
150-
151145
}
152146

153147
/**
@@ -187,6 +181,7 @@ object Ansi {
187181
val (leftColors, rightColors) = colors.splitAt(index)
188182
(new Str(leftChars, leftColors), new Str(rightChars, rightColors))
189183
}
184+
190185
def length = chars.length
191186
override def toString = render
192187

@@ -238,12 +233,9 @@ object Ansi {
238233
// Cap off the left-hand-side of the rendered string with any ansi escape
239234
// codes necessary to rest the state to 0
240235
emitDiff(0)
241-
242236
output.toString
243237
}
244238

245-
246-
247239
/**
248240
* Overlays the desired color over the specified range of the [[Ansi.Str]].
249241
*/
@@ -260,8 +252,5 @@ object Ansi {
260252
}
261253
new Str(chars, colorsOut)
262254
}
263-
264255
}
265-
266-
267256
}

src/dotty/tools/dotc/repl/ammonite/Filter.scala

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,24 @@ package repl
44
package ammonite.terminal
55

66
object Filter {
7-
87
def apply(id: String)(f: PartialFunction[TermInfo, TermAction]): Filter =
9-
new Filter{
8+
new Filter {
109
val op = f.lift
1110
def identifier = id
1211
}
1312

1413
def wrap(id: String)(f: TermInfo => Option[TermAction]): Filter =
15-
new Filter{
14+
new Filter {
1615
val op = f
1716
def identifier = id
1817
}
1918

20-
/**
21-
* Merges multiple [[Filter]]s into one.
22-
*/
19+
/** Merges multiple [[Filter]]s into one. */
2320
def merge(pfs: Filter*) = new Filter {
24-
2521
val op = (v1: TermInfo) => pfs.iterator.map(_.op(v1)).find(_.isDefined).flatten
26-
2722
def identifier = pfs.iterator.map(_.identifier).mkString(":")
2823
}
24+
2925
val empty = Filter.merge()
3026
}
3127

src/dotty/tools/dotc/repl/ammonite/FilterTools.scala

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package dotty.tools
22
package dotc
33
package repl
44
package ammonite.terminal
5+
56
/**
67
* A collection of helpers that to simpify the common case of building filters
78
*/
@@ -12,8 +13,8 @@ object FilterTools {
1213
var splitIndex = 0
1314
var length = 0
1415

15-
while(length < in){
16-
ansiRegex.r.findPrefixOf(buffer.drop(splitIndex)) match{
16+
while(length < in) {
17+
ansiRegex.r.findPrefixOf(buffer.drop(splitIndex)) match {
1718
case None =>
1819
splitIndex += 1
1920
length += 1
@@ -24,9 +25,6 @@ object FilterTools {
2425
splitIndex
2526
}
2627

27-
28-
29-
3028
/**
3129
* Shorthand to construct a filter in the common case where you're
3230
* switching on the prefix of the input stream and want to run some
@@ -58,12 +56,9 @@ object FilterTools {
5856
def identifier = "Case"
5957
}
6058

61-
/**
62-
* Shorthand for pattern matching on [[TermState]]
63-
*/
59+
/** Shorthand for pattern matching on [[TermState]] */
6460
val TS = TermState
6561

66-
6762
def findChunks(b: Vector[Char], c: Int) = {
6863
val chunks = Terminal.splitBuffer(b)
6964
// The index of the first character in each chunk
@@ -76,11 +71,10 @@ object FilterTools {
7671
(chunks, chunkStarts, chunkIndex)
7772
}
7873

79-
def firstRow(cursor: Int, buffer: Vector[Char], width: Int) = {
74+
def firstRow(cursor: Int, buffer: Vector[Char], width: Int) =
8075
cursor < width && (buffer.indexOf('\n') >= cursor || buffer.indexOf('\n') == -1)
81-
}
82-
def lastRow(cursor: Int, buffer: Vector[Char], width: Int) = {
76+
77+
def lastRow(cursor: Int, buffer: Vector[Char], width: Int) =
8378
(buffer.length - cursor) < width &&
8479
(buffer.lastIndexOf('\n') < cursor || buffer.lastIndexOf('\n') == -1)
85-
}
8680
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
License
2+
=======
3+
4+
5+
The MIT License (MIT)
6+
7+
Copyright (c) 2014 Li Haoyi ([email protected])
8+
9+
Permission is hereby granted, free of charge, to any person obtaining a copy
10+
of this software and associated documentation files (the "Software"), to deal
11+
in the Software without restriction, including without limitation the rights
12+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
copies of the Software, and to permit persons to whom the Software is
14+
furnished to do so, subject to the following conditions:
15+
16+
The above copyright notice and this permission notice shall be included in
17+
all copies or substantial portions of the Software.
18+
19+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25+
DEALINGS IN THE SOFTWARE.

src/dotty/tools/dotc/repl/ammonite/Protocol.scala

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,24 @@ case class TermInfo(ts: TermState, width: Int)
77

88
sealed trait TermAction
99
case class Printing(ts: TermState, stdout: String) extends TermAction
10-
case class TermState(inputs: LazyList[Int],
11-
buffer: Vector[Char],
12-
cursor: Int,
13-
msg: Ansi.Str = "") extends TermAction
14-
object TermState{
15-
def unapply(ti: TermInfo): Option[(LazyList[Int], Vector[Char], Int, Ansi.Str)] = {
10+
case class TermState(
11+
inputs: LazyList[Int],
12+
buffer: Vector[Char],
13+
cursor: Int,
14+
msg: Ansi.Str = ""
15+
) extends TermAction
16+
17+
object TermState {
18+
def unapply(ti: TermInfo): Option[(LazyList[Int], Vector[Char], Int, Ansi.Str)] =
1619
TermState.unapply(ti.ts)
17-
}
18-
def unapply(ti: TermAction): Option[(LazyList[Int], Vector[Char], Int, Ansi.Str)] = ti match{
19-
case ts: TermState => TermState.unapply(ts)
20-
case _ => None
21-
}
2220

21+
def unapply(ti: TermAction): Option[(LazyList[Int], Vector[Char], Int, Ansi.Str)] =
22+
ti match {
23+
case ts: TermState => TermState.unapply(ts)
24+
case _ => None
25+
}
2326
}
27+
2428
case class ClearScreen(ts: TermState) extends TermAction
2529
case object Exit extends TermAction
2630
case class Result(s: String) extends TermAction
27-

0 commit comments

Comments
 (0)