summaryrefslogtreecommitdiffhomepage
path: root/dragon
diff options
context:
space:
mode:
authorKevin Fischer <[email protected]>2020-09-05 20:24:19 +0900
committerKevin Fischer <[email protected]>2020-09-05 20:24:19 +0900
commit6d5b91289a6db11f7fae2453fdee8297a495773e (patch)
tree493e9966a0898198893b5118624b57fb9a46160a /dragon
parent8c69db94621010caa2b417891cae1933cc904bd2 (diff)
downloaddragonruby-game-toolkit-contrib-6d5b91289a6db11f7fae2453fdee8297a495773e.tar.gz
dragonruby-game-toolkit-contrib-6d5b91289a6db11f7fae2453fdee8297a495773e.zip
Add left/right arrow behaviour
Diffstat (limited to 'dragon')
-rw-r--r--dragon/console.rb4
-rw-r--r--dragon/console_prompt.rb10
2 files changed, 13 insertions, 1 deletions
diff --git a/dragon/console.rb b/dragon/console.rb
index c90755a..4f47ba0 100644
--- a/dragon/console.rb
+++ b/dragon/console.rb
@@ -428,6 +428,10 @@ S
@command_history_index -= 1
self.current_input_str = @command_history[@command_history_index].dup
end
+ elsif args.inputs.keyboard.key_down.left
+ prompt.move_cursor_left
+ elsif args.inputs.keyboard.key_down.right
+ prompt.move_cursor_right
elsif inputs_scroll_up_full? args
scroll_up_full
elsif inputs_scroll_down_full? args
diff --git a/dragon/console_prompt.rb b/dragon/console_prompt.rb
index 2aa1e48..3d1257b 100644
--- a/dragon/console_prompt.rb
+++ b/dragon/console_prompt.rb
@@ -44,6 +44,14 @@ module GTK
reset_autocomplete
end
+ def move_cursor_left
+ @cursor_position -= 1 if @cursor_position > 0
+ end
+
+ def move_cursor_right
+ @cursor_position += 1 if @cursor_position < current_input_str.length
+ end
+
def clear
@current_input_str = ''
@cursor_position = 0
@@ -124,7 +132,7 @@ S
def render(args, x:, y:)
args.outputs.reserved << font_style.label(x: x, y: y, text: "#{@prompt}#{current_input_str}", color: @text_color)
- args.outputs.reserved << font_style.label(x: x - 2, y: y + 3, text: (" " * (@prompt.length + current_input_str.length)) + "|", color: @cursor_color)
+ args.outputs.reserved << font_style.label(x: x - 4, y: y + 3, text: (" " * (@prompt.length + @cursor_position)) + "|", color: @cursor_color)
end
def tick