Class: TermuxRubyApi::SubSystems::Dialog

Inherits:
Base
  • Object
show all
Defined in:
lib/termux_ruby_api/sub_systems/dialog.rb

Instance Attribute Summary

Attributes inherited from Base

#owner

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from TermuxRubyApi::SubSystems::Base

Instance Method Details

#checkbox(title = nil, result_type: :index, options:) ⇒ Array

Shows a dialog asking for a multiple choice question, with checkboxes

Parameters:

  • title (String) (defaults to: nil)

    the title of the dialog

  • options (Array <String>)

    the options the user has to select from

  • result_type (:index, :text, raw) (defaults to: :index)

    How you want the result :index #=> The index (0 based) of the selected options :text #=> The texts for the selected options :raw #=> A parsed JSON object with the result from Termux API

Returns:

  • (Array)


40
41
42
43
44
45
46
47
48
# File 'lib/termux_ruby_api/sub_systems/dialog.rb', line 40

def checkbox(title = nil, result_type: :index, options:)
  args = owner.generate_args_list([['checkbox'],
                                   ['-t', title],
                                   ['-v', options.join(',')]
                                  ])
  res = owner.json_api_command('dialog', nil, *args)
  return res if result_type == :raw
  res[:values]&.map { |r| extract_result(r, result_type) }
end

#confirm(title = nil, hint: nil, result_type: :boolean) ⇒ Object

Shows a dialog asking for a Yes/No confirmation

Parameters:

  • title (String) (defaults to: nil)

    the title of the dialog

  • hint (String) (defaults to: nil)

    aclaratory text

  • result_type (:boolean, :text, raw) (defaults to: :boolean)

    How you want the result :boolean #=> true for “Yes” false for “No” :text #=> “Yes” or “No” :raw #=> A parsed JSON object with the result from Termux API

Returns:

  • Depends on @result_type



24
25
26
27
28
29
30
# File 'lib/termux_ruby_api/sub_systems/dialog.rb', line 24

def confirm(title = nil, hint: nil, result_type: :boolean)
  args = owner.generate_args_list([['confirm'],
                                   ['-t', title],
                                   ['-i', hint]
                                  ])
  single_result(args, result_type)
end

#date(title = nil, result_type: :date) ⇒ Object

Shows a dialog asking for a calendar date

Parameters:

  • title (String) (defaults to: nil)

    the title of the dialog

  • result_type (:date, :text, raw) (defaults to: :date)

    How you want the result :date #=> A Ruby Date class instance :text #=> The String for the selected date :raw #=> A parsed JSON object with the result from Termux API

Returns:

  • Depends on @result_type



83
84
85
86
87
88
# File 'lib/termux_ruby_api/sub_systems/dialog.rb', line 83

def date(title = nil, result_type: :date)
  args = owner.generate_args_list([['date'],
                                   ['-t', title]
                                  ])
  single_result(args, result_type)
end

#radio(title = nil, result_type: :index, options:) ⇒ Object Also known as: spinner, sheet

Shows a dialog asking for a multiple choice question, with radio buttons

Parameters:

  • title (String) (defaults to: nil)

    the title of the dialog

  • options (Array <String>)

    the options the user has to select from

  • result_type (:index, :text, raw) (defaults to: :index)

    How you want the result :index #=> The index (0 based) of the selected option :text #=> The text for the selected option :raw #=> A parsed JSON object with the result from Termux API

Returns:

  • Depends on the result_type



58
59
60
61
62
63
64
# File 'lib/termux_ruby_api/sub_systems/dialog.rb', line 58

def radio(title = nil, result_type: :index, options:)
  args = owner.generate_args_list([[__callee__.to_s],
                                   ['-t', title],
                                   ['-v', options.join(',')]
                                  ])
  single_result(args, result_type)
end

#speech(title = nil, hint: nil, result_type: :text) ⇒ Object

Shows a dialog asking for spoken input, to be converted to text

Parameters:

  • title (String) (defaults to: nil)

    the title of the dialog

  • hint (String) (defaults to: nil)

    aclaratory text

  • result_type (:boolean, :text, raw) (defaults to: :text)

    How you want the result :text #=> The recognized text :raw #=> A parsed JSON object with the result from Termux API

Returns:

  • Depends on @result_type



97
98
99
100
101
102
103
# File 'lib/termux_ruby_api/sub_systems/dialog.rb', line 97

def speech(title = nil, hint: nil, result_type: :text)
  args = owner.generate_args_list([['speech'],
                                   ['-t', title],
                                   ['-i', hint]
                                  ])
  single_result(args, result_type)
end

#text(title = nil, hint: nil) ⇒ String

Shows a dialog asking for a simple text message

Parameters:

  • title (String) (defaults to: nil)

    the title of the dialog

  • hint (String) (defaults to: nil)

    aclaratory text

Returns:

  • (String)

    the text entered by the user



8
9
10
11
12
13
14
# File 'lib/termux_ruby_api/sub_systems/dialog.rb', line 8

def text(title = nil, hint: nil)
  args = owner.generate_args_list([['text'],
                                   ['-t', title],
                                   ['-i', hint]
                                  ])
  single_result(args, :text)
end