diff options
| author | MaciejDym <[email protected]> | 2021-01-08 18:37:07 +0100 |
|---|---|---|
| committer | Amir Rajan <[email protected]> | 2021-01-11 04:26:28 -0600 |
| commit | b6e6b9187ef88f4900b8b29bbce56ec1631ce099 (patch) | |
| tree | b78e1c55c0392f205252f17c1ce9aa268c683b5b /dragon/console_prompt.rb | |
| parent | d430e6bd3434b6262169012377d9b5b27f0356ba (diff) | |
| download | dragonruby-game-toolkit-contrib-b6e6b9187ef88f4900b8b29bbce56ec1631ce099.tar.gz dragonruby-game-toolkit-contrib-b6e6b9187ef88f4900b8b29bbce56ec1631ce099.zip | |
Added support for `HOME`, `END`, `Ctrl+left` and `Ctrl+right`
Diffstat (limited to 'dragon/console_prompt.rb')
| -rw-r--r-- | dragon/console_prompt.rb | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/dragon/console_prompt.rb b/dragon/console_prompt.rb index e8c2820..9fb1b95 100644 --- a/dragon/console_prompt.rb +++ b/dragon/console_prompt.rb @@ -32,6 +32,7 @@ module GTK def current_input_str=(str) @current_input_str = str @cursor_position = str.length + update_cursor_position_px end def <<(str) @@ -63,11 +64,44 @@ module GTK update_cursor_position_px end + # ? Works well enough, could be better + # TODO: Maybe possibly add skipping multiple word-breaking characters + # TODO: (requires re-writing a lot of the code most likely) + # ?? how can we put in regex? the code would be cleaner that way \ amir please fix :P \\ abolish consoles :> + def move_cursor_left_word + str = @current_input_str[0..[@cursor_position - 1, 0].sort[1]] + # ? Can be changed, it was just taken from my editor settings :> + @cursor_position = ("`~!@#$%^&*-=+()[]{}\|;:'\",.<>/?_ \t\n\0".chars.map { |char| + (val = str.rindex char) ? (val + 1 == @cursor_position ? val : val + 1) : 0 + }.sort.reverse[0]) + update_cursor_position_px + end + def move_cursor_right @cursor_position += 1 if @cursor_position < current_input_str.length update_cursor_position_px end + def move_cursor_right_word + str = @current_input_str[@cursor_position..@current_input_str.length] + # ? Can be changed, it was just taken from my editor settings :> + cand = ("`~!@#$%^&*-=+()[]{}\|;:'\",.<>/?_ \t\n\0".chars.map { |char| + (val = str.index char) ? val : 0 + }.sort - [0]) + (cand == []) ? @cursor_position = @current_input_str.length : @cursor_position += (cand[0]+0) + update_cursor_position_px + end + + def move_cursor_home + @cursor_position = 0 + update_cursor_position_px + end + + def move_cursor_end + @cursor_position = @current_input_str.length + update_cursor_position_px + end + def clear @current_input_str = '' @cursor_position = 0 |
