summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornasr <nsrddyn@gmail.com>2025-11-30 21:23:58 +0100
committernasr <nsrddyn@gmail.com>2025-11-30 21:23:58 +0100
commit3da4bb782e17665ae476b4ed6e52f75952ef292a (patch)
tree6dbdca7e37cbbd4bb4cbcc211cf39cf7d94bf3a9
parentd5a9237b42cd1751e8f353cbee0f01e974d6dfc4 (diff)
feature: remember when I was trying to add a nice TUI with graphs etc, well this is the work around for 27 hours before the deadline
-rw-r--r--src/main/scala/main/view/View.scala114
1 files changed, 114 insertions, 0 deletions
diff --git a/src/main/scala/main/view/View.scala b/src/main/scala/main/view/View.scala
new file mode 100644
index 0000000..fd931a8
--- /dev/null
+++ b/src/main/scala/main/view/View.scala
@@ -0,0 +1,114 @@
+package main.view
+
+
+/**
+ *
+ * Handle the user interface together with the general user flow
+ *
+ **/
+
+class View {
+
+
+ /**
+ * General utils that will be used a lot later
+ * */
+
+ def clearScreen: Unit = print("\u001b[H\u001b[2J")
+
+ def pressToContinue: Unit = {
+ println("\nPress enter to continue")
+ scala.io.StdIn.readLine()
+ }
+
+
+
+ /**
+ * Multi line println for a nice UI
+ * putting "|" in front of the lines to strip the margin
+ * source: https://docs.scala-lang.org/scala3/book/first-look-at-types.html#strings
+ * */
+
+ def header: Unit = {
+
+ println(
+ """
+ _/ |_ ___________ ________ __ ____
+ \ __\/ _ \_ __ \/ ____/ | \_/ __ \
+ | | ( <_> ) | \< <_| | | /\ ___/
+ |__| \____/|__| \__ |____/ \___ >
+ |__| \/
+
+ |========== Welcome to Torque ==========|
+ | Cpu and Ram Stress testing tool |
+ | in Scala |
+ | Author: Abdellah El Morabit |
+ |=======================================|
+ """
+ )
+ pressToContinue
+ }
+
+ /**
+ * Safely casting a string to an int
+ * source: https://alvinalexander.com/scala/how-cast-string-to-int-in-scala-string-int-conversion/
+ */
+ def toInt(stringInput: String): Int = {
+ try {
+ stringInput.toInt
+ } catch {
+ // return 3 to exit the program
+ case e: Exception => 3
+ }
+ }
+
+ def checkInput(input: String): Unit = {
+
+ toInt(input) match {
+
+ case 1 => println("stressing cpu")
+ case 2 => println("stressing ram")
+ case 3 => System.exit(0)
+
+ }
+}
+
+ def menu: Unit = {
+
+ var continue = true
+
+ while (continue) {
+
+ Thread.sleep(500)
+ clearScreen
+ println(
+
+ """
+ _/ |_ ___________ ________ __ ____
+ \ __\/ _ \_ __ \/ ____/ | \_/ __ \
+ | | ( <_> ) | \< <_| | | /\ ___/
+ |__| \____/|__| \__ |____/ \___ >
+ |__| \/
+
+ |======= Select the stress test ========|
+ | 1: CPU |
+ | 2: Ram |
+ | 3: Exit |
+ |=======================================|
+
+ """
+ )
+
+ checkInput(scala.io.StdIn.readLine())
+ }
+
+ }
+
+ def serveView: Unit = {
+
+ clearScreen
+ header
+ menu
+
+ }
+}