commit be2d24771e1b1986a1ee90f32e5b3c3d93de2ae0 Author: Paillat Date: Fri Jul 25 10:17:27 2025 +0200 First commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9e79245 --- /dev/null +++ b/.gitignore @@ -0,0 +1,32 @@ +# macOS +.DS_Store + +# sbt specific +dist/* +target/ +lib_managed/ +src_managed/ +project/boot/ +project/plugins/project/ +project/local-plugins.sbt +.history +.ensime +.ensime_cache/ +.sbt-scripted/ +local.sbt + +# Bloop +.bsp + +# VS Code +.vscode/ + +# Metals +.bloop/ +.metals/ +metals.sbt + +# IDEA +.idea +.idea_modules +/.worksheet/ diff --git a/.scalafix.conf b/.scalafix.conf new file mode 100644 index 0000000..b9b6548 --- /dev/null +++ b/.scalafix.conf @@ -0,0 +1,11 @@ +rules = [ + RemoveUnused, + DisableSyntax, + LeakingImplicitClassVal, + NoValInForComprehension, + ProcedureSyntax, + RedundantSyntax, + OrganizeImports, + NoAutoTupling, + ExplicitResultTypes +] \ No newline at end of file diff --git a/.scalafmt.conf b/.scalafmt.conf new file mode 100644 index 0000000..d5a4c81 --- /dev/null +++ b/.scalafmt.conf @@ -0,0 +1,5 @@ +version = 3.9.8 +runner.dialect = scala3 + +align.preset = more +maxColumn = 120 \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..eeaca4e --- /dev/null +++ b/README.md @@ -0,0 +1,26 @@ +# Scala hello world + +This is my take at a hello world in Scala. It prints a colored "Hello, World!" message to the console. + +![](img.png) + +## Usage +This project uses [sbt](https://www.scala-sbt.org/) as the build tool. To run the project, you can use the following command: + +```bash +sbt run +``` + +## Requirements +- [Eclipse Temurin](https://adoptium.net/) or any other JDK 17+ installed on your system +- [sbt](https://www.scala-sbt.org/) for building and running the project +- [Scala](https://www.scala-lang.org/) installed on your system + +## Dependencies +This project uses the following dependencies: +- [Fansi](https://github.com/com-lihaoyi/fansi) for colored output in the console. + +## Linting and Formatting +Since I wanted to learn as most as I could by making this first project, I also setup [scalafmt](https://scalameta.org/scalafmt/) for code formatting and [scalafix](https://scalacenter.github.io/scalafix/) for code linting, not that they would be particularly useful in this context. +## License +This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details. \ No newline at end of file diff --git a/build.sbt b/build.sbt new file mode 100644 index 0000000..bbe28db --- /dev/null +++ b/build.sbt @@ -0,0 +1,15 @@ +val scala3Version = "3.7.1" + +lazy val root = project + .in(file(".")) + .settings( + name := "hello-world-scala", + version := "0.1.0-SNAPSHOT", + scalaVersion := scala3Version, + semanticdbEnabled := true, + scalacOptions += "-Wunused:all", + javaOptions += "-Dfile.encoding=UTF-8", + javaOptions += "-Dstdout.encoding=UTF-8", + javaOptions += "-Dstderr.encoding=UTF-8", + libraryDependencies += "com.lihaoyi" %% "fansi" % "0.5.0" + ) diff --git a/img.png b/img.png new file mode 100644 index 0000000..0ba2760 Binary files /dev/null and b/img.png differ diff --git a/project/build.properties b/project/build.properties new file mode 100644 index 0000000..c02c575 --- /dev/null +++ b/project/build.properties @@ -0,0 +1 @@ +sbt.version=1.11.3 diff --git a/project/plugins.sbt b/project/plugins.sbt new file mode 100644 index 0000000..59ba6d8 --- /dev/null +++ b/project/plugins.sbt @@ -0,0 +1 @@ +addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.14.3") diff --git a/src/main/resources/hello.txt b/src/main/resources/hello.txt new file mode 100644 index 0000000..69b07c9 --- /dev/null +++ b/src/main/resources/hello.txt @@ -0,0 +1,6 @@ +██╗ ██╗███████╗██╗ ██╗ ██████╗ ██╗ ██╗ ██████╗ ██████╗ ██╗ ██████╗ +██║ ██║██╔════╝██║ ██║ ██╔═══██╗ ██║ ██║██╔═══██╗██╔══██╗██║ ██╔══██╗ +███████║█████╗ ██║ ██║ ██║ ██║ ██║ █╗ ██║██║ ██║██████╔╝██║ ██║ ██║ +██╔══██║██╔══╝ ██║ ██║ ██║ ██║ ██║███╗██║██║ ██║██╔══██╗██║ ██║ ██║ +██║ ██║███████╗███████╗███████╗╚██████╔╝ ╚███╔███╔╝╚██████╔╝██║ ██║███████╗██████╔╝ +╚═╝ ╚═╝╚══════╝╚══════╝╚══════╝ ╚═════╝ ╚══╝╚══╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝╚═════╝ \ No newline at end of file diff --git a/src/main/scala/Main.scala b/src/main/scala/Main.scala new file mode 100644 index 0000000..184e405 --- /dev/null +++ b/src/main/scala/Main.scala @@ -0,0 +1,23 @@ +import fansi.Attr +import fansi.Color +import scala.io.Source + +def colors: List[Attr] = List( + Color.Red, + Color.LightRed, + Color.Yellow, + Color.Green, + Color.Blue, + Color.Magenta +) + +val message: String = Source.fromResource("hello.txt").mkString + +@main def hello(): Unit = { + val splitMessage: Array[String] = message.split("\n") + for (i <- splitMessage.indices) { + val colorIndex = i % colors.length + val coloredLine = colors(colorIndex)(splitMessage(i)) + println(coloredLine) + } +} diff --git a/src/test/scala/MySuite.scala b/src/test/scala/MySuite.scala new file mode 100644 index 0000000..621784d --- /dev/null +++ b/src/test/scala/MySuite.scala @@ -0,0 +1,9 @@ +// For more information on writing tests, see +// https://scalameta.org/munit/docs/getting-started.html +class MySuite extends munit.FunSuite { + test("example test that succeeds") { + val obtained = 42 + val expected = 42 + assertEquals(obtained, expected) + } +}