Class: VER::Window
Constant Summary collapse
- SPECIAL_KEYS =
2011-09-23 @since 1.3.1 Added more combinations here. These 2 are just indicative
{ [27, 79, 50, 81] => 20014, # 'F14', [27, 79, 50, 82] => 20015 # 'F15', }
Instance Attribute Summary collapse
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#layout ⇒ Object
hash containing hwtl.
-
#left ⇒ Object
readonly
Returns the value of attribute left.
-
#modified ⇒ Object
has it been modified and may need a refresh.
-
#name ⇒ Object
more for debugging log files.
-
#panel ⇒ Object
readonly
reader requires so he can del it in end.
-
#top ⇒ Object
readonly
Returns the value of attribute top.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
-
#window_type ⇒ Object
readonly
window or pad to distinguish 2009-11-02 23:11.
Class Method Summary collapse
-
.create_window(h = 0, w = 0, t = 0, l = 0) ⇒ Object
2009-10-13 12:24 not used as yet this is an alternative constructor created if you don’t want to create a hash first 2011-09-21 V1.3.1 You can now send an array to Window constructor.
-
.root_window(layout = { :height => 0, :width => 0, :top => 0, :left => 0 }) ⇒ Object
this is an alternative constructor.
Instance Method Summary collapse
- #_refresh ⇒ Object
-
#actual_height ⇒ Object
returns the actual ht in case you’ve used a root window which returns a 0 for wid and ht.
-
#actual_width ⇒ Object
returns the actual width in case you’ve used a root window which returns a 0 for wid and ht NOTE: this does not work when resize , use getmaxx instead.
- #attroff(*args) ⇒ Object
- #attron(*args) ⇒ Object
-
#clear ⇒ Object
doesn’t seem to work, clears first line, not both.
- #close_command(*args, &block) ⇒ Object (also: #command)
- #color=(color) ⇒ Object
- #color_parser(f) ⇒ Object
-
#confirm_close_command(*args, &block) ⇒ Object
set a single command to confirm whether window shoud close or not Block should return true or false for closing or not.
- #convert_to_chunk(s, colorp = $datacolor, att = FFI::NCurses::A_NORMAL) ⇒ Object
-
#default_for(name) ⇒ Object
this gives error since stdscr is only a pointer at this time.
-
#delwin ⇒ Object
2011-09-7.
-
#destroy ⇒ Object
destroy window, panel and any pads that were requested.
-
#fire_close_handler ⇒ Object
need a way of lettign user decide whether he wishes to close in which case we return false.
-
#get_pad(content_rows, content_cols) ⇒ Object
2011-11-13 since 1.4.1 Widgets can get window to create a pad for them.
-
#get_window ⇒ Object
This used to return an Ncurses window object, and you could call methods on it Now it returns a FFI::NCurses.window pointer which you cannot call methods on.
- #getch ⇒ Object
-
#getchar ⇒ Object
returns control, alt, alt+ctrl, alt+control+shift, F1 ..
-
#hide ⇒ Object
Ncurses panel.
- #highlight_line(color, y, x, max) ⇒ Object
- #init_vars ⇒ Object
-
#initialize(*args) ⇒ Window
constructor
or 2011-09-21 allowing array, or 4 ints, in addition to hash @since 1.3.1.
-
#layout_value(name) ⇒ Object
removed ref to default_for since giving error in FFI 2011-09-8.
- #method_missing(name, *args) ⇒ Object
-
#OLDmethod_missing(meth, *args) ⇒ Object
while moving from ncurses-ruby to FFI need to pass window pointer for w methods as well as mvw - NOT COMING HERE due to include FFI.
- #on_top ⇒ Object
-
#pos ⇒ Object
Ncurses.
-
#print(string, width = width) ⇒ Object
NOTE: many of these methods using width will not work since root windows width is 0.
-
#print_border(row, col, height, width, color, att = Ncurses::A_NORMAL) ⇒ Object
prints a border around a widget, CLEARING the area.
-
#print_border_mb(row, col, height, width, color, attr) ⇒ Object
NOTE : FOR MESSAGEBOXES ONLY !!!!.
- #print_border_only(row, col, height, width, color, att = Ncurses::A_NORMAL) ⇒ Object
-
#print_empty_line ⇒ Object
NOTE: many of these methods using width will not work since root windows width is 0.
-
#print_line(string) ⇒ Object
NOTE: many of these methods using width will not work since root windows width is 0.
-
#print_yx(string, y = 0, x = 0) ⇒ Object
NOTE: many of these methods using width will not work since root windows width is 0.
- #printstring(r, c, string, color, att = Ncurses::A_NORMAL) ⇒ Object
-
#printstring_formatted(r, c, content, color, att = Ncurses::A_NORMAL) ⇒ Object
prints a string formatted in our new experimental coloring format taken from tmux.
-
#printstring_formatted_right(r, c, content, color, att = Ncurses::A_NORMAL) ⇒ Object
print a formatted line right aligned c (col) is ignored and calculated based on width and unformatted string length.
-
#printstring_or_chunks(r, c, content, color, att = Ncurses::A_NORMAL) ⇒ Object
Allows user to send data as normal string or chunks for printing An array is assumed to be a chunk containing color and attrib info.
-
#prv_print_border_only(row, col, height, width, color, att = Ncurses::A_NORMAL) ⇒ Object
print just the border, no cleanup + Earlier, we would clean up.
-
#prv_printstring(r, c, string, color, att = Ncurses::A_NORMAL) ⇒ Object
name changed from printstring to prv_prinstring.
- #puts(*strings) ⇒ Object
-
#rb_mvaddch(row, col, char) ⇒ Object
use in place of mvaddch if your widget could be using a pad or window.
-
#rb_mvwhline(row, col, char, width) ⇒ Object
use in place of mvwhline if your widget could be using a pad or window.
-
#rb_mvwvline(row, col, char, width) ⇒ Object
use in place of mvwvline if your widget could be using a pad or window.
-
#reset_layout(layout) ⇒ Object
allow user to send an array I am tired of the hash layout (taken from ver).
-
#resize ⇒ Object
## END FFI.
- #resize_with(layout) ⇒ Object
- #respond_to?(name) ⇒ Boolean
- #show ⇒ Object
-
#show_colored_chunks(chunks, defcolor = nil, defattr = nil, wid = 999, pcol = 0) ⇒ Object
NOTE: many of these methods using width will not work since root windows width is 0 Previously this printed a chunk as a full line, I’ve modified it to print on one line.
- #to_s ⇒ Object
- #ungetch(ch) ⇒ Object
- #visible? ⇒ Boolean
-
#wmove(y, x) ⇒ Object
(also: #move)
end since include FFI is taking over, i need to force it here.
- #wnoutrefresh ⇒ Object
-
#wrefresh ⇒ Object
ADDED DUE TO FFI.
- #x ⇒ Object
- #x=(n) ⇒ Object
- #y ⇒ Object
- #y=(n) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Window
or 2011-09-21 allowing array, or 4 ints, in addition to hash @since 1.3.1
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/rbcurse/core/system/window.rb', line 44 def initialize(*args) case args.size when 1 case args[0] when Array, Hash layout = args[0] else raise ArgumentError, "Window expects 4 ints, array of 4 ints, or Hash in constructor" end when 4 layout = { :height => args[0], :width => args[1], :top => args[2], :left => args[3] } end @visible = true reset_layout(layout) #$log.debug "XXX:WINDOW got h #{@height}, w #{@width}, t #{@top}, l #{@left} " @height = FFI::NCurses.LINES if @height == 0 # 2011-11-14 added since tired of checking for zero @width = FFI::NCurses.COLS if @width == 0 @window = FFI::NCurses.newwin(@height, @width, @top, @left) # added FFI 2011-09-6 @panel = Ncurses::Panel.new(@window) # added FFI 2011-09-6 #$error_message_row = $status_message_row = Ncurses.LINES-1 $error_message_row ||= Ncurses.LINES-1 $error_message_col ||= 1 # ask (bottomline) uses 0 as default so you can have mismatch. XXX $status_message ||= RubyCurses::Variable.new # in case not an App $key_map ||= :vim $esc_esc = true; # gove me double esc as 2727 so i can map it. init_vars end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/rbcurse/core/system/window.rb', line 209 def method_missing(name, *args) name = name.to_s if (name[0,2] == "mv") test_name = name.dup test_name[2,0] = "w" # insert "w" after"mv" if (FFI::NCurses.respond_to?(test_name)) return FFI::NCurses.send(test_name, @window, *args) end end test_name = "w" + name if (FFI::NCurses.respond_to?(test_name)) return FFI::NCurses.send(test_name, @window, *args) end FFI::NCurses.send(name, @window, *args) end |
Instance Attribute Details
#height ⇒ Object (readonly)
Returns the value of attribute height.
33 34 35 |
# File 'lib/rbcurse/core/system/window.rb', line 33 def height @height end |
#layout ⇒ Object
hash containing hwtl
34 35 36 |
# File 'lib/rbcurse/core/system/window.rb', line 34 def layout @layout end |
#left ⇒ Object (readonly)
Returns the value of attribute left.
33 34 35 |
# File 'lib/rbcurse/core/system/window.rb', line 33 def left @left end |
#modified ⇒ Object
has it been modified and may need a refresh
38 39 40 |
# File 'lib/rbcurse/core/system/window.rb', line 38 def modified @modified end |
#name ⇒ Object
more for debugging log files. 2010-02-02 19:58
37 38 39 |
# File 'lib/rbcurse/core/system/window.rb', line 37 def name @name end |
#panel ⇒ Object (readonly)
reader requires so he can del it in end
35 36 37 |
# File 'lib/rbcurse/core/system/window.rb', line 35 def panel @panel end |
#top ⇒ Object (readonly)
Returns the value of attribute top.
33 34 35 |
# File 'lib/rbcurse/core/system/window.rb', line 33 def top @top end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
33 34 35 |
# File 'lib/rbcurse/core/system/window.rb', line 33 def width @width end |
#window_type ⇒ Object (readonly)
window or pad to distinguish 2009-11-02 23:11
36 37 38 |
# File 'lib/rbcurse/core/system/window.rb', line 36 def window_type @window_type end |
Class Method Details
.create_window(h = 0, w = 0, t = 0, l = 0) ⇒ Object
2009-10-13 12:24 not used as yet this is an alternative constructor created if you don’t want to create a hash first
2011-09-21 V1.3.1 You can now send an array to Window constructor
109 110 111 112 113 |
# File 'lib/rbcurse/core/system/window.rb', line 109 def self.create_window(h=0, w=0, t=0, l=0) layout = { :height => h, :width => w, :top => t, :left => l } @window = Window.new(layout) return @window end |
.root_window(layout = { :height => 0, :width => 0, :top => 0, :left => 0 }) ⇒ Object
this is an alternative constructor
95 96 97 98 99 100 101 102 103 |
# File 'lib/rbcurse/core/system/window.rb', line 95 def self.root_window(layout = { :height => 0, :width => 0, :top => 0, :left => 0 }) #VER::start_ncurses @layout = layout @window = Window.new(@layout) @window.name = "Window::ROOTW" @window.wrefresh Ncurses::Panel.update_panels return @window end |
Instance Method Details
#_refresh ⇒ Object
340 341 342 343 |
# File 'lib/rbcurse/core/system/window.rb', line 340 def _refresh return unless visible? @window.refresh end |
#actual_height ⇒ Object
returns the actual ht in case you’ve used a root window which returns a 0 for wid and ht
274 275 276 |
# File 'lib/rbcurse/core/system/window.rb', line 274 def actual_height height == 0? Ncurses.LINES : height end |
#actual_width ⇒ Object
returns the actual width in case you’ve used a root window which returns a 0 for wid and ht NOTE: this does not work when resize , use getmaxx instead
266 267 268 |
# File 'lib/rbcurse/core/system/window.rb', line 266 def actual_width width == 0? Ncurses.COLS : width end |
#attroff(*args) ⇒ Object
146 147 148 |
# File 'lib/rbcurse/core/system/window.rb', line 146 def attroff *args FFI::NCurses.wattroff @window, *args end |
#attron(*args) ⇒ Object
143 144 145 |
# File 'lib/rbcurse/core/system/window.rb', line 143 def attron *args FFI::NCurses.wattron @window, *args end |
#clear ⇒ Object
doesn’t seem to work, clears first line, not both
546 547 548 549 550 |
# File 'lib/rbcurse/core/system/window.rb', line 546 def clear # return unless visible? move 0, 0 puts *Array.new(height){ ' ' * (width - 1) } end |
#close_command(*args, &block) ⇒ Object Also known as: command
879 880 881 882 883 884 |
# File 'lib/rbcurse/core/system/window.rb', line 879 def close_command *args, &block @close_command ||= [] @close_args ||= [] @close_command << block @close_args << args end |
#color=(color) ⇒ Object
350 351 352 353 |
# File 'lib/rbcurse/core/system/window.rb', line 350 def color=(color) @color = color @window.color_set(color, nil) end |
#color_parser(f) ⇒ Object
719 720 721 722 723 724 725 726 |
# File 'lib/rbcurse/core/system/window.rb', line 719 def color_parser f $log.debug "XXX: color_parser setting in window to #{f} " if f == :tmux @color_parser = get_default_color_parser() else @color_parser = f end end |
#confirm_close_command(*args, &block) ⇒ Object
set a single command to confirm whether window shoud close or not Block should return true or false for closing or not
889 890 891 892 |
# File 'lib/rbcurse/core/system/window.rb', line 889 def confirm_close_command *args, &block @confirm_close_command = block @confirm_close_args = args end |
#convert_to_chunk(s, colorp = $datacolor, att = FFI::NCurses::A_NORMAL) ⇒ Object
735 736 737 738 739 740 741 |
# File 'lib/rbcurse/core/system/window.rb', line 735 def convert_to_chunk s, colorp=$datacolor, att=FFI::NCurses::A_NORMAL unless @color_parser @color_parser = get_default_color_parser() @converter = Chunks::ColorParser.new @color_parser end @converter.convert_to_chunk s, colorp, att end |
#default_for(name) ⇒ Object
this gives error since stdscr is only a pointer at this time
584 585 586 587 588 589 590 591 592 593 594 595 |
# File 'lib/rbcurse/core/system/window.rb', line 584 def default_for(name) case name when :height, :top #Ncurses.stdscr.getmaxy(stdscr) FFI::NCurses.LINES when :width, :left #Ncurses.stdscr.getmaxx(stdscr) FFI::NCurses.COLS else 0 end end |
#delwin ⇒ Object
2011-09-7
140 141 142 |
# File 'lib/rbcurse/core/system/window.rb', line 140 def delwin # 2011-09-7 Ncurses.delwin(@window) end |
#destroy ⇒ Object
destroy window, panel and any pads that were requested
627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 |
# File 'lib/rbcurse/core/system/window.rb', line 627 def destroy # typically the ensure block should have this #$log.debug "win destroy start" Ncurses::Panel.del_panel(@panel.pointer) if @panel delwin() if @window Ncurses::Panel.update_panels # added so below window does not need to do this 2011-10-1 # destroy any pads that were created by widgets using get_pad @pads.each { |pad| FFI::NCurses.delwin(pad) if pad pad = nil } if @pads #$log.debug "win destroy end" end |
#fire_close_handler ⇒ Object
need a way of lettign user decide whether he wishes to close in which case we return false. However, there could be several commands mapped. how do we know which is the one that has this authority
897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 |
# File 'lib/rbcurse/core/system/window.rb', line 897 def fire_close_handler if @confirm_close_command comm = @confirm_close_command ret = comm.call(self, *@confirm_close_args) return ret unless ret # only return if false returned end if @close_command @close_command.each_with_index do |comm, ix| comm.call(self, *@close_args[ix]) if comm end end @close_command = nil @close_args = nil return true end |
#get_pad(content_rows, content_cols) ⇒ Object
2011-11-13 since 1.4.1 Widgets can get window to create a pad for them. This way when the window
is destroyed, it will delete all the pads. A widget wold not be able to do this.
The destroy method of the widget will be called.
649 650 651 652 653 654 655 |
# File 'lib/rbcurse/core/system/window.rb', line 649 def get_pad content_rows, content_cols pad = FFI::NCurses.newpad(content_rows, content_cols) @pads ||= [] @pads << pad ## added 2013-03-05 - 19:21 without next line how was pad being returned return pad end |
#get_window ⇒ Object
This used to return an Ncurses window object, and you could call methods on it Now it returns a FFI::NCurses.window pointer which you cannot call methods on. You have to pass it to FFI::NCurses.<method>
865 |
# File 'lib/rbcurse/core/system/window.rb', line 865 def get_window; @window; end |
#getch ⇒ Object
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 |
# File 'lib/rbcurse/core/system/window.rb', line 363 def getch #c = @window.getch c = FFI::NCurses.wgetch(@window) # the only reason i am doing this is so ESC can be returned if no key is pressed # after that, not sure how this effects everything. most likely I should just # go back to using a wtimeout, and not worry about resize requiring a keystroke if c == 27 Ncurses::wtimeout(@window, $ncurses_timeout || 500) # will wait a second on wgetch so we can get gg and qq else Ncurses::nowtimeout(@window, true) end c # 2011-12-20 - i am trying setting a timer on wgetch, see timeout #c = FFI::NCurses.getch # this will keep waiting, nodelay won't be used on it, since # we've put nodelay on window #if c == Ncurses::KEY_RESIZE rescue SystemExit, Interrupt #FFI::NCurses.flushinp 3 # is C-c rescue StandardError -1 # is C-c end |
#getchar ⇒ Object
returns control, alt, alt+ctrl, alt+control+shift, F1 .. etc ALT combinations also send a 27 before the actual key Please test with above combinations before using on your terminal added by rkumar 2008-12-12 23:07
2011-09-23 Redone Control-left, right, and Shift-F5..F10.
Checking for quick press of Alt-Sh-O followed by Alt or printable char
Checking for quick press of Alt-[ followed by Alt or printable char
I attempted keeping a hash of combination arrays but it fails in the above
2 cases, so abandoned.
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 |
# File 'lib/rbcurse/core/system/window.rb', line 403 def getchar while 1 ch = self.getch #$log.debug "window getchar() GOT: #{ch}" if ch != -1 sf = @stack.first if ch == -1 # the returns escape 27 if no key followed it, so its SLOW if you want only esc if @stack.first == 27 #$log.debug " -1 stack sizze #{@stack.size}: #{@stack.inspect}, ch #{ch}" case @stack.size when 1 @stack.clear return 27 when 2 # basically a ALT-O, or alt-[ (79 or 91) this will be really slow since it waits for -1 ch = 128 + @stack.last $log.warn "XXX: WARN #{ch} CLEARING stack #{@stack} " @stack.clear return ch else # check up a hash of special keys ret = SPECIAL_KEYS(@stack) return ret if ret $log.warn "INVALID UNKNOWN KEY: SHOULD NOT COME HERE getchar():#{@stack}" end end # possibly a 49 left over from M3-1 unless @stack.empty? if @stack.size == 1 @stack.clear return sf end $log.warn "something on stack getchar(): #{@stack} " end # comemnt after testing keys since this will be called a lot, even stack.clear is called a lot $log.warn "ERROR CLEARING STACK WITH STUFF ON IT getchar():#{@stack}" if ($log.debug? && !@stack.empty?) @stack.clear next end # -1 # this is the ALT combination if @stack.first == 27 # experimental. 2 escapes in quick succession to make exit faster if @stack.size == 1 && ch == 27 @stack.clear return 2727 if $esc_esc # this is double-esc if you wanna trap it, trying out return 27 end # possible F1..F3 on xterm-color if ch == 79 || ch == 91 #$log.debug " got 27, #{ch}, waiting for one more" @stack << ch next end #$log.debug "stack SIZE #{@stack.size}, #{@stack.inspect}, ch: #{ch}" if @stack == [27,79] # xterm-color case ch when 80 ch = FFI::NCurses::KEY_F1 when 81 ch = FFI::NCurses::KEY_F2 when 82 ch = FFI::NCurses::KEY_F3 when 83 ch = FFI::NCurses::KEY_F4 #when 27 # another alt-char following Alt-Sh-O else ## iterm2 uses these for HOME END num keyboard keys @stack.clear #@stack << ch # earlier we pushed this but it could be of use #return 128 + 79 return 128 + 79 + ch end @stack.clear return ch elsif @stack == [27, 91] # XXX 27, 91 also is Alt-[ if ch == 90 @stack.clear return KEY_BTAB # backtab elsif ch == 53 || ch == 50 || ch == 51 # control left, right and shift function @stack << ch next elsif ch == 27 # another alt-char immediately after Alt-[ $log.debug "getchar in 27, will return 128+91 " if $log.debug? @stack.clear @stack << ch return 128 + 91 else $log.debug "getchar in other, will return 128+91: #{ch} " if $log.debug? # other cases Alt-[ followed by some char or key - merge with previous @stack.clear @stack << ch return 128 + 91 end elsif @stack == [27, 91, 53] if ch == 68 @stack.clear return C_LEFT # control-left elsif ch == 67 @stack.clear return C_RIGHT # -control-rt end elsif @stack == [27, 91, 51] if ch == 49 && getch()== 126 @stack.clear return 20009 # sh_f9 end elsif @stack == [27, 91, 50] if ch == 50 && getch()== 126 @stack.clear return 20010 # sh-F10 end if ch == 57 && getch()== 126 @stack.clear return 20008 # sh-F8 elsif ch == 56 && getch()== 126 @stack.clear return 20007 # sh-F7 elsif ch == 54 && getch()== 126 @stack.clear return 20006 # sh-F6 elsif ch == 53 && getch()== 126 @stack.clear return 20005 # sh-F5 end end # the usual Meta combos. (alt) - this is screwing it up, just return it in some way ch = 128 + ch @stack.clear return ch end # stack.first == 27 # append a 27 to stack, actually one can use a flag too if ch == 27 @stack << 27 next end return ch end # while end |
#hide ⇒ Object
Ncurses panel
599 600 601 602 603 604 605 |
# File 'lib/rbcurse/core/system/window.rb', line 599 def hide #return unless visible? # added 2011-10-14 these 2 are not behaving properly Ncurses::Panel.hide_panel @panel.pointer #Ncurses.refresh # wnoutrefresh Ncurses::Panel.update_panels # added so below window does not need to do this 2011-10-1 @visible = false end |
#highlight_line(color, y, x, max) ⇒ Object
355 356 357 |
# File 'lib/rbcurse/core/system/window.rb', line 355 def highlight_line(color, y, x, max) @window.mvchgat(y, x, max, Ncurses::A_NORMAL, color, nil) end |
#init_vars ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/rbcurse/core/system/window.rb', line 79 def init_vars @window_type = :WINDOW Ncurses::keypad(@window, true) # Added this so we can get Esc, and also C-c pressed in succession does not crash system # 2011-12-20 half-delay crashes system as does cbreak #This causes us to be unable to process gg qq since getch won't wait. #Ncurses::nodelay(@window, bf = true) # wtimeout was causing RESIZE sigwinch to only happen after pressing a key #Ncurses::wtimeout(@window, $ncurses_timeout || 500) # will wait a second on wgetch so we can get gg and qq @stack = [] @name ||="#{self}" @modified = true $catch_alt_digits ||= false # is this where is should put globals ? 2010-03-14 14:00 XXX end |
#layout_value(name) ⇒ Object
removed ref to default_for since giving error in FFI 2011-09-8
575 576 577 578 579 580 581 |
# File 'lib/rbcurse/core/system/window.rb', line 575 def layout_value(name) value = @layout[name] default = default_for(name) value = value.call(default) if value.respond_to?(:call) return (value || default).to_i end |
#OLDmethod_missing(meth, *args) ⇒ Object
while moving from ncurses-ruby to FFI need to pass window pointer for w methods as well as mvw - NOT COMING HERE due to include FFI
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/rbcurse/core/system/window.rb', line 190 def OLDmethod_missing(meth, *args) $log.debug " WWWW method missing #{meth} " if meth[0,1]=="w" || meth[0,3] == "mvw" $log.debug " WWWW method missing #{meth} adding window in call " #return @window.send(meth, @window, *args) return FFI::NCurses.send(meth, @window, *args) else end if @window if @window.respond_to? meth @window.send(meth, *args) else FFI::NCurses.send( meth, *args) end else FFI::NCurses.send( meth, *args) end end |
#on_top ⇒ Object
615 616 617 618 |
# File 'lib/rbcurse/core/system/window.rb', line 615 def on_top Ncurses::Panel.top_panel @panel.pointer wnoutrefresh end |
#pos ⇒ Object
Ncurses
158 159 160 |
# File 'lib/rbcurse/core/system/window.rb', line 158 def pos return y, x end |
#print(string, width = width) ⇒ Object
NOTE: many of these methods using width will not work since root windows width
is 0
234 235 236 237 238 |
# File 'lib/rbcurse/core/system/window.rb', line 234 def print(string, width = width) return unless visible? w = width == 0? Ncurses.COLS : width waddnstr(string.to_s, w) # changed 2011 dts end |
#print_border(row, col, height, width, color, att = Ncurses::A_NORMAL) ⇒ Object
prints a border around a widget, CLEARING the area.
If calling with a pad, you would typically use 0,0, h-1, w-1.
819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 |
# File 'lib/rbcurse/core/system/window.rb', line 819 def print_border row, col, height, width, color, att=Ncurses::A_NORMAL raise "height needs to be supplied." if height.nil? raise "width needs to be supplied." if width.nil? att ||= Ncurses::A_NORMAL #$log.debug " inside window print_border r #{row} c #{col} h #{height} w #{width} " # 2009-11-02 00:45 made att nil for blanking out # FIXME - in tabbedpanes this clears one previous line ??? XXX when using a textarea/view # when using a pad this calls pads printstring which again reduces top and left !!! 2010-01-26 23:53 ww=width-2 (row+1).upto(row+height-1) do |r| prv_printstring( r, col+1," "*ww , color, att) end prv_print_border_only row, col, height, width, color, att end |
#print_border_mb(row, col, height, width, color, attr) ⇒ Object
NOTE : FOR MESSAGEBOXES ONLY !!!!
791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 |
# File 'lib/rbcurse/core/system/window.rb', line 791 def print_border_mb row, col, height, width, color, attr # the next is for xterm-256 att = get_attrib attr len = width len = Ncurses.COLS-0 if len == 0 # print a bar across the screen #attron(Ncurses.COLOR_PAIR(color) | att) # this works for newmessagebox but not for old one. # Even now in some cases some black shows through, if the widget is printing spaces # such as field or textview on a messagebox. (row-1).upto(row+height-1) do |r| mvwhline(r, col, 1, len) end #attroff(Ncurses.COLOR_PAIR(color) | att) mvwaddch row, col, Ncurses::ACS_ULCORNER mvwhline( row, col+1, Ncurses::ACS_HLINE, width-6) mvwaddch row, col+width-5, Ncurses::ACS_URCORNER mvwvline( row+1, col, Ncurses::ACS_VLINE, height-4) mvwaddch row+height-3, col, Ncurses::ACS_LLCORNER mvwhline(row+height-3, col+1, Ncurses::ACS_HLINE, width-6) mvwaddch row+height-3, col+width-5, Ncurses::ACS_LRCORNER mvwvline( row+1, col+width-5, Ncurses::ACS_VLINE, height-4) end |
#print_border_only(row, col, height, width, color, att = Ncurses::A_NORMAL) ⇒ Object
835 836 837 |
# File 'lib/rbcurse/core/system/window.rb', line 835 def print_border_only row, col, height, width, color, att=Ncurses::A_NORMAL prv_print_border_only row, col, height, width, color, att end |
#print_empty_line ⇒ Object
NOTE: many of these methods using width will not work since root windows width
is 0
249 250 251 252 253 |
# File 'lib/rbcurse/core/system/window.rb', line 249 def print_empty_line return unless visible? w = getmaxx == 0? Ncurses.COLS : getmaxx printw(' ' * w) end |
#print_line(string) ⇒ Object
NOTE: many of these methods using width will not work since root windows width
is 0
257 258 259 260 |
# File 'lib/rbcurse/core/system/window.rb', line 257 def print_line(string) w = getmaxx == 0? Ncurses.COLS : getmaxx print(string.ljust(w)) end |
#print_yx(string, y = 0, x = 0) ⇒ Object
NOTE: many of these methods using width will not work since root windows width
is 0
242 243 244 245 |
# File 'lib/rbcurse/core/system/window.rb', line 242 def print_yx(string, y = 0, x = 0) w = width == 0? Ncurses.COLS : width mvwaddnstr(y, x, string, w) # changed 2011 dts end |
#printstring(r, c, string, color, att = Ncurses::A_NORMAL) ⇒ Object
754 755 756 757 758 |
# File 'lib/rbcurse/core/system/window.rb', line 754 def printstring(r,c,string, color, att = Ncurses::A_NORMAL) raise "Nil passed to peintstring row:#{r}, col:#{c}, #{color} " if r.nil? || c.nil? || color.nil? #raise "Zero or less passed to printstring row:#{r}, col:#{c} " if $log.debug? && (r <=0 || c <=0) prv_printstring(r,c,string, color, att ) end |
#printstring_formatted(r, c, content, color, att = Ncurses::A_NORMAL) ⇒ Object
prints a string formatted in our new experimental coloring format taken from tmux. Currently, since i have chunks workings, i convert to chunks and use the existing print function. This could change. An example of a formatted string is: s=“#testing chunks #[fg=yellow, bg=red, bold]yellow #[reverse] reverseme \
#[normal]normal#[bg = black]just yellow#[fg=blue],blue now #[underline] underlined text"
Ideally I should push and pop colors which the shell does not do with ansi terminal sequences. That way i can have a line in red,
with some word in yellow, and then the line continues in red.
696 697 698 699 700 |
# File 'lib/rbcurse/core/system/window.rb', line 696 def printstring_formatted(r,c,content, color, att = Ncurses::A_NORMAL) att = get_attrib att unless att.is_a? Fixnum chunkline = convert_to_chunk(content, color, att) printstring_or_chunks r,c, chunkline, color, att end |
#printstring_formatted_right(r, c, content, color, att = Ncurses::A_NORMAL) ⇒ Object
print a formatted line right aligned c (col) is ignored and calculated based on width and unformatted string length
705 706 707 708 709 710 |
# File 'lib/rbcurse/core/system/window.rb', line 705 def printstring_formatted_right(r,c,content, color, att = Ncurses::A_NORMAL) clean = content.gsub /#\[[^\]]*\]/,'' # clean out all markup #c = actual_width() - clean.length # actual width not working if resize c = getmaxx() - clean.length printstring_formatted(r,c,content, color, att ) end |
#printstring_or_chunks(r, c, content, color, att = Ncurses::A_NORMAL) ⇒ Object
Allows user to send data as normal string or chunks for printing An array is assumed to be a chunk containing color and attrib info
661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 |
# File 'lib/rbcurse/core/system/window.rb', line 661 def printstring_or_chunks(r,c,content, color, att = Ncurses::A_NORMAL) if content.is_a? String printstring(r,c,content, color, att) elsif content.is_a? Chunks::ChunkLine #$log.debug "XXX: using chunkline" # 2011-12-10 12:40:13 wmove r, c a = get_attrib att # please add width to avoid overflow show_colored_chunks content, color, a elsif content.is_a? Array # several chunks in one row - NOTE Very experimental may change if content[0].is_a? Array $log.warn "XXX: WARNING outdated should send in a chunkline" wmove r, c a = get_attrib att # please add width to avoid overflow show_colored_chunks content, color, a else # a single row chunk - NOTE Very experimental may change text = content[1].dup printstring r, c, text, content[0] || color, content[2] || att end end end |
#prv_print_border_only(row, col, height, width, color, att = Ncurses::A_NORMAL) ⇒ Object
print just the border, no cleanup + Earlier, we would clean up. Now in some cases, i’d like + to print border over what’s been done. XXX this reduces 1 from width but not height !!! FIXME
844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 |
# File 'lib/rbcurse/core/system/window.rb', line 844 def prv_print_border_only row, col, height, width, color, att=Ncurses::A_NORMAL if att.nil? att = Ncurses::A_NORMAL else att = get_attrib att end wattron(Ncurses.COLOR_PAIR(color) | att) mvwaddch row, col, Ncurses::ACS_ULCORNER mvwhline( row, col+1, Ncurses::ACS_HLINE, width-2) mvwaddch row, col+width-1, Ncurses::ACS_URCORNER mvwvline( row+1, col, Ncurses::ACS_VLINE, height-1) mvwaddch row+height-0, col, Ncurses::ACS_LLCORNER mvwhline(row+height-0, col+1, Ncurses::ACS_HLINE, width-2) mvwaddch row+height-0, col+width-1, Ncurses::ACS_LRCORNER mvwvline( row+1, col+width-1, Ncurses::ACS_VLINE, height-1) wattroff(Ncurses.COLOR_PAIR(color) | att) end |
#prv_printstring(r, c, string, color, att = Ncurses::A_NORMAL) ⇒ Object
name changed from printstring to prv_prinstring
761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 |
# File 'lib/rbcurse/core/system/window.rb', line 761 def prv_printstring(r,c,string, color, att = Ncurses::A_NORMAL) #$log.debug " #{@name} inside window printstring r #{r} c #{c} #{string} " if att.nil? att = Ncurses::A_NORMAL else att = get_attrib att end #att = att.downcase.to_sym if att.is_a? String #case att #when :normal #att = Ncurses::A_NORMAL #when :underline #att = Ncurses::A_UNDERLINE #when :bold #att = Ncurses::A_BOLD #when :reverse #att = Ncurses::A_REVERSE #when :dim #att = Ncurses::A_DIM #when :blink #att = Ncurses::A_BLINK # unlikely to work #end wattron(Ncurses.COLOR_PAIR(color) | att) mvwprintw(r, c, "%s", :string, string); wattroff(Ncurses.COLOR_PAIR(color) | att) end |
#puts(*strings) ⇒ Object
336 337 338 |
# File 'lib/rbcurse/core/system/window.rb', line 336 def puts(*strings) print(strings.join("\n") << "\n") end |
#rb_mvaddch(row, col, char) ⇒ Object
use in place of mvaddch if your widget could be using a pad or window
876 877 878 |
# File 'lib/rbcurse/core/system/window.rb', line 876 def rb_mvaddch row, col, char mvaddch row, col, char end |
#rb_mvwhline(row, col, char, width) ⇒ Object
use in place of mvwhline if your widget could be using a pad or window
868 869 870 |
# File 'lib/rbcurse/core/system/window.rb', line 868 def rb_mvwhline row, col, char, width mvwhline row, col, char, width end |
#rb_mvwvline(row, col, char, width) ⇒ Object
use in place of mvwvline if your widget could be using a pad or window
872 873 874 |
# File 'lib/rbcurse/core/system/window.rb', line 872 def rb_mvwvline row, col, char, width mvwvline row, col, char, width end |
#reset_layout(layout) ⇒ Object
allow user to send an array I am tired of the hash layout (taken from ver).
556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 |
# File 'lib/rbcurse/core/system/window.rb', line 556 def reset_layout(layout) case layout when Array $log.error "NIL in window constructor" if layout.include? nil raise ArgumentError, "Nil in window constructor" if layout.include? nil @height, @width, @top, @left = *layout raise ArgumentError, "Nil in window constructor" if @top.nil? || @left.nil? @layout = { :height => @height, :width => @width, :top => @top, :left => @top } when Hash @layout = layout [:height, :width, :top, :left].each do |name| instance_variable_set("@#{name}", layout_value(name)) end end end |
#resize ⇒ Object
## END FFI
152 153 154 |
# File 'lib/rbcurse/core/system/window.rb', line 152 def resize resize_with(@layout) end |
#resize_with(layout) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/rbcurse/core/system/window.rb', line 115 def resize_with(layout) $log.debug " DARN ! This awready duz a resize!! if h or w or even top or left changed!!! XXX" reset_layout(layout) #@window.wresize(height, width) wresize(height, width) #FFI::NCurses.wresize(@window,height, width) # this is dicey since we often change top and left in pads only for panning !! XXX #@window.mvwin(top, left) mvwin(top, left) #FFI::NCurses.mvwin(@window, top, left) end |
#respond_to?(name) ⇒ Boolean
224 225 226 227 228 229 230 |
# File 'lib/rbcurse/core/system/window.rb', line 224 def respond_to?(name) name = name.to_s if (name[0,2] == "mv" && FFI::NCurses.respond_to?("mvw" + name[2..-1])) return true end FFI::NCurses.respond_to?("w" + name) || FFI::NCurses.respond_to?(name) end |
#show ⇒ Object
607 608 609 610 611 612 613 |
# File 'lib/rbcurse/core/system/window.rb', line 607 def show #return if visible? # added 2011-10-14 these 2 are not behaving properly Ncurses::Panel.show_panel @panel.pointer #Ncurses.refresh # wnoutrefresh Ncurses::Panel.update_panels # added so below window does not need to do this 2011-10-1 @visible = true end |
#show_colored_chunks(chunks, defcolor = nil, defattr = nil, wid = 999, pcol = 0) ⇒ Object
NOTE: many of these methods using width will not work since root windows width
is 0
Previously this printed a chunk as a full line, I've modified it to print on
one line. This can be used for running text.
NOTE 2013-03-08 - 17:02 added width so we don't overflow
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 |
# File 'lib/rbcurse/core/system/window.rb', line 283 def show_colored_chunks(chunks, defcolor = nil, defattr = nil, wid = 999, pcol = 0) return unless visible? ww = 0 chunks.each do |chunk| #|color, chunk, attrib| case chunk when Chunks::Chunk color = chunk.color attrib = chunk.attrib text = chunk.text ## 2013-03-08 - 19:11 take care of scrolling by means of pcol if pcol > 0 if pcol > text.length # ignore entire chunk and reduce pcol pcol -= text.length next else # print portion of chunk and zero pcol text = text[pcol..-1] pcol = 0 end end oldw = ww ww += text.length if ww > wid # if we are exceeding the width then by howmuch rem = wid - oldw if rem > 0 # take only as much as we are allowed text = text[0,rem] else break end end when Array # for earlier demos that used an array color = chunk[0] attrib = chunk[2] text = chunk[1] end color ||= defcolor attrib ||= defattr cc, bg = ColorMap.get_colors_for_pair color #$log.debug "XXX: CHUNK window #{text}, cp #{color} , attrib #{attrib}. #{cc}, #{bg} " color_set(color,nil) if color wattron(attrib) if attrib print(text) wattroff(attrib) if attrib end end |
#to_s ⇒ Object
866 |
# File 'lib/rbcurse/core/system/window.rb', line 866 def to_s; @name || self; end |
#ungetch(ch) ⇒ Object
359 360 361 |
# File 'lib/rbcurse/core/system/window.rb', line 359 def ungetch(ch) Ncurses.ungetch(ch) end |
#visible? ⇒ Boolean
620 621 622 |
# File 'lib/rbcurse/core/system/window.rb', line 620 def visible? @visible end |
#wmove(y, x) ⇒ Object Also known as: move
end since include FFI is taking over, i need to force it here. not going into method_missing
182 183 184 185 |
# File 'lib/rbcurse/core/system/window.rb', line 182 def wmove y,x #Ncurses.wmove @window, y, x FFI::NCurses.wmove @window, y, x end |
#wnoutrefresh ⇒ Object
345 346 347 348 |
# File 'lib/rbcurse/core/system/window.rb', line 345 def wnoutrefresh return unless visible? @window.wnoutrefresh end |
#wrefresh ⇒ Object
ADDED DUE TO FFI
137 138 139 |
# File 'lib/rbcurse/core/system/window.rb', line 137 def wrefresh Ncurses.wrefresh(@window) end |
#x ⇒ Object
166 167 168 |
# File 'lib/rbcurse/core/system/window.rb', line 166 def x Ncurses.getcurx(@window) end |
#x=(n) ⇒ Object
170 |
# File 'lib/rbcurse/core/system/window.rb', line 170 def x=(n) move(y, n) end |
#y ⇒ Object
162 163 164 |
# File 'lib/rbcurse/core/system/window.rb', line 162 def y Ncurses.getcury(@window) end |
#y=(n) ⇒ Object
171 |
# File 'lib/rbcurse/core/system/window.rb', line 171 def y=(n) move(n, x) end |