Skip to content

Commit

Permalink
Provide a warn method, like fail
Browse files Browse the repository at this point in the history
  • Loading branch information
propensive committed Mar 16, 2024
1 parent 740e7e5 commit b5261af
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/core/fail.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,19 @@ def fail(using Quotes)(message: Message, pos: quotes.reflect.Position | Null = n

if pos == null then report.errorAndAbort(text) else report.errorAndAbort(text, pos)


def warn(using Quotes)(message: Message, pos: quotes.reflect.Position | Null = null)(using Realm): Unit =
import quotes.reflect.*
import dotty.tools.dotc.config.Settings.Setting.value

val useColor: Boolean = quotes match
case quotes: runtime.impl.QuotesImpl => value(quotes.ctx.settings.color)(using quotes.ctx) != "never"
case _ => false

val text =
if useColor
then s"${27.toChar}[38;2;0;190;255m${27.toChar}[1m${summon[Realm].name}${27.toChar}[0m ${message.colorText}"
else s"${summon[Realm].name}: ${message.text}"

if pos == null then report.warning(text) else report.warning(text, pos)

0 comments on commit b5261af

Please sign in to comment.