Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a tiny figlet font parser #47

Merged
merged 2 commits into from
Dec 17, 2020
Merged

Add a tiny figlet font parser #47

merged 2 commits into from
Dec 17, 2020

Conversation

domartynov
Copy link
Contributor

wip

@CLAassistant
Copy link

CLAassistant commented Nov 21, 2020

CLA assistant check
All committers have signed the CLA.

override def aspects = List(TestAspect.jvmOnly)

override def spec = suite("parsing")(
testM("parse standard.flf") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good. Maybe it would be nice to add a test that is normally @@ ignored, and which downloads all fonts from the website and tests that all of them can be parsed?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking of a resource like this:

http://www.figlet.org/fontdb.cgi

Wouldn't be too hard to just ZIO.foreach on a list of these files, scala.io.Source load them, and then parse them. Could catch possible errors and be run manually from time to time if anyone works in the parser code.

Copy link
Contributor Author

@domartynov domartynov Nov 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, i had something like this in mind, and few related questions for zio-test: 1) to check @@ ignored 2) in my practice i found useful for such tasks to generate a report for visual inspection, hence how to better do it in zio-test, e.g. to gen a temp file, and log a URL in console -- does zio-test have a test-scoped log channel for that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ZIO Test doesn't have report generation yet, but will soon.

object FigFontParser {
import ParseLib._

def parse(lines: Seq[String]): Either[String, FigFont] =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could move this to FigFont, as a constructor:

object FigFont {
  ...
  def fromFile(content: String): Either[String, FigFont] = ???
  def fromLines(content: Iterable[String]): Either[String, FigFont] = ???
  ...
}

Copy link
Contributor Author

@domartynov domartynov Nov 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • add object FigFont with publish API

chars: Map[Char, FigChar]
)

final case class FigChar(lines: Seq[FigCharLine], width: Int, height: Int)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than use the type Seq, we should probably use zio.Chunk for high-performance and immutability.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initially, i was using Chunk everywhere there is Seq now, but for some reason was getting NoSuchMethodException in Chunk.head -- i wonder if the issue was caused by the parser being in the shared project while the tests in the jvm project -- I'll try to restore Chunk.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try chunk(0) instead of chunk.head (although keep in mind it is unsafe).

@@ -0,0 +1,336 @@
package zio.cli

import scala.collection.mutable
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is a mutable collection necessary somewhere here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just in one place: Parser#rep, i'll try to replace with FP using zio.Chunk -- it just coming to Scala all these allocations to support abstractions... need more time to calibrate the perception 🦀 😉

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine as it is, I think, just wanted to check.

)
}

private[cli] object ParseLib {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this code imported or adapted from anywhere, such that we should reproduce copyright notices and ensure license compatibility? Or is it novel?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Novel, but i looked at https://github.com/scala/scala-parser-combinators for inspiration. I'd like to revisit it again, as the font file parser turned out simpler than i anticipated 😄

Copy link
Member

@jdegoes jdegoes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fantastic work! Just a few minor comments and suggestions, otherwise looks good to me. You really earned that t-shirt! 😉 😆

@jdegoes jdegoes marked this pull request as ready for review November 22, 2020 15:51
@domartynov
Copy link
Contributor Author

Thanks @jdegoes! Having a lot of fun...😄😏 I'll continue working on the PR for a few days, and ping you for a final review. I wish I was better familiar with zio codebases and FD from the start, so my ad hoc code was more conforming -- i'd like to refactor to better match zio-codec, but probably keep the executable encoding 😉

@jdegoes
Copy link
Member

jdegoes commented Nov 23, 2020

@domartynov Sounds great, just let me know when you're ready for that final review!

@jdegoes
Copy link
Member

jdegoes commented Nov 24, 2020

Be sure also to format the code using scalafmt so it will pass the lint checks!

@domartynov
Copy link
Contributor Author

@jdegoes i've updated the PR:

  • moved the code under the figlet package to not pollute zio.cli
  • sorry, you'll find all the previous PR code is replaced, but it got better 😉
  • i think i've addressed your previous comments except for the integration test to run against http://www.figlet.org/fontdb.cgi as i'd like to implement rendering first (following shortly), so the test renders all downloaded fonts in an .html file

@jdegoes jdegoes merged commit 7894099 into zio:master Dec 17, 2020
@jdegoes
Copy link
Member

jdegoes commented Dec 17, 2020

@domartynov Amazing work! Thank you for your contribution and let me know if you like the t-shirt. 😆 💪

@domartynov
Copy link
Contributor Author

@jdegoes Thanks! yes, sure, i think i've submitted the form during the hackathon 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants