Git Product home page Git Product logo

scurses's Introduction

Scurses / Onions

Build Status Maven Central Scurses Maven Central Onions MIT License

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.

Contents:


Onions

High-level Scurses framework for easy terminal UI

Maven Central Onions

Dependency:

libraryDependencies += "net.team2xh" %% "onions" % "<version in the badge>"

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

Example application

To see an example application showcasing all the widgets, run:

$ sbt onions/run

Make sure that your terminal is sized 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.). It works great through SSH as well!

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 regarding 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

Maven Central Scurses

Dependency:

libraryDependencies += "net.team2xh" %% "scurses" % "<version in the badge>"

screen shot 2015-11-12 at 11 07 32

Example applications

  • Hello World:
$ sbt "scurses/runMain net.team2xh.scurses.examples.HelloWorld"
  • Game of life:
$ sbt scurses/run
  • Stress test:
$ sbt "scurses/runMain 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()
}

scurses's People

Contributors

tenchi2xh avatar mdedetrich avatar valerii540 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.