Class: RubyCurses::StatusLine

Inherits:
Widget show all
Defined in:
lib/rbcurse/core/widgets/statusline.rb

Overview

A vim-like application status bar that can display time and various other statuses

at the bottom, typically above the dock (3rd line from last).

Instance Attribute Summary

Attributes inherited from Widget

#_object_created, #col_offset, #cols_panned, #config, #curpos, #focussed, #form, #id, #key_label, #parent_component, #row_offset, #rows_panned, #state

Instance Method Summary collapse

Methods inherited from Widget

#action_manager, #changed, #click, #color_pair, #destroy, #enter, #event_list, #focus, #get_preferred_size, #getvalue, #getvalue_for_paint, #handle_key, #height, #height=, #hide, #init_vars, #leave, #modified?, #move, #on_enter, #on_leave, #override_graphic, #process_key, #remove, #repaint_all, #repaint_required, #rowcol, #set_buffer_modified, #set_buffering, #set_form, #set_form_col, #set_form_row, #set_modified, #setformrowcol, #setrowcol, #show, #text_variable, #unbind_key, #width, #width=

Methods included from Io

#__create_footer_window, #clear_this, #get_file, #print_this, #rb_getchar, #rb_gets, #rbgetstr, #warn

Methods included from Utils

#OLDdefine_key, #_process_key, #bind_key, #bind_keys, #clean_string!, #define_key, #define_prefix_command, #display_app_help, #get_attrib, #get_color, #keycode_tos, #last_line, #one_line_window, #parse_formatted_text, #print_key_bindings, #repeatm, #run_command, #shell_out, #shell_output, #suspend, #view, #wrap_text

Methods included from ConfigSetup

#cget, #config_setup, #configure, #variable_set

Methods included from EventHandler

#bind, #fire_handler, #fire_property_change

Constructor Details

#initialize(form, config = {}, &block) ⇒ StatusLine

attr_accessor :row_relative # lets only advertise this when we’ve tested it out



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rbcurse/core/widgets/statusline.rb', line 12

def initialize form, config={}, &block
  @row_relative = -3
  if form.window.height == 0
    @row = Ncurses.LINES-3 # fix, what about smaller windows, use window dimensions and watch out for 0,0
  else
    @row = form.window.height-3 # fix, what about smaller windows, use window dimensions and watch out for 0,0
  end
   # in root windows FIXME
  @col = 0
  @name = "sl"
  super
  # if negativ row passed we store as relative to bottom, so we can maintain that.
  if @row < 0
    @row_relative = @row
    @row = Ncurses.LINES - @row
  else
    @row_relative = (Ncurses.LINES - @row) * -1
  end
  @focusable = false
  @editable  = false
  @command = nil
  @repaint_required = true
  bind(:PROPERTY_CHANGE) {  |e| @color_pair = nil ; }
end

Instance Method Details

#command(*args, &blk) ⇒ Object Also known as: left

command that returns a string that populates the status line (left aligned) See dbdemo.rb e.g.

@l.command { "%-20s [DB: %-s | %-s ]" % [ Time.now, $current_db || "None", $current_table || "----"] }

See Also:

  • :right


43
44
45
46
# File 'lib/rbcurse/core/widgets/statusline.rb', line 43

def command *args, &blk
  @command = blk
  @args = args
end

#handle_keys(ch) ⇒ Object



105
106
107
# File 'lib/rbcurse/core/widgets/statusline.rb', line 105

def handle_keys ch
  return :UNHANDLED
end

#repaintObject

NOTE: I have not put a check of repaint_required, so this will print on each key-stroke OR

rather whenever form.repaint is called.


58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/rbcurse/core/widgets/statusline.rb', line 58

def repaint
  @color_pair ||= get_color($datacolor, @color, @bgcolor) 
  len = @form.window.getmaxx # width does not change upon resizing so useless, fix or do something
  len = Ncurses.COLS if len == 0 || len > Ncurses.COLS
  # this should only happen if there's a change in window
  if @row_relative
    @row = Ncurses.LINES+@row_relative
  end

  # first print dashes through
  @form.window.printstring @row, @col, "%s" % "-" * len, @color_pair, Ncurses::A_REVERSE

  # now call the block to get current values
  if @command
    ftext = @command.call(self, @args) 
  else
    status = $status_message ? $status_message.value : ""
    #ftext = " %-20s | %s" % [Time.now, status] # should we print a default value just in case user doesn't
    ftext = status # should we print a default value just in case user doesn't
  end
  if ftext =~ /#\[/
    @form.window.printstring_formatted @row, @col, ftext, $datacolor, Ncurses::A_REVERSE
  else
    @form.window.printstring @row, @col, ftext, $datacolor, Ncurses::A_REVERSE
  end
  # move this to formatted FIXME
  #@form.window.printstring_or_chunks @row, @col, ftext, $datacolor, Ncurses::A_REVERSE

  if @right_text
    ftext = @right_text.call(self, @right_args) 
    if ftext =~ /#\[/
      @form.window.printstring_formatted_right @row, nil, ftext, $datacolor, Ncurses::A_REVERSE
    else
      c = len - ftext.length
      @form.window.printstring @row, c, ftext, $datacolor, Ncurses::A_REVERSE
    end
  else
    t = Time.now
    tt = t.strftime "%F %H:%M:%S"
    r = Ncurses.LINES
    # 2013-03-20 - 19:04 next line printing as is in 187 ???? what to do
    ftext = "#[fg=green,bg=blue] %-20s" % [tt] # print a default
    @form.window.printstring_formatted_right @row, nil, ftext, $datacolor, Ncurses::A_REVERSE
  end

  @repaint_required = false
end

#right(*args, &blk) ⇒ Object

Procudure for text to be right aligned in statusline



51
52
53
54
# File 'lib/rbcurse/core/widgets/statusline.rb', line 51

def right *args, &blk
  @right_text = blk
  @right_args = args
end