diff options
| author | Kevin Fischer <[email protected]> | 2020-09-05 20:24:19 +0900 |
|---|---|---|
| committer | Kevin Fischer <[email protected]> | 2020-09-05 20:24:19 +0900 |
| commit | 6d5b91289a6db11f7fae2453fdee8297a495773e (patch) | |
| tree | 493e9966a0898198893b5118624b57fb9a46160a /dragon/console_prompt.rb | |
| parent | 8c69db94621010caa2b417891cae1933cc904bd2 (diff) | |
| download | dragonruby-game-toolkit-contrib-6d5b91289a6db11f7fae2453fdee8297a495773e.tar.gz dragonruby-game-toolkit-contrib-6d5b91289a6db11f7fae2453fdee8297a495773e.zip | |
Add left/right arrow behaviour
Diffstat (limited to 'dragon/console_prompt.rb')
| -rw-r--r-- | dragon/console_prompt.rb | 10 |
1 files changed, 9 insertions, 1 deletions
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 |
