Class: Kitsune::Kit::Tui::Store
- Inherits:
-
Object
- Object
- Kitsune::Kit::Tui::Store
- Defined in:
- lib/kitsune/kit/tui/store.rb
Constant Summary collapse
- MAX_LOGS =
200
Instance Method Summary collapse
- #handle(event) ⇒ Object
-
#initialize(environment:, secret_filter: SecretFilter.new, terminal_size: [100, 30]) ⇒ Store
constructor
A new instance of Store.
- #modal(value) ⇒ Object
- #resize(width, height) ⇒ Object
- #resources=(values) ⇒ Object
- #running(value) ⇒ Object
- #scroll(delta) ⇒ Object
- #select(index) ⇒ Object
- #show(screen, result: nil) ⇒ Object
- #snapshot ⇒ Object
Constructor Details
#initialize(environment:, secret_filter: SecretFilter.new, terminal_size: [100, 30]) ⇒ Store
Returns a new instance of Store.
11 12 13 14 15 |
# File 'lib/kitsune/kit/tui/store.rb', line 11 def initialize(environment:, secret_filter: SecretFilter.new, terminal_size: [100, 30]) @state = State.initial(environment: environment, terminal_size: terminal_size) @secret_filter = secret_filter @mutex = Mutex.new end |
Instance Method Details
#handle(event) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/kitsune/kit/tui/store.rb', line 19 def handle(event) data = @secret_filter.filter(event.data) mutate do |state| operations = update_operations(state.operations, event.type, data) logs = append_log(state.logs, event.type, data) state.with(operations: operations, logs: logs, running: running_for(event.type, state.running), notification: notification_for(event.type, data, state.notification)) end end |
#modal(value) ⇒ Object
35 |
# File 'lib/kitsune/kit/tui/store.rb', line 35 def modal(value) = mutate { |state| state.with(modal: value) } |
#resize(width, height) ⇒ Object
33 |
# File 'lib/kitsune/kit/tui/store.rb', line 33 def resize(width, height) = mutate { |state| state.with(terminal_size: [width, height]) } |
#resources=(values) ⇒ Object
45 46 47 |
# File 'lib/kitsune/kit/tui/store.rb', line 45 def resources=(values) mutate { |state| state.with(resources: values, selected_resource: 0) } end |
#running(value) ⇒ Object
36 |
# File 'lib/kitsune/kit/tui/store.rb', line 36 def running(value) = mutate { |state| state.with(running: value) } |
#scroll(delta) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/kitsune/kit/tui/store.rb', line 38 def scroll(delta) mutate do |state| maximum = [state.logs.length - 1, 0].max state.with(scroll_offset: (state.scroll_offset + delta).clamp(0, maximum)) end end |
#select(index) ⇒ Object
34 |
# File 'lib/kitsune/kit/tui/store.rb', line 34 def select(index) = mutate { |state| state.with(selected_resource: index) } |
#show(screen, result: nil) ⇒ Object
29 30 31 |
# File 'lib/kitsune/kit/tui/store.rb', line 29 def show(screen, result: nil) mutate { |state| state.with(screen: screen, result: result, modal: nil, scroll_offset: 0) } end |
#snapshot ⇒ Object
17 |
# File 'lib/kitsune/kit/tui/store.rb', line 17 def snapshot = @mutex.synchronize { @state } |