<commit_before>package scribe.output.format

import scribe.output._
import scribe.ANSI

import scala.language.implicitConversions

object ANSIOutputFormat extends OutputFormat {
  private object ansi {
    var fg: Option[ANSI] = None
    var bg: Option[ANSI] = None
    var bold: Boolean = false
    var italic: Boolean = false
    var underline: Boolean = false
    var strikethrough: Boolean = false
  }

  override def begin(stream: String => Unit): Unit = stream(ANSI.ctrl.Reset)

  def apply(output: LogOutput, stream: String => Unit): Unit = output match {
    case o: TextOutput => stream(o.plainText)
    case o: CompositeOutput => o.entries.foreach(apply(_, stream))
    case o: ColoredOutput => {
      val color = color2fg(o.color)
      stream(color.ansi)
      val previous = ansi.fg
      ansi.fg = Some(color)
      try {
        apply(o.output, stream)
      } finally {
        ansi.fg = previous
        reset(stream)
      }<commit_msg>Reset ANSI before and after each line<commit_after>package scribe.output.format

import scribe.output._
import scribe.ANSI

import scala.language.implicitConversions

object ANSIOutputFormat extends OutputFormat {
  private object ansi {
    var fg: Option[ANSI] = None
    var bg: Option[ANSI] = None
    var bold: Boolean = false
    var italic: Boolean = false
    var underline: Boolean = false
    var strikethrough: Boolean = false
  }

  override def begin(stream: String => Unit): Unit = stream(ANSI.ctrl.Reset)

  override def end(stream: String => Unit): Unit = stream(ANSI.ctrl.Reset)

  def apply(output: LogOutput, stream: String => Unit): Unit = output match {
    case o: TextOutput => stream(o.plainText)
    case o: CompositeOutput => o.entries.foreach(apply(_, stream))
    case o: ColoredOutput => {
      val color = color2fg(o.color)
      stream(color.ansi)
      val previous = ansi.fg
      ansi.fg = Some(color)
      try {
        apply(o.output, stream)
      } finally {
        ansi.fg = previous
        reset(stream)
      }
{'fraction_non_alphanumeric': 0.1, 'fraction_numerical': 0.0009950248756218905, 'mean_word_length': 2.9980119284294235, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6203775', 'n_tokens_mistral': 620, 'n_tokens_neox': 613, 'n_words': 179}