Skip to content

Commit 3723034

Browse files
committed
amend gvar $shell to lvar shell && make Shell.simply_question singleton method
1 parent c5c9a90 commit 3723034

File tree

5 files changed

+13
-18
lines changed

5 files changed

+13
-18
lines changed

mrbgems/picoruby-bin-r2p2/tools/mrblib/app.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
Shell.bootstrap("../etc/init.d/r2p2")
1010

11-
$shell = Shell.new
12-
$shell.show_logo
13-
$shell.start
11+
shell = Shell.new
12+
shell.show_logo
13+
shell.start
1414
rescue => e
1515
puts e.message
1616
exit

mrbgems/picoruby-shell/mrblib/shell.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,7 @@ def self.setup_sdcard(spi)
143143
end
144144
end
145145

146-
def initialize(clean: false)
147-
require 'editor' # To save memory
148-
clean and IO.wait_terminal(timeout: 2) and IO.clear_screen
149-
@editor = Editor::Line.new
150-
end
151-
152-
def simple_question(question, &block)
146+
def self.simple_question(question, &block)
153147
while true
154148
print question
155149
answer = ""
@@ -167,6 +161,12 @@ def simple_question(question, &block)
167161
end
168162
end
169163

164+
def initialize(clean: false)
165+
require 'editor' # To save memory
166+
clean and IO.wait_terminal(timeout: 2) and IO.clear_screen
167+
@editor = Editor::Line.new
168+
end
169+
170170
LOGO_COLOR = "\e[32;1m"
171171
AUTHOR_COLOR = "\e[36;1m"
172172
if RUBY_ENGINE == "mruby/c"

mrbgems/picoruby-shell/shell_executables/setup_rtc.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# TODO: move /etc/init.c/r2p2-rtc
44
i2c_unit, sda, scl = :RP2040_I2C0, 4, 5
55

6-
$shell.simple_question("Do you have RTC? (sda:#{sda}, scl:#{scl}) [y/N] ") do |answer|
6+
Shell.simple_question("Do you have RTC? (sda:#{sda}, scl:#{scl}) [y/N] ") do |answer|
77
case answer
88
when "y", "Y"
99
i2c = I2C.new(unit: i2c_unit, sda_pin: sda, scl_pin: scl)

mrbgems/picoruby-shell/shell_executables/setup_sdcard.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# TODO: move /etc/init.c/r2p2-sdcard
44
spi_unit, sck, cipo, copi, cs = :RP2040_SPI0, 22, 20, 23, 21
55

6-
$shell.simple_question("Do you have SD card? (sck:#{sck}, cipo:#{cipo}, copi:#{copi}, cs:#{cs}) [y/N] ") do |answer|
6+
Shell.simple_question("Do you have SD card? (sck:#{sck}, cipo:#{cipo}, copi:#{copi}, cs:#{cs}) [y/N] ") do |answer|
77
case answer
88
when "y", "Y"
99
spi = SPI.new(frequency: 5_000_000, unit: spi_unit,

mrbgems/picoruby-shell/sig/shell.rbs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@
33
# Revealed types
44
# /home/hasumi/work/prk_firmware/lib/picoruby/mrbgems/picoruby-shell/mrblib/command.rb:69 #=> nil
55

6-
type rtc_t = PCF8523
7-
8-
$shell: Shell
9-
$sandbox: Sandbox
10-
116
# Classes
127

138
$LOAD_PATH: Array[String]
@@ -28,9 +23,9 @@ class Shell
2823
def self.ensure_system_file: (String path, String code, ?(Integer | nil) crc) -> void
2924
def self.setup_system_files: (?(String | nil) root, ?force: bool) -> void
3025
def self.bootstrap: (String file) -> bool
26+
def self.simple_question: (String question) { (String answer) -> boolish } -> void
3127

3228
def initialize: (?clean: bool) -> void
33-
def simple_question: (String question) { (String answer) -> boolish } -> void
3429
def show_logo: -> nil
3530
def start: (?Symbol mode) -> nil
3631
def run_shell: -> void

0 commit comments

Comments
 (0)