Module: RETerm

Defined in:
lib/reterm.rb,
lib/reterm/init.rb,
lib/reterm/menu.rb,
lib/reterm/panel.rb,
lib/reterm/layout.rb,
lib/reterm/loader.rb,
lib/reterm/resize.rb,
lib/reterm/window.rb,
lib/reterm/layouts.rb,
lib/reterm/version.rb,
lib/reterm/terminal.rb,
lib/reterm/component.rb,
lib/reterm/color_pair.rb,
lib/reterm/components.rb,
lib/reterm/components/dial.rb,
lib/reterm/components/entry.rb,
lib/reterm/components/image.rb,
lib/reterm/components/label.rb,
lib/reterm/components/radio.rb,
lib/reterm/components/slist.rb,
lib/reterm/layouts/vertical.rb,
lib/reterm/mixins/nav_input.rb,
lib/reterm/components/button.rb,
lib/reterm/components/dialog.rb,
lib/reterm/components/matrix.rb,
lib/reterm/components/rocker.rb,
lib/reterm/components/hslider.rb,
lib/reterm/components/vslider.rb,
lib/reterm/layouts/horizontal.rb,
lib/reterm/components/template.rb,
lib/reterm/mixins/cdk_component.rb,
lib/reterm/components/ascii_text.rb,
lib/reterm/mixins/component_input.rb,
lib/reterm/mixins/event_dispatcher.rb

Overview

The Ruby Enhanced Terminal interactive framework facilitating dynmaic/feature rich terminal applications.

Defined Under Namespace

Modules: CDKComponent, ComponentInput, Components, EventDispatcher, Layouts, NavInput Classes: ColorPair, Component, Layout, Loader, Menu, Panel, Terminal, Window

Constant Summary collapse

NC =

XXX Ncurses is exposed so that users may employ any constants if desired. This should not be needed though and is discouraged to maintain portability

Ncurses
RESIZE_TIME =

Seconds between terminal size syncs

0.2
VERSION =
"0.4.2"

Instance Method Summary collapse

Instance Method Details

#cdk_enabled?Boolean

Return boolean indicating if the CDK subsystem is enabled. CDK is a library used by various components providing many various ready to use ncurses widgets.

Returns:

  • (Boolean)


92
93
94
# File 'lib/reterm/init.rb', line 92

def cdk_enabled?
  !!@cdk_enabled
end

#enable_cdk!Object

Enable the CDK subsystem. Used by CDKbased components

See Also:



76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/reterm/init.rb', line 76

def enable_cdk!
  return if @cdk_enabled

  @cdk_enabled = true
  require 'cdk'

  # XXX defines standard color pairs, but we use our own
  # for standarization across components, but we need
  # to set cdk components to the correct color scheme
  # manually
  # CDK::Draw.initCDKColor
end

#init_reterm(opts = {}, &bl) ⇒ Object

Initializes the RETerm subsystem before invoking block. After block is finished regardless of execution state (return, exception, etc) this will cleanup the terminal environment before returning control to the TTY.

This method is the first method the user should invoke after requiring the reterm library.

Examples:

init_reterm {
  win = Window.new :rows => 20, :cols => 40
  # ... more UI logic
}


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/reterm/init.rb', line 19

def init_reterm(opts={}, &bl)
  begin
    Terminal.load # XXX: not sure why but loading terminal
                  #      info after changing terminal settings via
                  #      ncurses seems to corrupt the terminal
                  #      state to the point it cannot be restored
                  #      without a 'reset' (see below).
                  #      So just preload terminal info here.

    stdscr = Ncurses::initscr
    Ncurses::start_color
    Ncurses::noecho
    Ncurses::cbreak
    Ncurses::curs_set(0)
    Ncurses::keypad(stdscr, true)

    track_resize if opts[:resize]

    bl.call

  #ensure
    stop_track_resize
    Ncurses.curs_set(1)
    Window.all.each { |w| w.finalize! }
    CDK::SCREEN.endCDK if cdk_enabled?
    Ncurses.endwin()
    #`reset -Q` # XXX only way to guarantee a full reset (see above)
  end
end

#load_reterm(str) ⇒ Object

class Loader



123
124
125
# File 'lib/reterm/loader.rb', line 123

def load_reterm(str)
  Loader.new(str).window
end

#stop_track_resizeObject

Terminate resize tracking thread (if running)



23
24
25
26
# File 'lib/reterm/resize.rb', line 23

def stop_track_resize
  @track_resize = false
  @resize_thread.join if @resize_thread
end

#track_resizeObject

Internal helper to track size of terminal. This is a simple mechanism that launches a worker thread to periodically poll terminal size.



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/reterm/resize.rb', line 8

def track_resize
  @track_resize = true
  d = Terminal.dimensions

  @resize_thread = Thread.new {
    while @track_resize
      Terminal.reset!
      t = Terminal.dimensions
      Terminal.resize! if t != d
      sleep(RESIZE_TIME)
    end
  }
end

#update_retermObject

This method resyncs the visible terminal with the internal RETerm environment. It should be called any time the user needs to update the UI after making changes.

Examples:

init_reterm {
  win = Window.new
  win.border! # draw window border
  update_rti  # resync terminal ouput
  win.getch   # wait for input
}


61
62
63
64
65
# File 'lib/reterm/init.rb', line 61

def update_reterm
  Window.top.each { |w| w.refresh }
  Ncurses::Panel.update_panels
  Ncurses.doupdate
end