| 1 |
# ncurses_modeline.rb: the class definition of |
| 2 |
# Edmaru::Ncurses::NcursesModeLine |
| 3 |
# |
| 4 |
# Copyright (C) 2007 Takashi Nakamoto |
| 5 |
# |
| 6 |
# This program is free software; you can redistribute it and/or modify |
| 7 |
# it under the terms of the GNU General Public License version 2 as |
| 8 |
# published by the Free Software Foundation. |
| 9 |
# |
| 10 |
# This program is distributed in the hope that it will be useful, but |
| 11 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
# General Public License for more details. |
| 14 |
# |
| 15 |
# You should have received a copy of the GNU General Public License |
| 16 |
# along with this program; if not, write to the Free Software |
| 17 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 18 |
# 02110-1301 USA. |
| 19 |
# |
| 20 |
|
| 21 |
require "modeline.rb" |
| 22 |
|
| 23 |
module Edmaru::Ncurses |
| 24 |
class NcursesModeLine |
| 25 |
include Edmaru::ModeLine |
| 26 |
|
| 27 |
#Nothing to do. |
| 28 |
def init_ui |
| 29 |
end |
| 30 |
|
| 31 |
#Construct the modeline instance. |
| 32 |
#This method create a new Ncurses::Window. |
| 33 |
# |
| 34 |
#=== Arguments |
| 35 |
#_x_ :: The left edge position in the window's parent view. |
| 36 |
#_y_ :: The right edge position in the window's parent view. |
| 37 |
#_col_ :: The column size allocated for this modeline. |
| 38 |
def init_ncurses_modeline(x, y, col) |
| 39 |
@col = col |
| 40 |
@allocated_window = Ncurses::newwin(1, col, y, x) |
| 41 |
|
| 42 |
#Set the default color of this modeline. |
| 43 |
@allocated_window.wattron(Ncurses::COLOR_PAIR(NcursesColor::MODELINE_PAIR)) |
| 44 |
|
| 45 |
#Draw the modeline bar. (just fill it with space characters) |
| 46 |
@allocated_window.mvwaddstr(0, 0, " " * @col) |
| 47 |
@allocated_window.wrefresh |
| 48 |
end |
| 49 |
|
| 50 |
#Redraw thiw modeline. |
| 51 |
def refresh |
| 52 |
surface = "" |
| 53 |
|
| 54 |
@elements_order.each { |element_name| |
| 55 |
element = @elements[element_name] |
| 56 |
if element.visible? |
| 57 |
surface << element.surface |
| 58 |
|
| 59 |
#The length of the surface string is over the column size of |
| 60 |
#this modeline. |
| 61 |
if surface.size > @col |
| 62 |
break |
| 63 |
end |
| 64 |
end |
| 65 |
} |
| 66 |
|
| 67 |
if surface.size > @col |
| 68 |
surface = surface[0, @col] |
| 69 |
else |
| 70 |
surface << "-" * (@col - surface.size) |
| 71 |
end |
| 72 |
|
| 73 |
@allocated_window.mvwaddstr(0, 0, surface) |
| 74 |
@allocated_window.refresh |
| 75 |
end |
| 76 |
|
| 77 |
#Free allocated memory for this modeline. |
| 78 |
def terminate |
| 79 |
#Clear the window. |
| 80 |
@allocated_window.wattroff(Ncurses::COLOR_PAIR(NcursesColor::MODELINE_PAIR)) |
| 81 |
@allocated_window.mvwaddstr(0, 0, " " * @col) |
| 82 |
@allocated_window.refresh |
| 83 |
|
| 84 |
#Free |
| 85 |
@allocated_window.delwin |
| 86 |
end |
| 87 |
end |
| 88 |
end |