Merge branch 'master' of git@github.com:Pistos/diakonos
This commit is contained in:
commit
6beaf2141d
18 changed files with 394 additions and 183 deletions
2
Rakefile
2
Rakefile
|
@ -6,7 +6,7 @@ task :spec => [ :test ]
|
|||
|
||||
desc "Run Diakonos tests"
|
||||
task :test do
|
||||
system 'bacon -Ilib spec/*.rb'
|
||||
system 'bacon -Ilib spec/*.rb spec/*/*.rb'
|
||||
end
|
||||
|
||||
begin
|
||||
|
|
|
@ -359,7 +359,7 @@ module Diakonos
|
|||
end
|
||||
|
||||
if num_opened > 0
|
||||
switchToBufferNumber 1
|
||||
switch_to_buffer_number 1
|
||||
|
||||
update_status_line
|
||||
update_context_line
|
||||
|
|
|
@ -2,8 +2,7 @@ module Diakonos
|
|||
|
||||
class Buffer
|
||||
attr_reader :name, :key, :original_language, :changing_selection, :read_only,
|
||||
:last_col, :last_row, :tab_size, :last_screen_x, :last_screen_y, :last_screen_col,
|
||||
:selection_mode
|
||||
:tab_size, :selection_mode
|
||||
attr_writer :desired_column, :read_only
|
||||
|
||||
SELECTION = 0 # Selection mark is the first element of the @text_marks array
|
||||
|
|
|
@ -2,6 +2,8 @@ module Diakonos
|
|||
|
||||
class Buffer
|
||||
|
||||
attr_reader :last_col, :last_row, :last_screen_x, :last_screen_y, :last_screen_col
|
||||
|
||||
# Returns true iff the cursor changed positions in the buffer.
|
||||
def cursor_to( row, col, do_display = DONT_DISPLAY, stopped_typing = STOPPED_TYPING, adjust_row = ADJUST_ROW )
|
||||
old_last_row = @last_row
|
||||
|
|
|
@ -14,7 +14,7 @@ module Diakonos
|
|||
else
|
||||
@read_only = false
|
||||
if name.nil?
|
||||
@diakonos.saveFileAs
|
||||
@diakonos.save_file_as
|
||||
else
|
||||
proceed = true
|
||||
|
||||
|
|
|
@ -1,75 +1,72 @@
|
|||
module Diakonos
|
||||
module Functions
|
||||
alias_method :addNamedBookmark, :add_named_bookmark
|
||||
alias_method :anchorSelection, :anchor_selection
|
||||
alias_method :carriageReturn, :carriage_return
|
||||
alias_method :changeSessionSetting, :change_session_setting
|
||||
alias_method :clearMatches, :clear_matches
|
||||
alias_method :closeFile, :close_file
|
||||
alias_method :collapseWhitespace, :collapse_whitespace
|
||||
alias_method :copySelection, :copy_selection
|
||||
alias_method :cursorDown, :cursor_down
|
||||
alias_method :cursorLeft, :cursor_left
|
||||
alias_method :cursorRight, :cursor_right
|
||||
alias_method :cursorUp, :cursor_up
|
||||
alias_method :cursorBOF, :cursor_bof
|
||||
alias_method :cursorBOL, :cursor_bol
|
||||
alias_method :cursorEOL, :cursor_eol
|
||||
alias_method :cursorEOF, :cursor_eof
|
||||
alias_method :cursorTOV, :cursor_tov
|
||||
alias_method :cursorBOV, :cursor_bov
|
||||
alias_method :cursorReturn, :cursor_return
|
||||
alias_method :cutSelection, :cut_selection
|
||||
alias_method :deleteAndStoreLine, :delete_and_store_line
|
||||
alias_method :deleteLine, :delete_line
|
||||
alias_method :deleteToEOL, :delete_to_eol
|
||||
alias_method :findAgain, :find_again
|
||||
alias_method :findAndReplace, :search_and_replace
|
||||
alias_method :findExact, :find_exact
|
||||
alias_method :goToLineAsk, :go_to_line_ask
|
||||
alias_method :goToNamedBookmark, :go_to_named_bookmark
|
||||
alias_method :goToNextBookmark, :go_to_next_bookmark
|
||||
alias_method :goToPreviousBookmark, :go_to_previous_bookmark
|
||||
alias_method :goToTag, :go_to_tag
|
||||
alias_method :goToTagUnderCursor, :go_to_tag_under_cursor
|
||||
alias_method :insertSpaces, :insert_spaces
|
||||
alias_method :insertTab, :insert_tab
|
||||
alias_method :joinLines, :join_lines
|
||||
alias_method :loadScript, :load_script
|
||||
alias_method :newFile, :open_file
|
||||
alias_method :openFile, :open_file
|
||||
alias_method :openFileAsk, :open_file_ask
|
||||
alias_method :operateOnString, :operate_on_string
|
||||
alias_method :operateOnLines, :operate_on_lines
|
||||
alias_method :operateOnEachLine, :operate_on_each_line
|
||||
alias_method :pageUp, :page_up
|
||||
alias_method :pageDown, :page_down
|
||||
# alias_method :
|
||||
# alias_method :
|
||||
# alias_method :
|
||||
# alias_method :
|
||||
# alias_method :
|
||||
# alias_method :
|
||||
# alias_method :
|
||||
# alias_method :
|
||||
# alias_method :
|
||||
# alias_method :
|
||||
# alias_method :
|
||||
# alias_method :
|
||||
# alias_method :
|
||||
# alias_method :
|
||||
# alias_method :
|
||||
# alias_method :
|
||||
# alias_method :
|
||||
# alias_method :
|
||||
# alias_method :
|
||||
# alias_method :
|
||||
# alias_method :
|
||||
# alias_method :
|
||||
# alias_method :
|
||||
# alias_method :
|
||||
# alias_method :
|
||||
# alias_method :
|
||||
alias_method :searchAndReplace, :search_and_replace
|
||||
alias_method :addNamedBookmark, :add_named_bookmark
|
||||
alias_method :anchorSelection, :anchor_selection
|
||||
alias_method :carriageReturn, :carriage_return
|
||||
alias_method :changeSessionSetting, :change_session_setting
|
||||
alias_method :clearMatches, :clear_matches
|
||||
alias_method :closeFile, :close_file
|
||||
alias_method :collapseWhitespace, :collapse_whitespace
|
||||
alias_method :copySelection, :copy_selection
|
||||
alias_method :cursorDown, :cursor_down
|
||||
alias_method :cursorLeft, :cursor_left
|
||||
alias_method :cursorRight, :cursor_right
|
||||
alias_method :cursorUp, :cursor_up
|
||||
alias_method :cursorBOF, :cursor_bof
|
||||
alias_method :cursorBOL, :cursor_bol
|
||||
alias_method :cursorEOL, :cursor_eol
|
||||
alias_method :cursorEOF, :cursor_eof
|
||||
alias_method :cursorTOV, :cursor_tov
|
||||
alias_method :cursorBOV, :cursor_bov
|
||||
alias_method :cursorReturn, :cursor_return
|
||||
alias_method :cutSelection, :cut_selection
|
||||
alias_method :deleteAndStoreLine, :delete_and_store_line
|
||||
alias_method :deleteLine, :delete_line
|
||||
alias_method :deleteToEOL, :delete_to_eol
|
||||
alias_method :delete_to_EOL_to_klipper, :delete_to_eol_to_klipper
|
||||
alias_method :findAgain, :find_again
|
||||
alias_method :findAndReplace, :search_and_replace
|
||||
alias_method :findExact, :find_exact
|
||||
alias_method :goToLineAsk, :go_to_line_ask
|
||||
alias_method :goToNamedBookmark, :go_to_named_bookmark
|
||||
alias_method :goToNextBookmark, :go_to_next_bookmark
|
||||
alias_method :goToPreviousBookmark, :go_to_previous_bookmark
|
||||
alias_method :goToTag, :go_to_tag
|
||||
alias_method :goToTagUnderCursor, :go_to_tag_under_cursor
|
||||
alias_method :insertSpaces, :insert_spaces
|
||||
alias_method :insertTab, :insert_tab
|
||||
alias_method :joinLines, :join_lines
|
||||
alias_method :loadScript, :load_script
|
||||
alias_method :newFile, :open_file
|
||||
alias_method :openFile, :open_file
|
||||
alias_method :openFileAsk, :open_file_ask
|
||||
alias_method :operateOnString, :operate_on_string
|
||||
alias_method :operateOnLines, :operate_on_lines
|
||||
alias_method :operateOnEachLine, :operate_on_each_line
|
||||
alias_method :pageUp, :page_up
|
||||
alias_method :pageDown, :page_down
|
||||
alias_method :parsedIndent, :parsed_indent
|
||||
alias_method :playMacro, :play_macro
|
||||
alias_method :popTag, :pop_tag
|
||||
alias_method :printKeychain, :print_keychain
|
||||
alias_method :removeNamedBookmark, :remove_named_bookmark
|
||||
alias_method :removeSelection, :remove_selection
|
||||
alias_method :repeatLast, :repeat_last
|
||||
alias_method :saveFile, :save_file
|
||||
alias_method :saveFileAs, :save_file_as
|
||||
alias_method :scrollDown, :scroll_down
|
||||
alias_method :scrollUp, :scroll_up
|
||||
alias_method :searchAndReplace, :search_and_replace
|
||||
alias_method :setBufferType, :set_buffer_type
|
||||
alias_method :setReadOnly, :set_read_only
|
||||
alias_method :showClips, :show_clips
|
||||
alias_method :pasteShellResult, :paste_shell_result
|
||||
alias_method :toggleMacroRecording, :toggle_macro_recording
|
||||
alias_method :switchToBufferNumber, :switch_to_buffer_number
|
||||
alias_method :switchToNextBuffer, :switch_to_next_buffer
|
||||
alias_method :switchToPreviousBuffer, :switch_to_previous_buffer
|
||||
alias_method :toggleBookmark, :toggle_bookmark
|
||||
alias_method :toggleSelection, :toggle_selection
|
||||
alias_method :toggleSessionSetting, :toggle_session_setting
|
||||
end
|
||||
end
|
|
@ -103,7 +103,7 @@ module Diakonos
|
|||
case choice
|
||||
when CHOICE_YES, CHOICE_YES_TO_ALL
|
||||
do_closure = true
|
||||
saveFile( buffer )
|
||||
save_file buffer
|
||||
when CHOICE_NO, CHOICE_NO_TO_ALL
|
||||
do_closure = true
|
||||
when CHOICE_CANCEL
|
||||
|
@ -190,12 +190,12 @@ module Diakonos
|
|||
|
||||
def copy_selection
|
||||
@clipboard.add_clip @current_buffer.copy_selection
|
||||
removeSelection
|
||||
remove_selection
|
||||
end
|
||||
|
||||
def copy_selection_to_klipper
|
||||
if send_to_klipper( @current_buffer.selected_text )
|
||||
removeSelection
|
||||
remove_selection
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -353,7 +353,7 @@ module Diakonos
|
|||
end
|
||||
end
|
||||
|
||||
def delete_to_EOL_to_klipper
|
||||
def delete_to_eol_to_klipper
|
||||
removed_text = @current_buffer.delete_to_eol
|
||||
if removed_text
|
||||
send_to_klipper removed_text
|
||||
|
@ -1071,7 +1071,7 @@ module Diakonos
|
|||
update_context_line
|
||||
end
|
||||
|
||||
def parsedIndent
|
||||
def parsed_indent
|
||||
if( @current_buffer.changing_selection )
|
||||
@do_display = false
|
||||
mark = @current_buffer.selection_mark
|
||||
|
@ -1097,7 +1097,7 @@ module Diakonos
|
|||
@current_buffer.paste text
|
||||
end
|
||||
|
||||
def playMacro( name = nil )
|
||||
def play_macro( name = nil )
|
||||
macro, input_history = @macros[ name ]
|
||||
if input_history
|
||||
@macro_input_history = input_history.deep_clone
|
||||
|
@ -1112,7 +1112,7 @@ module Diakonos
|
|||
end
|
||||
end
|
||||
|
||||
def popTag
|
||||
def pop_tag
|
||||
tag = @tag_stack.pop
|
||||
if tag
|
||||
if not switch_to( @buffers[ tag[ 0 ] ] )
|
||||
|
@ -1129,7 +1129,7 @@ module Diakonos
|
|||
set_iline "Type any chain of keystrokes or key chords, or press Enter to stop."
|
||||
end
|
||||
|
||||
def printKeychain
|
||||
def print_keychain
|
||||
@capturing_keychain = true
|
||||
set_iline "Type any chain of keystrokes or key chords, then press Enter..."
|
||||
end
|
||||
|
@ -1152,7 +1152,7 @@ module Diakonos
|
|||
end
|
||||
end
|
||||
|
||||
def removeNamedBookmark( name_ = nil )
|
||||
def remove_named_bookmark( name_ = nil )
|
||||
if name_.nil?
|
||||
name = get_user_input "Bookmark name: "
|
||||
else
|
||||
|
@ -1165,12 +1165,12 @@ module Diakonos
|
|||
end
|
||||
end
|
||||
|
||||
def removeSelection
|
||||
def remove_selection
|
||||
@current_buffer.remove_selection
|
||||
update_status_line
|
||||
end
|
||||
|
||||
def repeatLast
|
||||
def repeat_last
|
||||
eval @last_commands[ -1 ] if not @last_commands.empty?
|
||||
end
|
||||
|
||||
|
@ -1202,12 +1202,12 @@ module Diakonos
|
|||
end
|
||||
end
|
||||
|
||||
def saveFile( buffer = @current_buffer )
|
||||
def save_file( buffer = @current_buffer )
|
||||
buffer.save
|
||||
run_hook_procs( :after_save, buffer )
|
||||
end
|
||||
|
||||
def saveFileAs
|
||||
def save_file_as
|
||||
if @current_buffer and @current_buffer.name
|
||||
path = File.expand_path( File.dirname( @current_buffer.name ) ) + "/"
|
||||
file = get_user_input( "Filename: ", @rlh_files, path )
|
||||
|
@ -1255,13 +1255,13 @@ module Diakonos
|
|||
update_status_line
|
||||
end
|
||||
|
||||
def scrollDown
|
||||
def scroll_down
|
||||
@current_buffer.pitch_view( @settings[ "view.scroll_amount" ] || 1 )
|
||||
update_status_line
|
||||
update_context_line
|
||||
end
|
||||
|
||||
def scrollUp
|
||||
def scroll_up
|
||||
if @settings[ "view.scroll_amount" ]
|
||||
@current_buffer.pitch_view( -@settings[ "view.scroll_amount" ] )
|
||||
else
|
||||
|
@ -1284,7 +1284,7 @@ module Diakonos
|
|||
end
|
||||
end
|
||||
|
||||
def setBufferType( type_ = nil )
|
||||
def set_buffer_type( type_ = nil )
|
||||
if type_.nil?
|
||||
type = get_user_input "Content type: "
|
||||
else
|
||||
|
@ -1301,7 +1301,7 @@ module Diakonos
|
|||
|
||||
# If read_only is nil, the read_only state of the current buffer is toggled.
|
||||
# Otherwise, the read_only state of the current buffer is set to read_only.
|
||||
def setReadOnly( read_only = nil )
|
||||
def set_read_only( read_only = nil )
|
||||
if read_only
|
||||
@current_buffer.read_only = read_only
|
||||
else
|
||||
|
@ -1321,7 +1321,7 @@ module Diakonos
|
|||
end
|
||||
end
|
||||
|
||||
def showClips
|
||||
def show_clips
|
||||
clip_filename = @diakonos_home + "/clips.txt"
|
||||
File.open( clip_filename, "w" ) do |f|
|
||||
@clipboard.each do |clip|
|
||||
|
@ -1332,7 +1332,7 @@ module Diakonos
|
|||
open_file clip_filename
|
||||
end
|
||||
|
||||
def subShellVariables( string )
|
||||
def sub_shell_variables( string )
|
||||
return if string.nil?
|
||||
|
||||
retval = string.dup
|
||||
|
@ -1399,7 +1399,7 @@ module Diakonos
|
|||
end
|
||||
|
||||
if command
|
||||
command = subShellVariables( command )
|
||||
command = sub_shell_variables( command )
|
||||
|
||||
result_file = "#{@diakonos_home}/#{result_filename}"
|
||||
File.open( result_file , "w" ) do |f|
|
||||
|
@ -1437,7 +1437,7 @@ module Diakonos
|
|||
end
|
||||
|
||||
if command
|
||||
command = subShellVariables( command )
|
||||
command = sub_shell_variables( command )
|
||||
|
||||
Curses::close_screen
|
||||
|
||||
|
@ -1455,7 +1455,7 @@ module Diakonos
|
|||
end
|
||||
end
|
||||
|
||||
def pasteShellResult( command_ = nil )
|
||||
def paste_shell_result( command_ = nil )
|
||||
if command_.nil?
|
||||
command = get_user_input( "Command: ", @rlh_shell )
|
||||
else
|
||||
|
@ -1463,7 +1463,7 @@ module Diakonos
|
|||
end
|
||||
|
||||
if command
|
||||
command = subShellVariables( command )
|
||||
command = sub_shell_variables( command )
|
||||
|
||||
Curses::close_screen
|
||||
|
||||
|
@ -1489,7 +1489,7 @@ module Diakonos
|
|||
|
||||
return if command.nil?
|
||||
|
||||
command = subShellVariables( command )
|
||||
command = sub_shell_variables( command )
|
||||
|
||||
Thread.new do
|
||||
if system( command )
|
||||
|
@ -1508,7 +1508,7 @@ module Diakonos
|
|||
refresh_all
|
||||
end
|
||||
|
||||
def toggleMacroRecording( name = nil )
|
||||
def toggle_macro_recording( name = nil )
|
||||
if @macro_history
|
||||
stop_recording_macro
|
||||
else
|
||||
|
@ -1516,7 +1516,7 @@ module Diakonos
|
|||
end
|
||||
end
|
||||
|
||||
def switchToBufferNumber( buffer_number_ )
|
||||
def switch_to_buffer_number( buffer_number_ )
|
||||
buffer_number = buffer_number_.to_i
|
||||
return if buffer_number < 1
|
||||
buffer_name = buffer_number_to_name( buffer_number )
|
||||
|
@ -1525,44 +1525,44 @@ module Diakonos
|
|||
end
|
||||
end
|
||||
|
||||
def switchToNextBuffer
|
||||
def switch_to_next_buffer
|
||||
if @buffer_history.any?
|
||||
@buffer_history_pointer += 1
|
||||
if @buffer_history_pointer >= @buffer_history_pointer.size
|
||||
@buffer_history_pointer = @buffer_history_pointer.size - 1
|
||||
switchToBufferNumber( buffer_to_number( @current_buffer ) + 1 )
|
||||
switch_to_buffer_number( buffer_to_number( @current_buffer ) + 1 )
|
||||
else
|
||||
switch_to @buffer_history[ @buffer_history_pointer ]
|
||||
end
|
||||
else
|
||||
switchToBufferNumber( buffer_to_number( @current_buffer ) + 1 )
|
||||
switch_to_buffer_number( buffer_to_number( @current_buffer ) + 1 )
|
||||
end
|
||||
end
|
||||
|
||||
def switchToPreviousBuffer
|
||||
def switch_to_previous_buffer
|
||||
if @buffer_history.any?
|
||||
@buffer_history_pointer -= 1
|
||||
if @buffer_history_pointer < 0
|
||||
@buffer_history_pointer = 0
|
||||
switchToBufferNumber( buffer_to_number( @current_buffer ) - 1 )
|
||||
switch_to_buffer_number( buffer_to_number( @current_buffer ) - 1 )
|
||||
else
|
||||
switch_to @buffer_history[ @buffer_history_pointer ]
|
||||
end
|
||||
else
|
||||
switchToBufferNumber( buffer_to_number( @current_buffer ) - 1 )
|
||||
switch_to_buffer_number( buffer_to_number( @current_buffer ) - 1 )
|
||||
end
|
||||
end
|
||||
|
||||
def toggleBookmark
|
||||
def toggle_bookmark
|
||||
@current_buffer.toggle_bookmark
|
||||
end
|
||||
|
||||
def toggleSelection
|
||||
def toggle_selection
|
||||
@current_buffer.toggle_selection
|
||||
update_status_line
|
||||
end
|
||||
|
||||
def toggleSessionSetting( key_ = nil, do_redraw = DONT_REDRAW )
|
||||
def toggle_session_setting( key_ = nil, do_redraw = DONT_REDRAW )
|
||||
key = key_ || get_user_input( "Setting: " )
|
||||
return if key.nil?
|
||||
|
||||
|
|
|
@ -281,7 +281,7 @@ module Diakonos
|
|||
|
||||
begin
|
||||
eval to_eval, nil, "eval"
|
||||
@last_commands << to_eval unless to_eval == "repeatLast"
|
||||
@last_commands << to_eval unless to_eval == "repeat_last"
|
||||
if ! @there_was_non_movement
|
||||
@there_was_non_movement = !( /^((cursor|page|scroll)(Up|Down|Left|Right)|find)/ === to_eval )
|
||||
end
|
||||
|
|
|
@ -37,7 +37,7 @@ module Diakonos
|
|||
|
||||
# Returns nil on cancel.
|
||||
def readline
|
||||
@input = @initial_text
|
||||
@input = @initial_text.dup
|
||||
if ! @input.empty?
|
||||
call_block
|
||||
end
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
module Diakonos
|
||||
|
||||
class TextMark
|
||||
class TextMark
|
||||
attr_reader :formatting, :start_row, :start_col, :end_row, :end_col
|
||||
|
||||
def initialize( start_row, start_col, end_row, end_col, formatting )
|
||||
@start_row = start_row
|
||||
@start_col = start_col
|
||||
@end_row = end_row
|
||||
@end_col = end_col
|
||||
@formatting = formatting
|
||||
@start_row = start_row
|
||||
@start_col = start_col
|
||||
@end_row = end_row
|
||||
@end_col = end_col
|
||||
@formatting = formatting
|
||||
end
|
||||
|
||||
def to_s
|
||||
"(#{start_row},#{start_col})-(#{end_row},#{end_col}) #{formatting}"
|
||||
"(#{start_row},#{start_col})-(#{end_row},#{end_col}) #{formatting}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -1,4 +1,4 @@
|
|||
module Diakonos
|
||||
VERSION = '0.8.9'
|
||||
LAST_MODIFIED = 'April 15, 2009'
|
||||
LAST_MODIFIED = 'April 18, 2009'
|
||||
end
|
|
@ -7,9 +7,6 @@ describe 'A Diakonos::Buffer' do
|
|||
@b.cursor_to( 0, 0 )
|
||||
end
|
||||
|
||||
after do
|
||||
end
|
||||
|
||||
it 'can provide selected text' do
|
||||
@b.anchor_selection( 0, 0 )
|
||||
@b.cursor_to( 3, 0 )
|
||||
|
|
|
@ -1,58 +0,0 @@
|
|||
require 'spec/preparation'
|
||||
|
||||
describe 'Diakonos' do
|
||||
|
||||
before do
|
||||
@d = $diakonos
|
||||
@b = @d.openFile( SAMPLE_FILE )
|
||||
end
|
||||
|
||||
it 'can cut consecutive lines into an internal clipboard' do
|
||||
original_lines = @b.to_a
|
||||
|
||||
@d.cursor_bof
|
||||
@d.delete_and_store_line
|
||||
@d.last_commands << 'delete_and_store_line'
|
||||
@d.clipboard.clip.should.equal( [
|
||||
'#!/usr/bin/env ruby',
|
||||
'',
|
||||
] )
|
||||
@d.delete_and_store_line
|
||||
@d.last_commands << 'delete_and_store_line'
|
||||
@d.clipboard.clip.should.equal( [
|
||||
'#!/usr/bin/env ruby',
|
||||
'',
|
||||
'',
|
||||
] )
|
||||
@d.delete_and_store_line
|
||||
@d.last_commands << 'delete_and_store_line'
|
||||
@d.clipboard.clip.should.equal( [
|
||||
'#!/usr/bin/env ruby',
|
||||
'',
|
||||
'# This is only a sample file used in the tests.',
|
||||
'',
|
||||
] )
|
||||
@b.to_a.should.not.equal original_lines
|
||||
|
||||
@d.paste
|
||||
@b.to_a.should.equal original_lines
|
||||
end
|
||||
|
||||
it 'can cut consecutive lines to Klipper' do
|
||||
original_lines = @b.to_a
|
||||
|
||||
@d.cursor_bof
|
||||
@d.delete_and_store_line_to_klipper
|
||||
@d.last_commands << 'delete_and_store_line_to_klipper'
|
||||
@b.to_a.should.equal original_lines[ 1..-1 ]
|
||||
@d.delete_and_store_line_to_klipper
|
||||
@d.last_commands << 'delete_and_store_line_to_klipper'
|
||||
@b.to_a.should.equal original_lines[ 2..-1 ]
|
||||
@d.delete_and_store_line_to_klipper
|
||||
@d.last_commands << 'delete_and_store_line_to_klipper'
|
||||
@b.to_a.should.equal original_lines[ 3..-1 ]
|
||||
|
||||
@d.paste
|
||||
@b.to_a.should.equal original_lines
|
||||
end
|
||||
end
|
42
spec/functions/basics.rb
Normal file
42
spec/functions/basics.rb
Normal file
|
@ -0,0 +1,42 @@
|
|||
require 'spec/preparation'
|
||||
|
||||
describe 'A Diakonos user can' do
|
||||
|
||||
before do
|
||||
@d = $diakonos
|
||||
@b = @d.open_file( SAMPLE_FILE )
|
||||
cursor_should_be_at 0,0
|
||||
end
|
||||
|
||||
after do
|
||||
@d.close_file @b, Diakonos::CHOICE_NO_TO_ALL
|
||||
end
|
||||
|
||||
it 'delete the current character' do
|
||||
@d.delete
|
||||
cursor_should_be_at 0,0
|
||||
@b.to_a[ 0 ].should.equal '!/usr/bin/env ruby'
|
||||
end
|
||||
|
||||
it 'backspace the previous character' do
|
||||
3.times{ @d.cursor_right }
|
||||
cursor_should_be_at 0,3
|
||||
@d.backspace
|
||||
@b.to_a[ 0 ].should.equal '#!usr/bin/env ruby'
|
||||
cursor_should_be_at 0,2
|
||||
end
|
||||
|
||||
it 'insert a newline character' do
|
||||
5.times{ @d.cursor_right }
|
||||
@d.carriage_return
|
||||
cursor_should_be_at 1,0
|
||||
lines = @b.to_a
|
||||
lines[ 0..3 ].should.equal [
|
||||
'#!/us',
|
||||
'r/bin/env ruby',
|
||||
'',
|
||||
'# This is only a sample file used in the tests.',
|
||||
]
|
||||
end
|
||||
|
||||
end
|
121
spec/functions/clipboard.rb
Normal file
121
spec/functions/clipboard.rb
Normal file
|
@ -0,0 +1,121 @@
|
|||
require 'spec/preparation'
|
||||
|
||||
describe 'A Diakonos user can' do
|
||||
|
||||
before do
|
||||
@d = $diakonos
|
||||
@b = @d.open_file( SAMPLE_FILE )
|
||||
cursor_should_be_at 0,0
|
||||
end
|
||||
|
||||
after do
|
||||
@d.close_file @b, Diakonos::CHOICE_NO_TO_ALL
|
||||
end
|
||||
|
||||
it 'copy selected text' do
|
||||
@d.anchor_selection
|
||||
@d.cursor_down
|
||||
@d.cursor_down
|
||||
@d.cursor_down
|
||||
@d.copy_selection
|
||||
@d.clipboard.clip.should.equal [
|
||||
'#!/usr/bin/env ruby',
|
||||
'',
|
||||
'# This is only a sample file used in the tests.',
|
||||
'',
|
||||
]
|
||||
end
|
||||
|
||||
it 'cut selected text' do
|
||||
@d.anchor_selection
|
||||
@d.cursor_down
|
||||
@d.cursor_down
|
||||
@d.cursor_down
|
||||
@d.cut_selection
|
||||
@d.clipboard.clip.should.equal [
|
||||
'#!/usr/bin/env ruby',
|
||||
'',
|
||||
'# This is only a sample file used in the tests.',
|
||||
'',
|
||||
]
|
||||
|
||||
lines = @b.to_a
|
||||
lines.size.should.equal 18
|
||||
lines[ 0..2 ].should.equal [
|
||||
'',
|
||||
'class Sample',
|
||||
' attr_reader :x, :y',
|
||||
]
|
||||
end
|
||||
|
||||
it 'paste from the clipboard' do
|
||||
@d.anchor_selection
|
||||
3.times { @d.cursor_down }
|
||||
@d.copy_selection
|
||||
@d.paste
|
||||
|
||||
lines = @b.to_a
|
||||
lines.size.should.equal 24
|
||||
lines[ 0..8 ].should.equal [
|
||||
'#!/usr/bin/env ruby',
|
||||
'',
|
||||
'# This is only a sample file used in the tests.',
|
||||
'#!/usr/bin/env ruby',
|
||||
'',
|
||||
'# This is only a sample file used in the tests.',
|
||||
'',
|
||||
'class Sample',
|
||||
' attr_reader :x, :y',
|
||||
]
|
||||
end
|
||||
|
||||
it 'cut consecutive lines' do
|
||||
original_lines = @b.to_a
|
||||
|
||||
@d.cursor_bof
|
||||
@d.delete_and_store_line
|
||||
@d.last_commands << 'delete_and_store_line'
|
||||
@d.clipboard.clip.should.equal( [
|
||||
'#!/usr/bin/env ruby',
|
||||
'',
|
||||
] )
|
||||
@d.delete_and_store_line
|
||||
@d.last_commands << 'delete_and_store_line'
|
||||
@d.clipboard.clip.should.equal( [
|
||||
'#!/usr/bin/env ruby',
|
||||
'',
|
||||
'',
|
||||
] )
|
||||
@d.delete_and_store_line
|
||||
@d.last_commands << 'delete_and_store_line'
|
||||
@d.clipboard.clip.should.equal( [
|
||||
'#!/usr/bin/env ruby',
|
||||
'',
|
||||
'# This is only a sample file used in the tests.',
|
||||
'',
|
||||
] )
|
||||
@b.to_a.should.not.equal original_lines
|
||||
|
||||
@d.paste
|
||||
@b.to_a.should.equal original_lines
|
||||
end
|
||||
|
||||
it 'cut consecutive lines to Klipper' do
|
||||
original_lines = @b.to_a
|
||||
|
||||
@d.cursor_bof
|
||||
@d.delete_and_store_line_to_klipper
|
||||
@d.last_commands << 'delete_and_store_line_to_klipper'
|
||||
@b.to_a.should.equal original_lines[ 1..-1 ]
|
||||
@d.delete_and_store_line_to_klipper
|
||||
@d.last_commands << 'delete_and_store_line_to_klipper'
|
||||
@b.to_a.should.equal original_lines[ 2..-1 ]
|
||||
@d.delete_and_store_line_to_klipper
|
||||
@d.last_commands << 'delete_and_store_line_to_klipper'
|
||||
@b.to_a.should.equal original_lines[ 3..-1 ]
|
||||
|
||||
@d.paste
|
||||
@b.to_a.should.equal original_lines
|
||||
end
|
||||
|
||||
end
|
49
spec/functions/cursor.rb
Normal file
49
spec/functions/cursor.rb
Normal file
|
@ -0,0 +1,49 @@
|
|||
require 'spec/preparation'
|
||||
|
||||
describe 'A Diakonos user can' do
|
||||
|
||||
before do
|
||||
@d = $diakonos
|
||||
@b = @d.open_file( SAMPLE_FILE )
|
||||
end
|
||||
|
||||
after do
|
||||
@d.close_file @b, Diakonos::CHOICE_NO_TO_ALL
|
||||
end
|
||||
|
||||
it 'move the cursor in the four basic directions' do
|
||||
cursor_should_be_at 0,0
|
||||
|
||||
@d.cursor_down
|
||||
cursor_should_be_at 1,0
|
||||
@d.cursor_up
|
||||
cursor_should_be_at 0,0
|
||||
@d.cursor_right
|
||||
cursor_should_be_at 0,1
|
||||
@d.cursor_left
|
||||
cursor_should_be_at 0,0
|
||||
end
|
||||
|
||||
it 'move the cursor to the end of a line' do
|
||||
@d.cursor_eol
|
||||
cursor_should_be_at 0,19
|
||||
end
|
||||
|
||||
it 'move the cursor to the beginning of a line' do
|
||||
@b.cursor_to 2,2
|
||||
@d.cursor_bol
|
||||
cursor_should_be_at 2,0
|
||||
end
|
||||
|
||||
it 'move the cursor to the end of a file' do
|
||||
@d.cursor_eof
|
||||
cursor_should_be_at 20,0
|
||||
end
|
||||
|
||||
it 'move the cursor to the beginning of a file' do
|
||||
@b.cursor_to 2,2
|
||||
@d.cursor_bof
|
||||
cursor_should_be_at 0,0
|
||||
end
|
||||
|
||||
end
|
57
spec/functions/selection.rb
Normal file
57
spec/functions/selection.rb
Normal file
|
@ -0,0 +1,57 @@
|
|||
require 'spec/preparation'
|
||||
|
||||
describe 'A Diakonos user can' do
|
||||
|
||||
before do
|
||||
@d = $diakonos
|
||||
@b = @d.openFile( SAMPLE_FILE )
|
||||
cursor_should_be_at 0,0
|
||||
end
|
||||
|
||||
it 'select text' do
|
||||
@d.anchor_selection
|
||||
@d.cursor_down
|
||||
@d.cursor_down
|
||||
@d.cursor_down
|
||||
cursor_should_be_at 3,0
|
||||
|
||||
selection = @b.selection_mark
|
||||
selection.start_row.should.equal 0
|
||||
selection.start_col.should.equal 0
|
||||
selection.end_row.should.equal 3
|
||||
selection.end_col.should.equal 0
|
||||
end
|
||||
|
||||
it 'stop selecting text' do
|
||||
@b.selection_mark.should.be.nil
|
||||
@d.anchor_selection
|
||||
@d.cursor_down
|
||||
@d.cursor_down
|
||||
@b.selection_mark.should.not.be.nil
|
||||
@d.remove_selection
|
||||
@b.selection_mark.should.be.nil
|
||||
end
|
||||
|
||||
it 'select the whole file at once' do
|
||||
@b.selection_mark.should.be.nil
|
||||
@d.select_all
|
||||
s = @b.selection_mark
|
||||
s.start_row.should.equal 0
|
||||
s.start_col.should.equal 0
|
||||
s.end_row.should.equal 20
|
||||
s.end_col.should.equal 0
|
||||
end
|
||||
|
||||
it 'delete the selection' do
|
||||
@d.anchor_selection
|
||||
3.times { @d.cursor_down }
|
||||
@d.delete
|
||||
@b.to_a[ 0..2 ].should.equal [
|
||||
'',
|
||||
'class Sample',
|
||||
' attr_reader :x, :y',
|
||||
]
|
||||
cursor_should_be_at 0,0
|
||||
end
|
||||
|
||||
end
|
|
@ -17,6 +17,11 @@ if ! Object.const_defined? 'TEMP_FILE'
|
|||
TEMP_FILE = File.join( TEST_DIR, '/temp-file.rb' )
|
||||
end
|
||||
|
||||
def cursor_should_be_at( row, col )
|
||||
@b.current_row.should.equal row
|
||||
@b.current_column.should.equal col
|
||||
end
|
||||
|
||||
$diakonos = Diakonos::Diakonos.new [ '-e', 'quit', '--test', ]
|
||||
$diakonos.start
|
||||
$diakonos.parse_configuration_file( File.join( __DIR__, 'test-files', 'test.conf' ) )
|
Loading…
Reference in a new issue