Class: Canis::StatusLine
- Defined in:
- lib/canis/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), or else the last line.
Example
require 'canis/core/widgets/statusline'
@status_line = Canis::StatusLine.new @form, :row => Ncurses.LINES-2
@status_line.command {
"F1 Help | F2 Menu | F3 View | F4 Shell | F5 Sh | %20s" % [.text]
}
Changes
Earlier, the color of teh status line was REVERSED while printing which can be confusing
and surprising. We should use normal, or use whatever attribute the user gives.
Also, using the row as -3 is assuming that a dock is used, which may not be the case,
so -1 should be used.
Constant Summary collapse
- @@negative_offset =
2014-08-31 - 12:18 earlier -3
-1 # 2014-08-31 - 12:18 earlier -3 #attr_accessor :row_relative # lets only advertise this when we've tested it out
Instance Attribute Summary
Attributes inherited from Widget
#_object_created, #col_offset, #config, #curpos, #focussed, #form, #handler, #id, #key_label, #parent_component, #row_offset, #state
Instance Method Summary collapse
-
#command(*args, &blk) ⇒ Object
(also: #left)
command that returns a string that populates the status line (left aligned) == Example.
-
#handle_keys(ch) ⇒ Object
not used since not focusable.
-
#initialize(form, config = {}, &block) ⇒ StatusLine
constructor
attr_accessor :row_relative # lets only advertise this when we’ve tested it out.
-
#repaint ⇒ Object
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.
-
#right(*args, &blk) ⇒ Object
Procedure for text to be right aligned in statusline.
Methods inherited from Widget
#action_manager, #bgcolor, #color, #color_pair, #destroy, #focus, #focusable, #focusable?, #getvalue, #getvalue_for_paint, #handle_key, #hide, #init_vars, #modified?, #move, #on_enter, #on_leave, #override_graphic, #process_key, #property_set, #remove, #repaint_all, #repaint_required, #rowcol, #set_form, #set_form_col, #set_form_row, #set_modified, #setformrowcol, #setrowcol, #show, #unbind_key
Methods included from Io
#__create_footer_window, #clear_this, #get_file, #print_this, #rb_getchar, #rb_gets, #rb_getstr, #warn
Methods included from Utils
#ORIG_process_key, #ORIGbind_key, #ORIGkeycode_tos, #_process_key, #bind_composite_mapping, #bind_key, #bind_keys, #check_composite_mapping, #create_logger, #define_key, #define_prefix_command, #execute_mapping, #get_attrib, #get_color, #key, #key_tos, #print_key_bindings, #repeatm, #run_command, #shell_out, #shell_output, #suspend, #view, #xxxbind_composite_mapping
Methods included from ConfigSetup
Methods included from EventHandler
#bind, #event?, #event_list, #fire_handler, #fire_property_change, #register_events
Constructor Details
#initialize(form, config = {}, &block) ⇒ StatusLine
attr_accessor :row_relative # lets only advertise this when we’ve tested it out
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/canis/core/widgets/statusline.rb', line 27 def initialize form, config={}, &block @row_relative = @@negative_offset if form.window.height == 0 @row = Ncurses.LINES + @@negative_offset else @row = form.window.height + @@negative_offset 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)
Example
@l.command { "%-20s [DB: %-s | %-s ]" % [ Time.now, $current_db || "None", $current_table || "----"] }
59 60 61 62 |
# File 'lib/canis/core/widgets/statusline.rb', line 59 def command *args, &blk @command = blk @args = args end |
#handle_keys(ch) ⇒ Object
not used since not focusable
127 128 129 |
# File 'lib/canis/core/widgets/statusline.rb', line 127 def handle_keys ch return :UNHANDLED end |
#repaint ⇒ Object
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.
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 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/canis/core/widgets/statusline.rb', line 74 def repaint @color_pair ||= get_color($datacolor, @color, @bgcolor) # earlier attrib defaulted to REVERSE which was surprising. _attr = @attr || Ncurses::A_NORMAL 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, _attr # 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 # 2013-03-25 - 11:52 replaced $datacolor with @color_pair - how could this have been ? # what if user wants to change attrib ? if ftext =~ /#\[/ # hopefully color_pair does not clash with formatting @form.window.printstring_formatted @row, @col, ftext, @color_pair, _attr else @form.window.printstring @row, @col, ftext, @color_pair, _attr end if @right_text ftext = @right_text.call(self, @right_args) if ftext =~ /#\[/ # hopefully color_pair does not clash with formatting @form.window.printstring_formatted_right @row, nil, ftext, @color_pair, _attr else c = len - ftext.length @form.window.printstring @row, c, ftext, @color_pair, _attr end else t = Time.now tt = t.strftime "%F %H:%M:%S" #r = Ncurses.LINES # somehow the bg defined here affects the bg in left text, if left does not define # a bg. The bgcolor defined of statusline is ignored in left or overriden by this #ftext = "#[fg=white,bg=blue] %-20s#[/end]" % [tt] # print a default @form.window.printstring_formatted_right @row, nil, tt, @color_pair, _attr end @repaint_required = false end |
#right(*args, &blk) ⇒ Object
Procedure for text to be right aligned in statusline
67 68 69 70 |
# File 'lib/canis/core/widgets/statusline.rb', line 67 def right *args, &blk @right_text = blk @right_args = args end |