Experimental, incomplete development towards a functional keying branch.

This commit is contained in:
Pistos 2009-06-25 01:18:50 -04:00
parent 51842a957b
commit b399c7f01e
9 changed files with 114 additions and 32 deletions

View file

@ -455,6 +455,31 @@ key keycode319 operateOnLines
#key ctrl+x ctrl+f;openFileAsk
#key ctrl+x ctrl+s;saveFile
mkey input left readline_cursor_left
mkey input esc [ D readline_cursor_left
mkey input right readline_cursor_right
mkey input esc [ C readline_cursor_right
mkey input esc esc readline_abort
mkey input ctrl+q readline_abort
mkey input ctrl+c readline_abort
mkey input backspace readline_backspace
mkey input ctrl+h readline_backspace
mkey input del readline_delete
mkey input ctrl+k readline_delete_line
mkey input home readline_cursor_bol
mkey input esc O H readline_cursor_bol
mkey input esc [ H readline_cursor_bol
mkey input esc [ 1 ~ readline_cursor_bol
mkey input esc [ 7 ~ readline_cursor_bol
mkey input ctrl+a readline_cursor_bol
mkey input end readline_cursor_eol
mkey input esc O F readline_cursor_eol
mkey input esc [ F readline_cursor_eol
mkey input esc [ 4 ~ readline_cursor_eol
mkey input esc [ 8 ~ readline_cursor_eol
mkey input ctrl+e readline_cursor_eol
# ---------------------------------------------------------------------
# Language Definitions
# For syntax highlighting and indentation.

View file

@ -43,6 +43,7 @@ require 'diakonos/functions/clipboard'
require 'diakonos/functions/cursor'
require 'diakonos/functions/grepping'
require 'diakonos/functions/indentation'
require 'diakonos/functions/readline'
require 'diakonos/functions/search'
require 'diakonos/functions/selection'
require 'diakonos/functions/sessions'

View file

@ -76,6 +76,9 @@ module Diakonos
end
end
@modes[ 'edit' ].window = @win_main
@modes[ 'input' ].window = @win_interaction
@win_interaction.refresh
@win_main.refresh
if @win_line_numbers

View file

@ -0,0 +1,37 @@
module Diakonos
module Functions
def readline_abort
@readline.abort
end
def readline_backspace
@readline.backspace
end
def readline_cursor_left
@readline.cursor_left
end
def readline_cursor_right
@readline.cursor_right
end
def readline_cursor_bol
@readline.cursor_bol
end
def readline_cursor_eol
@readline.cursor_eol
end
def readline_delete
@readline.delete
end
def readline_delete_line
@readline.delete_line
end
end
end

View file

@ -36,6 +36,8 @@ module Diakonos
CHOICE_STRINGS = [ '(n)o', '(y)es', '(a)ll', '(c)ancel', 'y(e)s to all', 'n(o) to all', 'yes and (s)top', '(d)elete' ]
class Diakonos
attr_reader :readline
# completion_array is the array of strings that tab completion can use
# @param options :initial_text, :completion_array, :history, :do_complete, :on_dirs
def get_user_input( prompt, options = {}, &block )
@ -46,7 +48,8 @@ module Diakonos
if @playing_macro
retval = @macro_input_history.shift
else
retval = Readline.new( self, @win_interaction, prompt, options, &block ).readline
@readline = Readline.new( self, @win_interaction, prompt, options, &block )
retval = @readline.readline
if @macro_history
@macro_input_history.push retval
end

View file

@ -245,7 +245,7 @@ module Diakonos
# context is an array of characters (bytes) which are keystrokes previously
# typed (in a chain of keystrokes)
def process_keystroke( context = [], mode = 'edit', ch = nil )
ch ||= @win_main.getch
ch ||= @modes[ mode ].window.getch
return if ch.nil?
c = ch.ord
@ -268,7 +268,7 @@ module Diakonos
ch = nil
begin
Timeout::timeout( 0.02 ) do
ch = @win_main.getch
ch = @modes[ mode ].window.getch
end
rescue Timeout::Error => e
break
@ -300,7 +300,11 @@ module Diakonos
if function_and_args
function, args = function_and_args
set_iline if not @settings[ "context.combined" ]
debug_log function
debug_log args
if mode != 'input' && ! @settings[ "context.combined" ]
set_iline
end
if args
to_eval = "#{function}( #{args} )"

View file

@ -1,9 +1,13 @@
module Diakonos
class Mode
attr_reader :keymap
attr_reader :keymap, :window
def initialize
@keymap = Hash.new.extend( KeyMap )
end
def window=( w )
@window = w
end
end
end

View file

@ -114,11 +114,7 @@ module Diakonos
end
cursor_write_input
when CTRL_K
@input = ""
if @block
@block.call @input
end
cursor_write_input
delete_line
when Curses::KEY_F5
@diakonos.decrease_grep_context
call_block
@ -182,8 +178,9 @@ module Diakonos
end
while ! @done
process_keystroke
@diakonos.process_keystroke Array.new, 'input'
end
@diakonos.debug_log 'done'
@diakonos.close_list_buffer

View file

@ -2,11 +2,24 @@ module Diakonos
class Readline
def delete
return if @input_cursor >= @input.length
@window.delch
set_input( @input[ 0...@input_cursor ] + @input[ (@input_cursor + 1)..-1 ] )
call_block
def abort
@input = nil
@done = true
end
def backspace
cursor_left
delete
end
def cursor_bol
@input_cursor = 0
@window.setpos( @icury, @icurx )
end
def cursor_eol
@input_cursor = @input.length
@window.setpos( @window.cury, @icurx + @input.length )
end
def cursor_left
@ -21,24 +34,19 @@ module Diakonos
@window.setpos( @window.cury, @window.curx + 1 )
end
def cursor_bol
@input_cursor = 0
@window.setpos( @icury, @icurx )
def delete
return if @input_cursor >= @input.length
@window.delch
set_input( @input[ 0...@input_cursor ] + @input[ (@input_cursor + 1)..-1 ] )
call_block
end
def cursor_eol
@input_cursor = @input.length
@window.setpos( @window.cury, @icurx + @input.length )
end
def abort
@input = nil
@done = true
end
def backspace
cursor_left
delete
def delete_line
@input = ""
if @block
@block.call @input
end
cursor_write_input
end
end