Class: Textbringer::EchoArea

Inherits:
Window
  • Object
show all
Defined in:
lib/textbringer/window.rb,
sig/lib/textbringer/window.rbs

Constant Summary

Constants inherited from Window

Window::ALT_ALPHA_BASE, Window::ALT_NUMBER_BASE, Window::FALLBACK_CHARACTERS, Window::HAVE_GET_KEY_MODIFIERS, Window::KEY_NAMES

Instance Attribute Summary collapse

Attributes inherited from Window

#bottom_of_window, #buffer, #columns, #cursor, #lines, #mode_line, #top_of_window, #window, #x, #y

Instance Method Summary collapse

Methods inherited from Window

beep, #beginning_of_line_and_count, #calc_tab_width, #close, colors, columns, #compose_character, #compose_hangul_character, current, current=, #current?, #current_or_minibuffer_selected?, #delete, #delete_marks, delete_other_windows, delete_window, #deleted?, echo_area, #enlarge, #get_char, has_colors=, has_colors?, #has_input?, #highlight, #isearch_attr, lines, list, load_faces, minibuffer_selected, minibuffer_selected=, other_window, #read_event, #read_event_nonblock, #recenter, #recenter_if_needed, redisplay, #redisplay_mode_line, redraw, #region_attr, resize, #restore_point, #save_point, #scroll_down, #scroll_up, set_default_colors, #shrink, #shrink_if_larger_than_buffer, #split, start, #unicode_codepoint, update, #update_cursor_and_attr, #wait_input

Constructor Details

#initialize(*args) ⇒ EchoArea

Returns a new instance of EchoArea.

Parameters:

  • (Integer)


1021
1022
1023
1024
1025
1026
# File 'lib/textbringer/window.rb', line 1021

def initialize(*args)
  super
  @message = nil
  @prompt = ""
  @active = false
end

Instance Attribute Details

#active=(value) ⇒ Object (writeonly)

Sets the attribute active

Parameters:

  • value

    the value to set the attribute active to.



1019
1020
1021
# File 'lib/textbringer/window.rb', line 1019

def active=(value)
  @active = value
end

#messageObject (readonly)

Returns the value of attribute message.



1017
1018
1019
# File 'lib/textbringer/window.rb', line 1017

def message
  @message
end

#promptObject

Returns the value of attribute prompt.



1018
1019
1020
# File 'lib/textbringer/window.rb', line 1018

def prompt
  @prompt
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


1032
1033
1034
# File 'lib/textbringer/window.rb', line 1032

def active?
  @active
end

#clearString

Returns:

  • (String)


1036
1037
1038
1039
1040
1041
# File 'lib/textbringer/window.rb', line 1036

def clear
  @buffer.clear
  @top_of_window.location = @buffer.point_min
  @message = nil
  @prompt = ""
end

#clear_messagenil

Returns:

  • (nil)


1043
1044
1045
# File 'lib/textbringer/window.rb', line 1043

def clear_message
  @message = nil
end

#echo_area?Boolean

Returns:

  • (Boolean)


1028
1029
1030
# File 'lib/textbringer/window.rb', line 1028

def echo_area?
  true
end

#editable_columnsInteger

Returns:

  • (Integer)


1116
1117
1118
1119
1120
1121
1122
# File 'lib/textbringer/window.rb', line 1116

def editable_columns
  if @buffer.input_method_status == "--"
    @columns
  else
    @columns - Buffer.display_width(@buffer.input_method_status) - 1
  end
end

#escape(s) ⇒ String

Parameters:

  • (String)

Returns:

  • (String)


1130
1131
1132
# File 'lib/textbringer/window.rb', line 1130

def escape(s)
  super(s).gsub(/\t/, "^I")
end

#framerInteger

Returns:

  • (Integer)


1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
# File 'lib/textbringer/window.rb', line 1134

def framer
  @buffer.save_point do |saved|
    max_width = editable_columns - @window.curx
    width = 0
    loop do
      c = @buffer.char_after
      if c.nil?
        width += 1
      else
        width += Buffer.display_width(escape(c))
      end
      if width > max_width
        @buffer.forward_char
        break
      elsif width == max_width || @buffer.beginning_of_line? ||
          @buffer.point_at_mark?(@top_of_window)
        break
      end
      @buffer.backward_char
    end
    @top_of_window.location = @buffer.point
  end
end

#initialize_window(num_lines, num_columns, y, x) ⇒ void

This method returns an undefined value.

Parameters:

  • (Integer)
  • (Integer)
  • (Integer)
  • (Integer)


1126
1127
1128
# File 'lib/textbringer/window.rb', line 1126

def initialize_window(num_lines, num_columns, y, x)
  @window = Curses::Window.new(num_lines, num_columns, y, x)
end

#move(y, x) ⇒ Integer

Parameters:

  • (Integer)
  • (Integer)

Returns:

  • (Integer)


1104
1105
1106
1107
1108
# File 'lib/textbringer/window.rb', line 1104

def move(y, x)
  @y = y
  @x = x
  @window.move(y, x)
end

#redisplaynil

Returns:

  • (nil)


1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
# File 'lib/textbringer/window.rb', line 1051

def redisplay
  return if @buffer.nil?
  @buffer.save_point do |point|
    @window.erase
    if @buffer.input_method_status != "--"
      @window.setpos(@window.cury, editable_columns + 1)
      @window.addstr(@buffer.input_method_status)
    end
    @window.setpos(0, 0)
    @window.attrset(0)
    @in_region = false
    @in_isearch = false
    @current_highlight_attrs = 0
    if @message
      @window.addstr(escape(@message))
    else
      prompt = escape(@prompt)
      @window.addstr(prompt)
      framer
      @buffer.point_to_mark(@top_of_window)
      @cursor.y = @cursor.x = 0
      while !@buffer.end_of_buffer?
        cury = @window.cury
        curx = @window.curx
        update_cursor_and_attr(point, cury, curx)
        c = @buffer.char_after
        if c == "\n"
          break
        end
        c = compose_character(point, cury, curx, c)
        s = escape(c)
        newx = curx + Buffer.display_width(s)
        if newx > editable_columns
          break
        end
        @window.addstr(s)
        @buffer.forward_char
        break if newx >= editable_columns
      end
      if @buffer.point_at_mark?(point)
        @cursor.y = @window.cury
        @cursor.x = @window.curx
      end
      @window.setpos(@cursor.y, @cursor.x)
    end
    @window.noutrefresh
  end
end

#redrawnil

Returns:

  • (nil)


1100
1101
1102
# File 'lib/textbringer/window.rb', line 1100

def redraw
  @window.redraw
end

#resize(lines, columns) ⇒ Integer

Parameters:

  • (Integer)
  • (Integer)

Returns:

  • (Integer)


1110
1111
1112
1113
1114
# File 'lib/textbringer/window.rb', line 1110

def resize(lines, columns)
  @lines = lines
  @columns = columns
  @window.resize(lines, columns)
end

#show(message) ⇒ String

Parameters:

  • (String)

Returns:

  • (String)


1047
1048
1049
# File 'lib/textbringer/window.rb', line 1047

def show(message)
  @message = message
end