88use \Smuuf \Primi \Helpers \Common ;
99use \Smuuf \Primi \Colors ;
1010use \Smuuf \Primi \Interpreter ;
11+ use \Smuuf \Primi \IContext ;
1112use \Smuuf \Primi \IReadlineDriver ;
1213
1314class Repl extends \Smuuf \Primi \StrictObject {
@@ -56,12 +57,19 @@ public function start() {
5657 private function loop () {
5758
5859 $ i = $ this ->interpreter ;
60+ $ c = $ i ->getContext ();
61+
5962 readline_completion_function (function () { return []; });
63+
6064 while (true ) {
6165
6266 $ input = $ this ->gatherLines ();
6367
6468 switch (trim ($ input )) {
69+ case '? ' :
70+ $ this ->printContext ($ c );
71+ continue 2 ;
72+ break ;
6573 case '' :
6674 // Ignore (skip) empty input.
6775 continue 2 ;
@@ -91,7 +99,7 @@ private function loop() {
9199
92100 }
93101
94- public function printResult (Value $ result = null ): void {
102+ private function printResult (Value $ result = null ): void {
95103
96104 if ($ result === null ) {
97105 return ;
@@ -100,12 +108,12 @@ public function printResult(Value $result = null): void {
100108 printf (
101109 "%s %s \n" ,
102110 $ result ->getStringValue (),
103- !$ this ->rawOutput ? $ this -> formatType ($ result ) : null
111+ !$ this ->rawOutput ? self :: formatType ($ result ) : null
104112 );
105113
106114 }
107115
108- private function formatType (Value $ value ) {
116+ private static function formatType (Value $ value ) {
109117
110118 return Colors::get (sprintf (
111119 "{darkgrey}(%s %s){_} " ,
@@ -115,6 +123,15 @@ private function formatType(Value $value) {
115123
116124 }
117125
126+ private function printContext (IContext $ c ): void {
127+
128+ foreach ($ c ->getVariables () as $ name => $ value ) {
129+ echo "$ name: " ;
130+ $ this ->printResult ($ value );
131+ }
132+
133+ }
134+
118135 private function gatherLines (): string {
119136
120137 $ gathering = false ;
0 commit comments