This repository was archived by the owner on Mar 12, 2023. It is now read-only.
Commit 899c771 1 parent 903ce52 commit 899c771 Copy full SHA for 899c771
File tree 3 files changed +76
-60
lines changed
3 files changed +76
-60
lines changed Original file line number Diff line number Diff line change 15
15
require 'ruby_jard/key_bindings'
16
16
require 'ruby_jard/repl_processor'
17
17
require 'ruby_jard/repl_manager'
18
+ require 'ruby_jard/repl_state'
18
19
require 'ruby_jard/screen_manager'
19
20
require 'ruby_jard/reflection'
20
21
Original file line number Diff line number Diff line change @@ -56,68 +56,8 @@ class ReplManager
56
56
KEY_READ_TIMEOUT = 0.2 # 200ms
57
57
PTY_OUTPUT_TIMEOUT = 1 . to_f / 60 # 60hz
58
58
59
- # A class to store the state with multi-thread guarding
60
- # Ready => Processing/Exiting
61
- # Processing => Ready again
62
- # Exiting => Exited
63
- # Exited => Ready
64
- class ReplState
65
- STATES = [
66
- STATE_READY = 0 ,
67
- STATE_EXITING = 1 ,
68
- STATE_PROCESSING = 2 ,
69
- STATE_EXITED = 3
70
- ] . freeze
71
- def initialize
72
- @state = STATE_EXITED
73
- @mutex = Mutex . new
74
- end
75
-
76
- def check ( method_name )
77
- @mutex . synchronize { yield if send ( method_name ) }
78
- end
79
-
80
- def ready?
81
- @state == STATE_READY
82
- end
83
-
84
- def ready!
85
- if ready? || processing? || exited?
86
- @mutex . synchronize { @state = STATE_READY }
87
- end
88
- end
89
-
90
- def processing?
91
- @state == STATE_PROCESSING
92
- end
93
-
94
- def processing!
95
- return unless ready?
96
-
97
- @mutex . synchronize { @state = STATE_PROCESSING }
98
- end
99
-
100
- def exiting?
101
- @state == STATE_EXITING
102
- end
103
-
104
- def exiting!
105
- @mutex . synchronize { @state = STATE_EXITING }
106
- end
107
-
108
- def exited?
109
- @state == STATE_EXITED
110
- end
111
-
112
- def exited!
113
- @mutex . synchronize { @state = STATE_EXITED }
114
- end
115
- end
116
-
117
59
def initialize ( console :, key_bindings : nil )
118
60
@console = console
119
- @state = ReplState . new
120
-
121
61
@pry_input_pipe_read , @pry_input_pipe_write = IO . pipe
122
62
@pry_output_pty_read , @pry_output_pty_write = PTY . open
123
63
Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ module RubyJard
4
+ # A class to store the state with multi-thread guarding
5
+ # Ready => Processing/Exiting
6
+ # Processing => Ready again
7
+ # Exiting => Exited
8
+ # Exited => Ready
9
+ class ReplState
10
+ STATES = [
11
+ STATE_READY = 0 ,
12
+ STATE_EXITING = 1 ,
13
+ STATE_PROCESSING = 2 ,
14
+ STATE_EXITED = 3
15
+ ] . freeze
16
+
17
+ def initialize
18
+ @state = STATE_EXITED
19
+ @mutex = Mutex . new
20
+ @pager = false
21
+ end
22
+
23
+ def check ( method_name )
24
+ @mutex . synchronize { yield if send ( method_name ) }
25
+ end
26
+
27
+ def pager?
28
+ @pager == true
29
+ end
30
+
31
+ def set_pager!
32
+ @pager = true
33
+ end
34
+
35
+ def clear_pager!
36
+ @pager = false
37
+ end
38
+
39
+ def ready?
40
+ @state == STATE_READY
41
+ end
42
+
43
+ def ready!
44
+ if ready? || processing? || exited?
45
+ @mutex . synchronize { @state = STATE_READY }
46
+ end
47
+ end
48
+
49
+ def processing?
50
+ @state == STATE_PROCESSING
51
+ end
52
+
53
+ def processing!
54
+ return unless ready?
55
+
56
+ @mutex . synchronize { @state = STATE_PROCESSING }
57
+ end
58
+
59
+ def exiting?
60
+ @state == STATE_EXITING
61
+ end
62
+
63
+ def exiting!
64
+ @mutex . synchronize { @state = STATE_EXITING }
65
+ end
66
+
67
+ def exited?
68
+ @state == STATE_EXITED
69
+ end
70
+
71
+ def exited!
72
+ @mutex . synchronize { @state = STATE_EXITED }
73
+ end
74
+ end
75
+ end
You can’t perform that action at this time.
0 commit comments