aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Odersky <jakob@inpher.io>2019-10-09 20:32:48 -0400
committerJakob Odersky <jakob@inpher.io>2019-10-09 20:33:16 -0400
commitf67c8d59a26132a8d7c80b3e15bddc35ba0091d9 (patch)
treeeb733861e64397d7b36b2ee00aa97e8a92a9044f
parent0ceee5ed4bae240b8c8e94d2fd7424d9d0b67ec7 (diff)
downloadscala-triad-f67c8d59a26132a8d7c80b3e15bddc35ba0091d9.tar.gz
scala-triad-f67c8d59a26132a8d7c80b3e15bddc35ba0091d9.tar.bz2
scala-triad-f67c8d59a26132a8d7c80b3e15bddc35ba0091d9.zip
format
-rw-r--r--.scalafmt.conf0
-rw-r--r--client/src/Main.scala13
-rw-r--r--client/src/http/CurlBackend.scala59
-rw-r--r--client/src/http/curl.scala16
-rw-r--r--server/src/LiveMessages.scala6
-rw-r--r--shared/Message.scala8
-rw-r--r--shared/Templates.scala9
-rw-r--r--shared/TextTemplates.scala41
-rw-r--r--shared/http/Response.scala8
-rw-r--r--ui/src/http/XhrBackend.scala3
10 files changed, 102 insertions, 61 deletions
diff --git a/.scalafmt.conf b/.scalafmt.conf
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/.scalafmt.conf
diff --git a/client/src/Main.scala b/client/src/Main.scala
index 4b11fe0..f87be2a 100644
--- a/client/src/Main.scala
+++ b/client/src/Main.scala
@@ -27,10 +27,12 @@ object Main {
val message = Message(content, author).toJson.compactPrint
- val req = Request("POST",
- s"$server/messages",
- Map("Content-type" -> "application/json"),
- message.getBytes("utf-8"))
+ val req = Request(
+ "POST",
+ s"$server/messages",
+ Map("Content-type" -> "application/json"),
+ message.getBytes("utf-8")
+ )
if (verbose) {
System.err.println(req.url)
@@ -43,7 +45,8 @@ object Main {
sys.exit(0)
case resp =>
System.err.println(
- s"Bad response code while posting message ${resp.statusCode}.")
+ s"Bad response code while posting message ${resp.statusCode}."
+ )
sys.exit(1)
}
} catch {
diff --git a/client/src/http/CurlBackend.scala b/client/src/http/CurlBackend.scala
index 4dc8577..ff1cf7d 100644
--- a/client/src/http/CurlBackend.scala
+++ b/client/src/http/CurlBackend.scala
@@ -32,8 +32,10 @@ object CurlBackend {
def allocHead() = allocAppend(0, NullPtr[Chunk])
- def allocAppend(size: CSize,
- head: Ptr[Chunk] = NullPtr[Chunk]): Ptr[Chunk] = {
+ def allocAppend(
+ size: CSize,
+ head: Ptr[Chunk] = NullPtr[Chunk]
+ ): Ptr[Chunk] = {
val chunk: Ptr[Chunk] = stdlib.malloc(sizeof[Chunk]).cast[Ptr[Chunk]]
if (chunk == NullPtr[Chunk]) return NullPtr[Chunk]
@@ -73,7 +75,7 @@ object CurlBackend {
var chunk = head
do {
val next = chunk.next
- var i = 0l
+ var i = 0L
while (i < next.size) {
buffer += next.buffer(i)
i += 1
@@ -88,7 +90,7 @@ object CurlBackend {
do {
val next = chunk.next
val buffer = new ArrayBuffer[Byte]()
- var i = 0l
+ var i = 0L
while (i < next.size) {
buffer += next.buffer(i)
i += 1
@@ -100,10 +102,12 @@ object CurlBackend {
}
- private def receive(data: Ptr[Byte],
- size: CSize,
- nmemb: CSize,
- userdata: Ptr[Byte]): CSize = {
+ private def receive(
+ data: Ptr[Byte],
+ size: CSize,
+ nmemb: CSize,
+ userdata: Ptr[Byte]
+ ): CSize = {
val head = userdata.cast[Ptr[Chunk]]
val length = size * nmemb
val chunk = Chunk.allocAppend(length, head)
@@ -135,19 +139,25 @@ object CurlBackend {
() =>
curl_easy_setopt(curl, CURLoption.CURLOPT_ERRORBUFFER, errorBuffer),
() =>
- curl_easy_setopt(curl,
- CURLoption.CURLOPT_CUSTOMREQUEST,
- toCString(request.method)),
+ curl_easy_setopt(
+ curl,
+ CURLoption.CURLOPT_CUSTOMREQUEST,
+ toCString(request.method)
+ ),
() =>
- curl_easy_setopt(curl,
- CURLoption.CURLOPT_URL,
- toCString(request.url)),
+ curl_easy_setopt(
+ curl,
+ CURLoption.CURLOPT_URL,
+ toCString(request.url)
+ ),
() => {
val buffer = ArrayUtils.toBuffer(request.body)
curl_easy_setopt(curl, CURLoption.CURLOPT_POSTFIELDS, buffer)
- curl_easy_setopt(curl,
- CURLoption.CURLOPT_POSTFIELDSIZE,
- request.body.size)
+ curl_easy_setopt(
+ curl,
+ CURLoption.CURLOPT_POSTFIELDSIZE,
+ request.body.size
+ )
},
() => {
for ((k, v) <- request.headers) {
@@ -161,9 +171,11 @@ object CurlBackend {
() =>
curl_easy_setopt(curl, CURLoption.CURLOPT_WRITEDATA, responseChunks),
() =>
- curl_easy_setopt(curl,
- CURLoption.CURLOPT_HEADERDATA,
- responseHeaderChunks),
+ curl_easy_setopt(
+ curl,
+ CURLoption.CURLOPT_HEADERDATA,
+ responseHeaderChunks
+ ),
() => curl_easy_perform(curl)
)
@@ -186,13 +198,16 @@ object CurlBackend {
statusCode = (!responseCode).toInt,
headers = responseHeaders.toMap,
body = Chunk.toArray(responseChunks)
- ))
+ )
+ )
case code =>
val message = curl_easy_strerror(curl, code)
Failure(
new RuntimeException(
- s"${fromCString(errorBuffer)} (curl exit status $code)"))
+ s"${fromCString(errorBuffer)} (curl exit status $code)"
+ )
+ )
}
Chunk.freeAll(responseChunks)
Chunk.freeAll(responseHeaderChunks)
diff --git a/client/src/http/curl.scala b/client/src/http/curl.scala
index 1eda584..97a867e 100644
--- a/client/src/http/curl.scala
+++ b/client/src/http/curl.scala
@@ -59,15 +59,19 @@ object curl {
def curl_easy_init(): CURL = extern
- def curl_easy_setopt(curl: CURL,
- option: CURLoption,
- parameter: CVararg*): CURLcode = extern
+ def curl_easy_setopt(
+ curl: CURL,
+ option: CURLoption,
+ parameter: CVararg*
+ ): CURLcode = extern
def curl_easy_perform(curl: CURL): CURLcode = extern
- def curl_easy_getinfo(curl: CURL,
- option: CURLINFO,
- parameter: CVararg*): CURLcode = extern
+ def curl_easy_getinfo(
+ curl: CURL,
+ option: CURLINFO,
+ parameter: CVararg*
+ ): CURLcode = extern
def curl_easy_cleanup(curl: CURL): Unit = extern
diff --git a/server/src/LiveMessages.scala b/server/src/LiveMessages.scala
index 9729353..b2d27c1 100644
--- a/server/src/LiveMessages.scala
+++ b/server/src/LiveMessages.scala
@@ -11,8 +11,10 @@ import akka.stream.{Materializer, OverflowStrategy}
class LiveMessages(implicit materializer: Materializer) {
- private val (in: SourceQueueWithComplete[Message],
- out: Source[Message, NotUsed]) = Source
+ private val (
+ in: SourceQueueWithComplete[Message],
+ out: Source[Message, NotUsed]
+ ) = Source
.queue[Message](10, OverflowStrategy.dropTail)
.toMat(BroadcastHub.sink[Message])(Keep.both)
.run()
diff --git a/shared/Message.scala b/shared/Message.scala
index 84c733e..bc76fae 100644
--- a/shared/Message.scala
+++ b/shared/Message.scala
@@ -3,9 +3,11 @@ package triad
import java.security.MessageDigest
import java.time.Instant
-case class Message(content: String,
- author: String,
- timestamp: Instant = Instant.now()) {
+case class Message(
+ content: String,
+ author: String,
+ timestamp: Instant = Instant.now()
+) {
lazy val id: String = {
val digest = MessageDigest.getInstance("SHA-256")
diff --git a/shared/Templates.scala b/shared/Templates.scala
index 10ee116..23a8eff 100644
--- a/shared/Templates.scala
+++ b/shared/Templates.scala
@@ -1,7 +1,8 @@
package triad
class Templates[Builder, Output <: FragT, FragT](
- val bundle: scalatags.generic.Bundle[Builder, Output, FragT]) {
+ val bundle: scalatags.generic.Bundle[Builder, Output, FragT]
+) {
import bundle.all._
val colorStyles = List(
@@ -20,7 +21,8 @@ class Templates[Builder, Output <: FragT, FragT](
(hash * 31 + char.toInt)
}
colorStyles(
- ((dataHash % colorStyles.length) + colorStyles.length) % colorStyles.length)
+ ((dataHash % colorStyles.length) + colorStyles.length) % colorStyles.length
+ )
}
def message(msg: Message) = {
@@ -28,7 +30,8 @@ class Templates[Builder, Output <: FragT, FragT](
hashTag =>
span(`class` := "badge badge-light float-right ml-1")(
hashTag
- ))
+ )
+ )
div(`class` := "col-xs-12 col-sm-6 col-md-3 col-lg-2")(
div(`class` := s"card text-white mb-3 ${dataStyle(msg.author)}")(
div(`class` := "card-header")(
diff --git a/shared/TextTemplates.scala b/shared/TextTemplates.scala
index 0dd45c5..5674eac 100644
--- a/shared/TextTemplates.scala
+++ b/shared/TextTemplates.scala
@@ -9,8 +9,7 @@ object TextTemplates extends Templates(scalatags.Text) {
div(id := "scalajs-error", style := "display: none;")(
"ScalaJS raised an exception. See the log for more information."
),
- script(`type` := "text/javascript",
- src := "/out.js"),
+ script(`type` := "text/javascript", src := "/out.js"),
script(`type` := "text/javascript")(
raw(
"""|document.addEventListener("DOMContentLoaded", function(event) {
@@ -40,20 +39,30 @@ object TextTemplates extends Templates(scalatags.Text) {
def page(messages: Seq[Message], js: Boolean = true) = html(
head(
- link(rel := "stylesheet",
- `type` := "text/css",
- href := "/assets/lib/bootstrap-4.1.0/css/bootstrap-reboot.min.css"),
- link(rel := "stylesheet",
- `type` := "text/css",
- href := "/assets/lib/bootstrap-4.1.0/css/bootstrap-grid.min.css"),
- link(rel := "stylesheet",
- `type` := "text/css",
- href := "/assets/lib/bootstrap-4.1.0/css/bootstrap.min.css"),
- link(rel := "stylesheet",
- `type` := "text/css",
- href := "/assets/main.css"),
- meta(name := "viewport",
- content := "width=device-width, initial-scale=1, shrink-to-fit=no")
+ link(
+ rel := "stylesheet",
+ `type` := "text/css",
+ href := "/assets/lib/bootstrap-4.1.0/css/bootstrap-reboot.min.css"
+ ),
+ link(
+ rel := "stylesheet",
+ `type` := "text/css",
+ href := "/assets/lib/bootstrap-4.1.0/css/bootstrap-grid.min.css"
+ ),
+ link(
+ rel := "stylesheet",
+ `type` := "text/css",
+ href := "/assets/lib/bootstrap-4.1.0/css/bootstrap.min.css"
+ ),
+ link(
+ rel := "stylesheet",
+ `type` := "text/css",
+ href := "/assets/main.css"
+ ),
+ meta(
+ name := "viewport",
+ content := "width=device-width, initial-scale=1, shrink-to-fit=no"
+ )
),
body(
conversation(messages),
diff --git a/shared/http/Response.scala b/shared/http/Response.scala
index 4ba2342..652e72f 100644
--- a/shared/http/Response.scala
+++ b/shared/http/Response.scala
@@ -1,6 +1,8 @@
package triad
package http
-case class Response(statusCode: Int,
- headers: Map[String, String],
- body: Array[Byte])
+case class Response(
+ statusCode: Int,
+ headers: Map[String, String],
+ body: Array[Byte]
+)
diff --git a/ui/src/http/XhrBackend.scala b/ui/src/http/XhrBackend.scala
index 3a791c1..376e66d 100644
--- a/ui/src/http/XhrBackend.scala
+++ b/ui/src/http/XhrBackend.scala
@@ -42,7 +42,8 @@ trait XhrBackend extends Backend {
}
xhr.ontimeout = (e: Event) => {
promise.failure(
- new TimeoutException(s"Request timed out: ${xhr.statusText}"))
+ new TimeoutException(s"Request timed out: ${xhr.statusText}")
+ )
}
promise.future