File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -29,9 +29,33 @@ public ShellContext() {
2929 this .aliases = new HashMap <>();
3030 this .commandHistory = new ArrayList <>();
3131 this .startTime = Instant .now ();
32+ this .scanner = null ; // Will be set by App.java
3233 loadAliases ();
3334 }
3435
36+ // ==================== Scanner Management ====================
37+
38+ /**
39+ * Set the shared Scanner instance for all commands to use.
40+ * Should only be called once by App.java during initialization.
41+ */
42+ public void setScanner (Scanner scanner ) {
43+ this .scanner = scanner ;
44+ }
45+
46+ /**
47+ * Get the shared Scanner instance.
48+ * All commands should use this instead of creating their own Scanner.
49+ * @return the shared Scanner instance
50+ * @throws IllegalStateException if Scanner hasn't been initialized
51+ */
52+ public Scanner getScanner () {
53+ if (scanner == null ) {
54+ throw new IllegalStateException ("Scanner not initialized in ShellContext" );
55+ }
56+ return scanner ;
57+ }
58+
3559 public void addToHistory (String command ) {
3660 history .add (command );
3761 commandHistory .add (command );
You can’t perform that action at this time.
0 commit comments