Skip to content

Scurses, terminal drawing API for Scala, and Onions, a Scurses framework for easy terminal UI

License

Notifications You must be signed in to change notification settings

LoafingBunny/Marily

 
 

Repository files navigation

Marily

Marily is a project that attempts to create a dashboard to use to monitor both in real time and offline. Don't expect anything better from the forked project as of now but some updated deps. and some small refactoring matching my code style.

I think to integrate some of these libraries: https://github.com/fusesource/jansi to replace the scourses library, in case https://github.com/mabe02/lanterna to add nice stuff I still don't know the purpose https://github.com/null93/drawille to improve plots http://slick.lightbend.com/ to read infos from a database, for later analysis or for real time watching maybe also scala-pb as an alternative way to store real time packets

maybe an ipc library might be useful, but thats at a too early stage to decide

the final last ultimate objective is to have a dash and a database standard to debug and visualize the neural network training

Scurses / Onions

Scurses and Onions are frameworks for drawing nice things in your terminal using simple, elegant Scala. Scurses provides a low-level drawing and event handling API while Onions provides a high-level UI API with useful widgets.

Onions

High-level Scurses framework for easy terminal UI

screen shot 2015-11-12 at 10 58 51

screen shot 2015-11-12 at 10 59 11

screen shot 2015-11-12 at 10 59 40


Examples

What's been done so far:

$ sbt onions/run

Be sure that your terminal is resized big enough, scrolling is not supported yet.

Goal is to provide an API full of widgets to make it really easy for users to quickly set up a dashboard to monitor their services in the terminal (graphs, histograms, logs, etc.)

How to use

Scurses { implicit screen =>
  val frame = Frame("Example UI")
  // Three columns
  val colA = frame.panel
  val colB = colA.splitRight
  val colC = colB.splitRight
  // Split second column in three rows
  val colB2 = colB.splitDown
  val colB3 = colB2.splitDown
  // Split third row of second column into two columns
  val colB3B = colB3.splitRight
  val colB3B2 = colB3B.splitDown
  // Split last column into two rows
  val colC2 = colC.splitDown

  // Add a label in the first column
  Label(colA, Lorem.Ipsum, TextWrap.JUSTIFY)
  
  val r = Random
  val points = (1 to 50) map (i => {
    val x = r.nextInt(40)
    val y = 50 - x + (r.nextGaussian() * 5).toInt - 2
    (x, y max 0)
  })
  
  // Add a scatter plot in the first row of third column
  ScatterPlot(colC, points, "Time", "Sales")
  
  // Show a heat map of the same values in the second row
  HeatMap(colC2, points, "Time", "Sales")

  // Display and launch event loop
  frame.show()
}

For examples about all widgets, see ExampleUI.scala

Keyboard controls

Keys Action
/ Focus next widget in direction / Focus next panel in direction
/ Focus next panel in direction
/ + Focus next / previous panel
CTRL+SPACE Switch to next tab (if panel has multiple tabs)
SPACE / Activate label action, check radio or checkbox
< / > Move slider left / right (also with SPACE / )
ESC / CTRL+C Exit

Scurses

Low-level terminal drawing API for Scala

screen shot 2015-11-12 at 11 07 32

---

Examples

  • Hello World:
$ sbt "scurses/run-main net.team2xh.scurses.examples.HelloWorld"
  • Game of life:
$ sbt scurses/run
  • Stress test:
$ sbt "scurses/run-main net.team2xh.scurses.examples.StressTest"

How to use

import net.team2xh.scurses.Scurses

Scurses { screen =>
  // The screen will only be in Scurses mode inside this block
  // Scurses will reset the terminal buffer and everything when outside
  
  // Get the current terminal size
  val (w, h) = screen.size
  
  val greeting = "Hello, world!"
  val prompt = "Press a key to continue..."
  // Put some strings in the middle of the screen
  screen.put(w/2 - greeting.length/2, h/2, greeting)
  screen.put(w/2 - prompt.length/2, h/2 + 1, prompt, Colors.BRIGHT_BLACK)
  // Flush the buffer
  screen.refresh()
  // Wait for an input without storing it
  screen.keypress()
}

About

Scurses, terminal drawing API for Scala, and Onions, a Scurses framework for easy terminal UI

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Scala 100.0%